Package io.micronaut.runtime.graceful
Interface GracefulShutdownCapable
- All Known Subinterfaces:
NettyEmbeddedServer
- All Known Implementing Classes:
ExecutorFactory
,NettyHttpServer
,PipeliningServerHandler
public interface GracefulShutdownCapable
Interface implemented by beans that support graceful shutdown.
- Since:
- 4.9.0
- Author:
- Jonas Konrad
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull CompletionStage<?>
allOf
(@NonNull Stream<CompletionStage<?>> stages) Combine the given futures.static @NonNull OptionalLong
combineActiveTasks
(@NonNull Iterable<? extends GracefulShutdownCapable> delegates) default OptionalLong
After a call toshutdownGracefully()
report the state of the shutdown.static @NonNull CompletionStage<?>
shutdownAll
(@NonNull Stream<? extends GracefulShutdownCapable> stages) Shutdown all the given lifecycles.Trigger a graceful shutdown.
-
Method Details
-
shutdownGracefully
Trigger a graceful shutdown. The returnedCompletionStage
will complete when the shutdown is complete.Note that the completion of the returned future may be user-dependent. If a user does not close their connection, the future may never terminate. Always add a timeout for a hard shutdown.
This method should not throw an exception, nor should the returned stage complete exceptionally. Just log an error instead.
- Returns:
- A future that completes when this bean is fully shut down
-
reportActiveTasks
After a call toshutdownGracefully()
report the state of the shutdown. IfshutdownGracefully()
has not been called the behavior of this method is undefined.- Returns:
- The current number of still-active tasks before the shutdown completes, or
Optional.empty()
if no state can be reported
-
allOf
@NonNull static @NonNull CompletionStage<?> allOf(@NonNull @NonNull Stream<CompletionStage<?>> stages) Combine the given futures.- Parameters:
stages
- The input futures- Returns:
- A future that completes when all inputs have completed
-
shutdownAll
@NonNull static @NonNull CompletionStage<?> shutdownAll(@NonNull @NonNull Stream<? extends GracefulShutdownCapable> stages) Shutdown all the given lifecycles.- Parameters:
stages
- The input lifecycles- Returns:
- A future that completes when all inputs have completed shutdown
-
combineActiveTasks
@NonNull static @NonNull OptionalLong combineActiveTasks(@NonNull @NonNull Iterable<? extends GracefulShutdownCapable> delegates)
-