Interface ShutdownHooks

All Known Implementing Classes:
ShutdownHookRegistry

@Deprecated public interface ShutdownHooks
Deprecated.
use com.mastfrog.shutdown.hooks.ShutdownHooks directly - the code has been moved there, and this class simply delegates to it.
A registry of shutdown hooks which run in LIFO order on shutdown; for cases where the order cannot be determined by instantiaton/addition order, first, last and middle (default) batches of hooks are provided.

Hooks are guaranteed to be run regardless of any other hook aborting or throwing an exception.

Hooks may be added such that they are weakly referenced, and will be omitted if garbage-collected.

Additions during shutdown are guaranteed to be run.

Executor services will have termination waited for for a settable timeout; the timeout is collective and is how long all executors will be waited for in aggregate. The default is three minutes.

Author:
Tim Boudreau
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(AutoCloseable toClose)
    Deprecated.
    Add an AutoCloseable to be cancelled to the default batch; the AutoCloseable will be weakly referenced.
    void
    add(Runnable toRun)
    Deprecated.
    Add a Runnable to the default batch.
    add(Callable<?> toRun)
    Deprecated.
     
    add(ExecutorService toShutdown)
    Deprecated.
    Add an executor service to the default batch; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.
    void
    add(Timer toCancel)
    Deprecated.
    Add a timer to be cancelled to the default batch; the timer will be weakly referenced.
    Deprecated.
    Add an AutoCloseable to be cancelled to the batch which runs first; the AutoCloseable will be weakly referenced.
    Deprecated.
    Add a Runnable to the batch which runs first.
    addFirst(Callable<?> toRun)
    Deprecated.
     
    Deprecated.
    Add an executor service to the batch which runs first; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.
    addFirst(Timer toCancel)
    Deprecated.
    Add a timer to be cancelled to the batch which runs first; the timer will be weakly referenced.
    addFirstThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
    Deprecated.
     
    Deprecated.
    Add a Runnable to the batch which runs first, without keeping it strongly referenced.
    Deprecated.
     
    addFirstWeakThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
    Deprecated.
     
    Deprecated.
    Add an AutoCloseable to be cancelled to the batch which runs last; the AutoCloseable will be weakly referenced.
    Deprecated.
    Add a Runnable to the batch which runs last.
    addLast(Callable<?> toRun)
    Deprecated.
     
    Deprecated.
    Add an executor service to the batch which runs last; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.
    addLast(Timer toCancel)
    Deprecated.
    Add a timer to be cancelled to the batch which runs last; the timer will be weakly referenced.
    addLastThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
    Deprecated.
     
    Deprecated.
    Add a Runnable to the batch which runs first, without keeping it strongly referenced.
    Deprecated.
     
    addLastWeakThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
    Deprecated.
     
    addThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
    Deprecated.
     
    Deprecated.
    Add a Runnable to the default batch, without keeping it strongly referenced.
    addWeak(Callable<?> toRun)
    Deprecated.
     
    addWeakThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
    Deprecated.
     
    boolean
    Deprecated.
    Returns true if shutdown hooks are currently being run.
    int
    Deprecated.
    Imperatively run shutdown tasks, clearing the set of tasks and deregistering the ShutdownHooks as a VM shutdown hook if it has been registered.
  • Method Details

    • isRunningShutdownHooks

      boolean isRunningShutdownHooks()
      Deprecated.
      Returns true if shutdown hooks are currently being run.
      Returns:
      True if hooks are running
    • add

      void add(Runnable toRun)
      Deprecated.
      Add a Runnable to the default batch.
      Parameters:
      toRun - A runnable
    • addLast

      ShutdownHooks addLast(Runnable toRun)
      Deprecated.
      Add a Runnable to the batch which runs last.
      Parameters:
      toRun - A runnable
      Returns:
      this
    • addFirst

      ShutdownHooks addFirst(Runnable toRun)
      Deprecated.
      Add a Runnable to the batch which runs first.
      Parameters:
      toRun - A runnable
      Returns:
      this
    • addWeak

      ShutdownHooks addWeak(Runnable toRun)
      Deprecated.
      Add a Runnable to the default batch, without keeping it strongly referenced.
      Parameters:
      toRun - A runnable
    • addFirstWeak

      ShutdownHooks addFirstWeak(Runnable toRun)
      Deprecated.
      Add a Runnable to the batch which runs first, without keeping it strongly referenced.
      Parameters:
      toRun - A runnable
    • addLastWeak

      ShutdownHooks addLastWeak(Runnable toRun)
      Deprecated.
      Add a Runnable to the batch which runs first, without keeping it strongly referenced.
      Parameters:
      toRun - A runnable
    • add

      ShutdownHooks add(ExecutorService toShutdown)
      Deprecated.
      Add an executor service to the default batch; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.
      Parameters:
      toShutdown - An ExecutorService
      Returns:
      this
    • addFirst

      ShutdownHooks addFirst(ExecutorService toShutdown)
      Deprecated.
      Add an executor service to the batch which runs first; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.
      Parameters:
      toShutdown - An ExecutorService
      Returns:
      this
    • addLast

      ShutdownHooks addLast(ExecutorService toShutdown)
      Deprecated.
      Add an executor service to the batch which runs last; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.
      Parameters:
      toShutdown - An ExecutorService
      Returns:
      this
    • add

      void add(Timer toCancel)
      Deprecated.
      Add a timer to be cancelled to the default batch; the timer will be weakly referenced.
      Parameters:
      toCancel - A timer
    • addFirst

      ShutdownHooks addFirst(Timer toCancel)
      Deprecated.
      Add a timer to be cancelled to the batch which runs first; the timer will be weakly referenced.
      Parameters:
      toCancel - A timer
      Returns:
      this
    • addLast

      ShutdownHooks addLast(Timer toCancel)
      Deprecated.
      Add a timer to be cancelled to the batch which runs last; the timer will be weakly referenced.
      Parameters:
      toCancel - A timer
      Returns:
      this
    • add

      void add(AutoCloseable toClose)
      Deprecated.
      Add an AutoCloseable to be cancelled to the default batch; the AutoCloseable will be weakly referenced.
      Parameters:
      toClose - A resource to be closed
    • addFirst

      ShutdownHooks addFirst(AutoCloseable toClose)
      Deprecated.
      Add an AutoCloseable to be cancelled to the batch which runs first; the AutoCloseable will be weakly referenced.
      Parameters:
      toClose - A resource to be closed
      Returns:
      this
    • addLast

      ShutdownHooks addLast(AutoCloseable toClose)
      Deprecated.
      Add an AutoCloseable to be cancelled to the batch which runs last; the AutoCloseable will be weakly referenced.
      Parameters:
      toClose - A resource to be closed
      Returns:
      this
    • add

      ShutdownHooks add(Callable<?> toRun)
      Deprecated.
    • addFirst

      ShutdownHooks addFirst(Callable<?> toRun)
      Deprecated.
    • addLast

      ShutdownHooks addLast(Callable<?> toRun)
      Deprecated.
    • addFirstWeak

      ShutdownHooks addFirstWeak(Callable<?> toRun)
      Deprecated.
    • addLastWeak

      ShutdownHooks addLastWeak(Callable<?> toRun)
      Deprecated.
    • addWeak

      ShutdownHooks addWeak(Callable<?> toRun)
      Deprecated.
    • addThrowing

      ShutdownHooks addThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
      Deprecated.
    • addFirstThrowing

      ShutdownHooks addFirstThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
      Deprecated.
    • addLastThrowing

      ShutdownHooks addLastThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
      Deprecated.
    • addWeakThrowing

      default ShutdownHooks addWeakThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
      Deprecated.
    • addFirstWeakThrowing

      default ShutdownHooks addFirstWeakThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
      Deprecated.
    • addLastWeakThrowing

      default ShutdownHooks addLastWeakThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun)
      Deprecated.
    • shutdown

      int shutdown()
      Deprecated.
      Imperatively run shutdown tasks, clearing the set of tasks and deregistering the ShutdownHooks as a VM shutdown hook if it has been registered.

      In general this should only be called by test frameworks and a few rare cases of applications that cleanly shut down all their state and reload themselves, or things run inside an isolating classloader whose shutdown tasks must run before the classloader is closed.

      Returns:
      The count of tasks run during shutdown