Package io.airlift.bootstrap
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddInstance(Object instance)Add an additional managed instanceintsize()Returns the number of managed instancesvoidstart()Start the life cycle - all instances will have theirPostConstructmethod(s) calledvoidstop()Stop the life cycle - all instances will have theirPreDestroymethod(s) called and any exceptions raised will be immediately logged.voidstopWithoutFailureLogging()Stop the life cycle - all instances will have theirPreDestroymethod(s) called and any exceptions raised will be collected and thrown in a wrappedLifeCycleStopExceptionas suppressed exceptions.
-
-
-
Constructor Detail
-
LifeCycleManager
public LifeCycleManager(List<Object> managedInstances, io.airlift.bootstrap.LifeCycleMethodsMap methodsMap) throws LifeCycleStartException
- Parameters:
managedInstances- list of objects that have life cycle annotationsmethodsMap- existing or new methods map- Throws:
LifeCycleStartException- exceptions starting instances (depending on mode)
-
-
Method Detail
-
size
public int size()
Returns the number of managed instances- Returns:
- qty
-
start
public void start() throws LifeCycleStartExceptionStart the life cycle - all instances will have theirPostConstructmethod(s) called- Throws:
LifeCycleStartException
-
stopWithoutFailureLogging
public void stopWithoutFailureLogging() throws LifeCycleStopExceptionStop the life cycle - all instances will have theirPreDestroymethod(s) called and any exceptions raised will be collected and thrown in a wrappedLifeCycleStopExceptionas 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 LifeCycleStopExceptionStop the life cycle - all instances will have theirPreDestroymethod(s) called and any exceptions raised will be immediately logged. If any such exceptions occur, a singleLifeCycleStopExceptionwill 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 duringPostConstructmethod invocationIllegalStateException- if the life cycle has been stopped
-
-