public interface Stopping
When a service gets called to stop it can return a Stopping
instance
which can be used to identify the end of the stopping process. A standard
call to a stop method will initiate the shutdown process of this service.
However when the stop method returns it is not ensured that all resources are
already freed.
The Stopping
interface allows to wait for the actual shutdown of all
resources while staying outside of service instances and its locks.
The Stopping
interface can be compared to Future
or
CompletionStage
, although it is not that sophisticated and more
targeted to this specific task.
Modifier and Type | Field and Description |
---|---|
static Stopping |
EMPTY
An empty stopping instance which does nothing.
|
Modifier and Type | Method and Description |
---|---|
default Stopping |
andThen(Stopping other)
Return a new, combined instance of this and the other instance
|
void |
await()
Synchronously wait for the end of the process
|
default void |
awaitAsync()
Execute the waiting code on a the
ForkJoinPool.commonPool() and
wait for the result in this thread |
default void |
awaitAsync(Executor executor)
Execute the waiting code on the provided executor and wait for the result
in this thread
|
default void |
awaitSeperately()
Execute the waiting code in a freshly created
ExecutorService ,
wait for the result and shut down the pool |
default CompletableFuture<?> |
completion()
Wrap this instance in a
CompletableFuture on the
ForkJoinPool.commonPool() |
default CompletableFuture<?> |
completion(Executor executor)
Wrap this instance in a
CompletableFuture on the
provided executor |
static final Stopping EMPTY
This can be used if the service actually is stopped when the stop method returns. It has a few optimizations over using a custom empty Stopping instance.
void await() throws Exception
Exception
- if anything goes wrongdefault Stopping andThen(Stopping other)
other
- the other instance to wait for as welldefault void awaitAsync()
ForkJoinPool.commonPool()
and
wait for the result in this threaddefault void awaitAsync(Executor executor)
executor
- the execute to run the await()
method indefault void awaitSeperately()
ExecutorService
,
wait for the result and shut down the pooldefault CompletableFuture<?> completion()
CompletableFuture
on the
ForkJoinPool.commonPool()
CompletableFuture
default CompletableFuture<?> completion(Executor executor)
CompletableFuture
on the
provided executorexecutor
- the executor to useCompletableFuture