Package io.airlift.bootstrap
Class LifeCycleManager
java.lang.Object
io.airlift.bootstrap.LifeCycleManager
Manages PostConstruct and PreDestroy life cycles
-
Constructor Summary
ConstructorsConstructorDescriptionLifeCycleManager(List<Object> managedInstances, io.airlift.bootstrap.LifeCycleMethodsMap methodsMap) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInstance(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.voidStop 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 Details
-
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 Details
-
size
public int size()Returns the number of managed instances- Returns:
- qty
-
start
Start the life cycle - all instances will have theirPostConstructmethod(s) called- Throws:
LifeCycleStartException
-
stopWithoutFailureLogging
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. 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
Stop 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
Add an additional managed instance- Parameters:
instance- instance to add- Throws:
LifeCycleStartException- errors duringPostConstructmethod invocationIllegalStateException- if the life cycle has been stopped
-