GracefullyStoppable
Interface for components that support graceful shutdown.
Implementations of this interface provide both synchronous and asynchronous graceful stop operations. The synchronous close() method blocks until all ongoing operations complete, while stopGracefully() returns a reactive stream that completes when shutdown is finished.
This is particularly useful for message dispatchers, connection pools, and other resources that need to complete in-flight operations before terminating.
Example usage:
class MyDispatcher : GracefullyStoppable {
private val activeOperations = mutableListOf<Mono<Void>>()
override fun stopGracefully(): Mono<Void> {
// Cancel new operations and wait for active ones
stopAcceptingNewOperations()
return if (activeOperations.isNotEmpty()) {
Flux.merge(activeOperations).then()
} else {
Mono.empty()
}
}
}
// Usage
val dispatcher = MyDispatcher()
// ... use dispatcher ...
dispatcher.close() // Blocks until graceful shutdown completesContent copied to clipboard
See also
for the standard close contract