Class ContainerLifeCycle
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- All Implemented Interfaces:
Container,Destroyable,Dumpable,Dumpable.DumpableContainer,LifeCycle
- Direct Known Subclasses:
AbstractConnectionFactory,AbstractConnectionPool,AbstractConnector,AbstractHandler,AbstractHttpClientTransport,AbstractLoginService,AbstractNCSARequestLog,AbstractSessionCache,AbstractSessionDataStore,AttributeContainerMap,CachingSessionDataStore,ClientContainer,ConfigurableSpnegoLoginService,ConnectionManager,CustomRequestLog,DefaultSessionIdManager,DelegatingThreadPool,DeploymentManager,EatWhatYouKill,ExecutorThreadPool,ExtensionStack,HTTP2Client,HTTP2Session,HttpClient,HttpDestination,JAASLoginService,KeyStoreScanner,LeakTrackingByteBufferPool,LowResourceMonitor,ManagedSelector,MavenServerConnector,NativeWebSocketConfiguration,OpenIdConfiguration,OpenIdLoginService,QueuedThreadPool,SelectorManager,SimpleContainerScope,WebSocketClient,WebSocketServerFactory,WebSocketSession
@ManagedObject("Implementation of Container and LifeCycle") public class ContainerLifeCycle extends AbstractLifeCycle implements Container, Destroyable, Dumpable.DumpableContainer
A ContainerLifeCycle is anLifeCycleimplementation for a collection of contained beans.Beans can be added to the ContainerLifeCycle either as managed beans or as unmanaged beans. A managed bean is started, stopped and destroyed with the aggregate. An unmanaged bean is associated with the aggregate for the purposes of
dump(), but its lifecycle must be managed externally.When a
LifeCyclebean is added without a managed state being specified the state is determined heuristically:- If the added bean is running, it will be added as an unmanaged bean.
- If the added bean is !running and the container is !running, it will be added as an AUTO bean (see below).
- If the added bean is !running and the container is starting, it will be added as a managed bean and will be started (this handles the frequent case of new beans added during calls to doStart).
- If the added bean is !running and the container is started, it will be added as an unmanaged bean.
When stopping the container, a contained bean will be stopped by this aggregate only if it is started by this aggregate.
The methods
addBean(Object, boolean),manage(Object)andunmanage(Object)can be used to explicitly control the life cycle relationship.If adding a bean that is shared between multiple
ContainerLifeCycleinstances, then it should be started before being added, so it is unmanaged, or the API must be used to explicitly set it as unmanaged.This class also provides utility methods to dump deep structures of objects. In the dump, the following symbols are used to indicate the type of contained object:
SomeContainerLifeCycleInstance +- contained POJO instance += contained MANAGED object, started and stopped with this instance +~ referenced UNMANAGED object, with separate lifecycle +? referenced AUTO object that could become MANAGED or UNMANAGED.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Constructor Summary
Constructors Constructor Description ContainerLifeCycle()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanaddBean(java.lang.Object o)Adds the given bean, detecting whether to manage it or not.booleanaddBean(java.lang.Object o, boolean managed)Adds the given bean, explicitly managing it or not.voidaddEventListener(Container.Listener listener)Add an event listener.voidaddManaged(LifeCycle lifecycle)Adds a managed lifecycle.booleancontains(java.lang.Object bean)voiddestroy()Destroys the managed Destroyable beans in the reverse order they were added.protected voiddoStart()Starts the managed lifecycle beans in the order they were added.protected voiddoStop()Stops the managed lifecycle beans in the reverse order they were added.java.lang.Stringdump()voiddump(java.lang.Appendable out)Dump this object to an Appendable with no indent.voiddump(java.lang.Appendable out, java.lang.String indent)Dump this object (and children) into an Appendable using the provided indent after any new lines.static voiddump(java.lang.Appendable out, java.lang.String indent, java.util.Collection<?>... collections)Deprecated.static java.lang.Stringdump(Dumpable dumpable)Deprecated.useDumpable.dump(Dumpable)insteadprotected voiddumpBeans(java.lang.Appendable out, java.lang.String indent, java.util.Collection<?>... items)Deprecated.static voiddumpObject(java.lang.Appendable out, java.lang.Object obj)Deprecated.useDumpable.dumpObject(Appendable, Object)insteadprotected voiddumpObjects(java.lang.Appendable out, java.lang.String indent, java.lang.Object... items)Dump this object, it's contained beans and additional items to an AppendablevoiddumpStdErr()Dumps toSystem.err.protected voiddumpThis(java.lang.Appendable out)Deprecated.<T> TgetBean(java.lang.Class<T> clazz)java.util.Collection<java.lang.Object>getBeans()<T> java.util.Collection<T>getBeans(java.lang.Class<T> clazz)<T> java.util.Collection<T>getContainedBeans(java.lang.Class<T> clazz)protected <T> voidgetContainedBeans(java.lang.Class<T> clazz, java.util.Collection<T> beans)booleanisAuto(java.lang.Object bean)booleanisManaged(java.lang.Object bean)Test if this container manages a beanbooleanisUnmanaged(java.lang.Object bean)voidmanage(java.lang.Object bean)Manages a bean already contained by this aggregate, so that it is started/stopped/destroyed with this aggregate.booleanremoveBean(java.lang.Object o)Removes the given bean.voidremoveBeans()Removes all beanvoidremoveEventListener(Container.Listener listener)Remove an event listener.voidsetBeans(java.util.Collection<java.lang.Object> beans)voidsetStopTimeout(long stopTimeout)protected voidstart(LifeCycle l)Starts the given lifecycle.protected voidstop(LifeCycle l)Stops the given lifecycle.voidunmanage(java.lang.Object bean)Unmanages a bean already contained by this aggregate, so that it is not started/stopped/destroyed with this aggregate.voidupdateBean(java.lang.Object oldBean, java.lang.Object newBean)voidupdateBean(java.lang.Object oldBean, java.lang.Object newBean, boolean managed)voidupdateBeans(java.lang.Object[] oldBeans, java.lang.Object[] newBeans)-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
-
-
-
Method Detail
-
doStart
protected void doStart() throws java.lang.ExceptionStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classAbstractLifeCycle- Throws:
java.lang.Exception
-
start
protected void start(LifeCycle l) throws java.lang.Exception
Starts the given lifecycle.- Parameters:
l- the lifecycle to start- Throws:
java.lang.Exception- if unable to start lifecycle
-
stop
protected void stop(LifeCycle l) throws java.lang.Exception
Stops the given lifecycle.- Parameters:
l- the lifecycle to stop- Throws:
java.lang.Exception- if unable to stop the lifecycle
-
doStop
protected void doStop() throws java.lang.ExceptionStops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStopin classAbstractLifeCycle- Throws:
java.lang.Exception
-
destroy
public void destroy()
Destroys the managed Destroyable beans in the reverse order they were added.- Specified by:
destroyin interfaceDestroyable
-
contains
public boolean contains(java.lang.Object bean)
- Parameters:
bean- the bean to test- Returns:
- whether this aggregate contains the bean
-
isManaged
public boolean isManaged(java.lang.Object bean)
Description copied from interface:ContainerTest if this container manages a bean
-
isAuto
public boolean isAuto(java.lang.Object bean)
- Parameters:
bean- the bean to test- Returns:
- whether this aggregate contains the bean in auto state
-
isUnmanaged
public boolean isUnmanaged(java.lang.Object bean)
- Parameters:
bean- the bean to test- Returns:
- whether this aggregate contains the bean in auto state
-
addBean
public boolean addBean(java.lang.Object o)
Adds the given bean, detecting whether to manage it or not. If the bean is aLifeCycle, then it will be managed if it is not already started and not managed if it is already started. TheaddBean(Object, boolean)method should be used if this is not correct, or themanage(Object)andunmanage(Object)methods may be used after an add to change the status.
-
addBean
public boolean addBean(java.lang.Object o, boolean managed)Adds the given bean, explicitly managing it or not.
-
addManaged
public void addManaged(LifeCycle lifecycle)
Adds a managed lifecycle.This is a convenience method that uses addBean(lifecycle,true) and then ensures that the added bean is started iff this container is running. Exception from nested calls to start are caught and wrapped as RuntimeExceptions
- Parameters:
lifecycle- the managed lifecycle to add
-
addEventListener
public void addEventListener(Container.Listener listener)
Description copied from interface:ContainerAdd an event listener.- Specified by:
addEventListenerin interfaceContainer- Parameters:
listener- the listener to add- See Also:
Container.addBean(Object)
-
manage
public void manage(java.lang.Object bean)
Manages a bean already contained by this aggregate, so that it is started/stopped/destroyed with this aggregate.
-
unmanage
public void unmanage(java.lang.Object bean)
Unmanages a bean already contained by this aggregate, so that it is not started/stopped/destroyed with this aggregate.
-
getBeans
public java.util.Collection<java.lang.Object> getBeans()
- Specified by:
getBeansin interfaceContainer- Returns:
- the collection of beans known to this aggregate, in the order they were added.
- See Also:
Container.getBean(Class)
-
setBeans
public void setBeans(java.util.Collection<java.lang.Object> beans)
-
getBeans
public <T> java.util.Collection<T> getBeans(java.lang.Class<T> clazz)
- Specified by:
getBeansin interfaceContainer- Type Parameters:
T- the Bean type- Parameters:
clazz- the class of the beans- Returns:
- a list of beans of the given class (or subclass), in the order they were added.
- See Also:
Container.getBeans(),Container.getContainedBeans(Class)
-
getBean
public <T> T getBean(java.lang.Class<T> clazz)
-
removeBeans
public void removeBeans()
Removes all bean
-
removeBean
public boolean removeBean(java.lang.Object o)
Description copied from interface:ContainerRemoves the given bean. If the bean is-aContainer.Listener, then also do an implicitContainer.removeEventListener(Listener).- Specified by:
removeBeanin interfaceContainer- Parameters:
o- the bean to remove- Returns:
- whether the bean was removed
-
removeEventListener
public void removeEventListener(Container.Listener listener)
Description copied from interface:ContainerRemove an event listener.- Specified by:
removeEventListenerin interfaceContainer- Parameters:
listener- the listener to remove- See Also:
Container.removeBean(Object)
-
setStopTimeout
public void setStopTimeout(long stopTimeout)
- Overrides:
setStopTimeoutin classAbstractLifeCycle
-
dumpStdErr
@ManagedOperation("Dump the object to stderr") public void dumpStdErr()
Dumps toSystem.err.- See Also:
dump()
-
dump
@ManagedOperation("Dump the object to a string") public java.lang.String dump()
-
dump
@Deprecated public static java.lang.String dump(Dumpable dumpable)
Deprecated.useDumpable.dump(Dumpable)insteadDescription copied from interface:DumpableUtility method to implementDumpable.dump()by callingDumpable.dump(Appendable, String)- Parameters:
dumpable- the object to dump- Returns:
- the string representation of the given Dumpable
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOExceptionDescription copied from interface:DumpableDump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
-
dump
public void dump(java.lang.Appendable out) throws java.io.IOExceptionDump this object to an Appendable with no indent.- Parameters:
out- The appendable to dump to.- Throws:
java.io.IOException- May be thrown by the Appendable
-
dumpThis
@Deprecated protected void dumpThis(java.lang.Appendable out) throws java.io.IOExceptionDeprecated.Dump just this object, but not it's children. Typically used to implementdump(Appendable, String)- Parameters:
out- The appendable to dump to- Throws:
java.io.IOException- May be thrown by the Appendable
-
dumpObject
@Deprecated public static void dumpObject(java.lang.Appendable out, java.lang.Object obj) throws java.io.IOExceptionDeprecated.useDumpable.dumpObject(Appendable, Object)insteadDescription copied from interface:DumpableDump just an Object (but not it's contained items) to an Appendable.- Parameters:
out- The Appendable to dump toobj- The object to dump- Throws:
java.io.IOException- May be thrown by the Appendable
-
dumpObjects
protected void dumpObjects(java.lang.Appendable out, java.lang.String indent, java.lang.Object... items) throws java.io.IOExceptionDump this object, it's contained beans and additional items to an Appendable- Parameters:
out- The appendable to dump toindent- The indent to apply after any new linesitems- Additional items to be dumped as contained.- Throws:
java.io.IOException- May be thrown by the Appendable
-
dumpBeans
@Deprecated protected void dumpBeans(java.lang.Appendable out, java.lang.String indent, java.util.Collection<?>... items) throws java.io.IOExceptionDeprecated.- Parameters:
out- The appendable to dump toindent- The indent to apply after any new linesitems- Additional collections to be dumped- Throws:
java.io.IOException- May be thrown by the Appendable
-
dump
@Deprecated public static void dump(java.lang.Appendable out, java.lang.String indent, java.util.Collection<?>... collections) throws java.io.IOExceptionDeprecated.- Throws:
java.io.IOException
-
updateBean
public void updateBean(java.lang.Object oldBean, java.lang.Object newBean)
-
updateBean
public void updateBean(java.lang.Object oldBean, java.lang.Object newBean, boolean managed)
-
updateBeans
public void updateBeans(java.lang.Object[] oldBeans, java.lang.Object[] newBeans)
-
getContainedBeans
public <T> java.util.Collection<T> getContainedBeans(java.lang.Class<T> clazz)
- Specified by:
getContainedBeansin interfaceContainer- Type Parameters:
T- the Bean type- Parameters:
clazz- the class of the beans- Returns:
- the list of beans of the given class from the entire Container hierarchy. The order is primarily depth first and secondarily added order.
-
getContainedBeans
protected <T> void getContainedBeans(java.lang.Class<T> clazz, java.util.Collection<T> beans)
-
-