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 completes

See also

for the standard close contract

Inheritors

Functions

Link copied to clipboard
open override fun close()

Closes this resource by performing a graceful shutdown.

Link copied to clipboard
open fun stop()

Synchronously closes this resource with graceful shutdown.

open fun stop(timeout: Duration)

Synchronously closes this resource with graceful shutdown within a specified timeout.

Link copied to clipboard
abstract fun stopGracefully(): Mono<Void>

Asynchronously closes this resource with graceful shutdown.