Class ContainerLifeCycle
- All Implemented Interfaces:
Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
- Direct Known Subclasses:
AbstractConnectionFactory
,AbstractConnectionPool
,AbstractConnector
,AbstractHttpClientTransport
,AbstractLoginService
,AbstractSessionCache
,AbstractSessionDataStore
,AbstractSessionManager
,AdaptiveExecutionStrategy
,AttributeContainerMap
,CachingSessionDataStore
,ClientConnectionFactory.Info
,ClientConnectionFactoryOverHTTP2
,ClientConnectionFactoryOverHTTP3
,ClientConnector
,ClientConnector.Configurator
,CompressionPool
,CustomRequestLog
,DefaultSessionIdManager
,DelegatingThreadPool
,DeploymentManager
,ExecutorThreadPool
,Handler.Abstract
,HTTP2Client
,HTTP2Session
,HTTP3Client
,HTTP3Session
,HttpClient
,HttpDestination
,JAASLoginService
,JakartaWebSocketContainer
,JettyWebSocketFrameHandlerFactory
,JettyWebSocketServerContainer
,KeyStoreScanner
,LowResourceMonitor
,ManagedSelector
,OpenIdConfiguration
,OpenIdLoginService
,ProtocolSession
,QueuedThreadPool
,QuicConfiguration
,QuicSession
,ReservedThreadExecutor
,Scanner
,ScanningAppProvider
,SelectorManager
,ServerWebSocketContainer
,ServletContextHandler.ServletContainerInitializerStarter
,ServletTester
,SPNEGOLoginService
,SslContextFactory
,UserStore
,VirtualThreadPool
,WebSocketClient
,WebSocketComponents
,WebSocketCoreClient
LifeCycle
implementation 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 LifeCycle
bean 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)
and unmanage(Object)
can be used to
explicitly control the life cycle relationship.
If adding a bean that is shared between multiple ContainerLifeCycle
instances, then it should be started
before being added, so it is unmanaged, or the API must be used to explicitly set it as unmanaged.
All EventListener
s added via addEventListener(EventListener)
are also added as beans and all beans
added via an addBean(Object)
method that are also EventListener
s are added as listeners via a
call to addEventListener(EventListener)
.
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, AbstractLifeCycle.StopException
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
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds the given bean, detecting whether to manage it or not.boolean
Adds the given bean, explicitly managing it or not.boolean
addEventListener
(EventListener listener) Add an event listener.void
addManaged
(LifeCycle lifecycle) Adds a managed lifecycle.boolean
void
destroy()
Destroys the managed Destroyable beans in the reverse order they were added.protected void
doStart()
Starts the managed lifecycle beans in the order they were added.protected void
doStop()
Stops the managed lifecycle beans in the reverse order they were added.dump()
void
dump
(Appendable out) Dump this object to an Appendable with no indent.void
dump
(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.protected void
dumpObjects
(Appendable out, String indent, Object... items) Dump this object, it's contained beans and additional items to an Appendablevoid
Dumps toSystem.err
.<T> T
getBeans()
<T> Collection<T>
<T> Collection<T>
getContainedBeans
(Class<T> clazz) protected <T> void
getContainedBeans
(Class<T> clazz, Collection<T> beans) protected final boolean
Add a bean in a way that is safe to call from a super constructor of thisContainerLifeCycle
: there are noContainer.Listener
s registered; the object itself is not aContainer.Listener
; thisLifeCycle
is not started or starting; and the is no debugging call tothis.toString()
.protected final boolean
installBean
(Object o, boolean managed) Add a bean in a way that is safe to call from a super constructor of thisContainerLifeCycle
: there are noContainer.Listener
s registered; the object itself is not aContainer.Listener
; thisLifeCycle
is not started or starting; and the is no debugging call tothis.toString()
.boolean
boolean
Test if this container manages a beanboolean
isUnmanaged
(Object bean) void
Manages a bean already contained by this aggregate, so that it is started/stopped/destroyed with this aggregate.boolean
removeBean
(Object o) Removes the given bean.void
Removes all beanboolean
removeEventListener
(EventListener listener) Remove an event listener.void
setBeans
(Collection<Object> beans) protected void
Starts the given lifecycle.protected void
Stops the given lifecycle.void
Unmanages a bean already contained by this aggregate, so that it is not started/stopped/destroyed with this aggregate.void
updateBean
(Object oldBean, Object newBean) void
updateBean
(Object oldBean, Object newBean, boolean managed) void
updateBeans
(Object[] oldBeans, Object[] newBeans) void
updateBeans
(Collection<?> oldBeans, Collection<?> newBeans) Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, 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.Container
getCachedBeans, getEventListeners
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
Constructor Details
-
ContainerLifeCycle
public ContainerLifeCycle()
-
-
Method Details
-
doStart
Starts the managed lifecycle beans in the order they were added.- Overrides:
doStart
in classAbstractLifeCycle
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
start
Starts the given lifecycle.- Parameters:
l
- the lifecycle to start- Throws:
Exception
- if unable to start lifecycle
-
stop
Stops the given lifecycle.- Parameters:
l
- the lifecycle to stop- Throws:
Exception
- if unable to stop the lifecycle
-
doStop
Stops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStop
in classAbstractLifeCycle
- Throws:
Exception
- If there was a problem stopping. Will cause a transition to FAILED state
-
destroy
public void destroy()Destroys the managed Destroyable beans in the reverse order they were added.- Specified by:
destroy
in interfaceDestroyable
-
contains
- Parameters:
bean
- the bean to test- Returns:
- whether this aggregate contains the bean
-
isManaged
Description copied from interface:Container
Test if this container manages a bean -
isAuto
- Parameters:
bean
- the bean to test- Returns:
- whether this aggregate contains the bean in auto state
-
isUnmanaged
- Parameters:
bean
- the bean to test- Returns:
- whether this aggregate contains the bean in auto state
-
addBean
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.This method should not be called from a constructor, instead use
installBean(Object)
-
addBean
Adds the given bean, explicitly managing it or not.
This method should not be called from a constructor, instead use
installBean(Object)
-
installBean
Add a bean in a way that is safe to call from a super constructor of thisContainerLifeCycle
: there are noContainer.Listener
s registered; the object itself is not aContainer.Listener
; thisLifeCycle
is not started or starting; and the is no debugging call tothis.toString()
.- Parameters:
o
- The bean to add- Returns:
- true if the bean was added
-
installBean
Add a bean in a way that is safe to call from a super constructor of thisContainerLifeCycle
: there are noContainer.Listener
s registered; the object itself is not aContainer.Listener
; thisLifeCycle
is not started or starting; and the is no debugging call tothis.toString()
.- Parameters:
o
- The bean to addmanaged
- true if the bean is to be managed.- Returns:
- true if the bean was added
-
addManaged
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
Description copied from interface:Container
Add an event listener. EventListeners added by this method are also added as beans.- Specified by:
addEventListener
in interfaceContainer
- Specified by:
addEventListener
in interfaceLifeCycle
- Overrides:
addEventListener
in classAbstractLifeCycle
- Parameters:
listener
- the listener to add- Returns:
- true if the listener was added
- See Also:
-
removeEventListener
Description copied from interface:Container
Remove an event listener.- Specified by:
removeEventListener
in interfaceContainer
- Specified by:
removeEventListener
in interfaceLifeCycle
- Overrides:
removeEventListener
in classAbstractLifeCycle
- Parameters:
listener
- the listener to remove- Returns:
- true if the listener was removed
- See Also:
-
manage
Manages a bean already contained by this aggregate, so that it is started/stopped/destroyed with this aggregate. -
unmanage
Unmanages a bean already contained by this aggregate, so that it is not started/stopped/destroyed with this aggregate. -
setBeans
-
getBeans
-
getBeans
-
getBean
-
removeBeans
public void removeBeans()Removes all bean -
removeBean
Description copied from interface:Container
Removes the given bean. If the bean is-aEventListener
, then also do an implicitContainer.removeEventListener(EventListener)
.- Specified by:
removeBean
in interfaceContainer
- Parameters:
o
- the bean to remove- Returns:
- whether the bean was removed
-
dumpStdErr
Dumps toSystem.err
.- See Also:
-
dump
-
dump
Description copied from interface:Dumpable
Dump 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.- Specified by:
dump
in interfaceDumpable
- Parameters:
out
- The appendable to dump toindent
- The indent to apply after any new lines.- Throws:
IOException
- if unable to write to Appendable
-
dump
Dump this object to an Appendable with no indent.- Parameters:
out
- The appendable to dump to.- Throws:
IOException
- May be thrown by the Appendable
-
dumpObjects
Dump 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:
IOException
- May be thrown by the Appendable
-
updateBean
-
updateBean
-
updateBeans
-
updateBeans
-
getContainedBeans
- Specified by:
getContainedBeans
in interfaceContainer
- Type Parameters:
T
- the bean type- Parameters:
clazz
- the class of the beans- Returns:
- the collection of beans of the given class from the
Container
hierarchy
-
getContainedBeans
-