Package com.glitchybyte.glib
Class GShutdownMonitor
java.lang.Object
com.glitchybyte.glib.GShutdownMonitor
Utility to monitor SIGINT and SIGTERM for proper application shutdown.
-
Method Summary
Modifier and TypeMethodDescriptionvoidAwaits for a shutdown.voidawaitShutdown(Duration timeout) Awaits for a shutdown or expiration of the given timeout.static GShutdownMonitorCreates a monitor that will get notified when it's time for an orderly shutdown.booleanReturns true when an orderly shutdown should occur.voidshutdown()Manually triggers an orderly shutdown.voidConvenience method to execute an action periodically at the given cadence, until a shutdown is triggered.
-
Method Details
-
createShutdownMonitor
Creates a monitor that will get notified when it's time for an orderly shutdown.- Returns:
- A shutdown monitor.
-
shouldShutdown
public boolean shouldShutdown()Returns true when an orderly shutdown should occur.- Returns:
- True when an orderly shutdown should occur.
-
shutdown
public void shutdown()Manually triggers an orderly shutdown. -
awaitShutdown
Awaits for a shutdown or expiration of the given timeout.If a shutdown has been triggered, the method will exit fast.
- Parameters:
timeout- Time to wait for shutdown.
-
awaitShutdown
public void awaitShutdown()Awaits for a shutdown.If a shutdown has been triggered, the method will exit fast.
-
whileLive
Convenience method to execute an action periodically at the given cadence, until a shutdown is triggered.- Parameters:
cadence- Cadence at which to execute the action.action- Action to execute.
-