Class LifeCycleManager

java.lang.Object
io.airlift.bootstrap.LifeCycleManager

public final class LifeCycleManager extends Object
Manages PostConstruct and PreDestroy life cycles
  • Constructor Summary

    Constructors
    Constructor
    Description
    LifeCycleManager(List<Object> managedInstances, io.airlift.bootstrap.LifeCycleMethodsMap methodsMap)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addInstance(Object instance)
    Add an additional managed instance
    int
    Returns the number of managed instances
    void
    Start the life cycle - all instances will have their PostConstruct method(s) called
    void
    Stop the life cycle - all instances will have their PreDestroy method(s) called and any exceptions raised will be immediately logged.
    void
    Stop the life cycle - all instances will have their PreDestroy method(s) called and any exceptions raised will be collected and thrown in a wrapped LifeCycleStopException as suppressed exceptions.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LifeCycleManager

      public LifeCycleManager(List<Object> managedInstances, io.airlift.bootstrap.LifeCycleMethodsMap methodsMap) throws LifeCycleStartException
      Parameters:
      managedInstances - list of objects that have life cycle annotations
      methodsMap - existing or new methods map
      Throws:
      LifeCycleStartException - exceptions starting instances (depending on mode)
  • Method Details

    • size

      public int size()
      Returns the number of managed instances
      Returns:
      qty
    • start

      public void start() throws LifeCycleStartException
      Start the life cycle - all instances will have their PostConstruct method(s) called
      Throws:
      LifeCycleStartException
    • stopWithoutFailureLogging

      public void stopWithoutFailureLogging() throws LifeCycleStopException
      Stop the life cycle - all instances will have their PreDestroy method(s) called and any exceptions raised will be collected and thrown in a wrapped LifeCycleStopException as suppressed exceptions. Those failures will not be logged and are the responsibility of the caller to handle appropriately.
      Throws:
      LifeCycleStopException - If any failure occurs during the clean up process
    • stop

      public void stop() throws LifeCycleStopException
      Stop the life cycle - all instances will have their PreDestroy method(s) called and any exceptions raised will be immediately logged. If any such exceptions occur, a single LifeCycleStopException will be raised at the end of processing which will not contain any reference to exceptions already logged.
      Throws:
      LifeCycleStopException - If any failure occurs during the clean up process
    • addInstance

      public void addInstance(Object instance) throws LifeCycleStartException
      Add an additional managed instance
      Parameters:
      instance - instance to add
      Throws:
      LifeCycleStartException - errors during PostConstruct method invocation
      IllegalStateException - if the life cycle has been stopped