Class GShutdownMonitor

java.lang.Object
com.glitchybyte.glib.GShutdownMonitor

public final class GShutdownMonitor extends Object
Utility to monitor SIGINT and SIGTERM for proper application shutdown.
  • Method Details

    • createShutdownMonitor

      public static GShutdownMonitor 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

      public void awaitShutdown(Duration timeout)
      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

      public void whileLive(Duration cadence, Runnable action)
      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.