Top Description Inners Fields Constructors Methods
org.eclipse.jetty.util.component

public Class ContainerLifeCycle

extends AbstractLifeCycle
implements Container, Destroyable, DumpableContainer
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Container
Known Direct Subclasses
org.eclipse.jetty.util.compression.CompressionPool, org.eclipse.jetty.util.ssl.KeyStoreScanner, org.eclipse.jetty.util.ssl.SslContextFactory, org.eclipse.jetty.util.thread.ExecutorThreadPool, org.eclipse.jetty.util.thread.QueuedThreadPool, org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy, org.eclipse.jetty.util.Scanner, org.eclipse.jetty.util.component.AttributeContainerMap
Annotations
@ManagedObject:Implementation of Container and LifeCycle
Imports
java.io.IOException, java.util.ArrayList, .Arrays, .Collection, .Collections, .EventListener, .HashSet, .List, .Objects, .Set, java.util.concurrent.CopyOnWriteArrayList, org.eclipse.jetty.util.ExceptionUtil, org.eclipse.jetty.util.annotation.ManagedObject, .ManagedOperation, org.slf4j.Logger, .LoggerFactory

A ContainerLifeCycle is an 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:

When the container is started, then all contained managed beans will also be started. Any contained AUTO beans will be check for their status and if already started will be switched unmanaged beans, else they will be started and switched to managed beans. Beans added after a container is started are not started and their state needs to be explicitly managed.

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 EventListeners added via addEventListener(EventListener) are also added as beans and all beans added via an addBean(Object) method that are also EventListeners 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 and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static enum

Field Summary

Modifier and TypeField and Description
private final List<ContainerLifeCycle.Bean>
private boolean
private boolean
private final List<Container.Listener>
private static final Logger
Inherited from org.eclipse.jetty.util.component.AbstractLifeCycle:
FAILEDSTARTEDSTARTINGSTOPPEDSTOPPING

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the bean was added, false if it was already present
addBean
(Object
the bean object to add
o
)

Implements org.eclipse.jetty.util.component.Container.addBean.

Adds the given bean, detecting whether to manage it or not.
public boolean

Returns:

true if the bean was added, false if it was already present
addBean
(Object
The bean object to add
o
,
boolean
whether to managed the lifecycle of the bean
managed
)

Implements org.eclipse.jetty.util.component.Container.addBean.

Adds the given bean, explicitly managing it or not.
private boolean
public boolean
public void
addManaged(LifeCycle
the managed lifecycle to add
lifecycle
)

Adds a managed lifecycle.

public boolean

Returns:

whether this aggregate contains the bean
contains
(Object
the bean to test
bean
)

public void
destroy()

Implements org.eclipse.jetty.util.component.Destroyable.destroy.

Destroys the managed Destroyable beans in the reverse order they were added.
protected void
doStart()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.
protected void
doStop()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.
public String
public void
dump(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines.
indent
)

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.
public void
dump(Appendable
The appendable to dump to.
out
)

Dump this object to an Appendable with no indent.

protected void
dumpObjects(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines
indent
,
Object...
Additional items to be dumped as contained.
items
)

Dump this object, it's contained beans and additional items to an Appendable

public void
public <T> T
getBean(Class<T>
the class of the bean
clazz
)

Implements org.eclipse.jetty.util.component.Container.getBean.

private ContainerLifeCycle.Bean
public Collection<Object>
public <T> Collection<T>
getBeans(Class<T>
the class of the beans
clazz
)

Implements org.eclipse.jetty.util.component.Container.getBeans.

public <T> Collection<T>
protected <T> void
getContainedBeans(Class<T> clazz, Collection<T> beans)

public boolean

Returns:

whether this aggregate contains the bean in auto state
isAuto
(Object
the bean to test
bean
)

public boolean

Returns:

whether this aggregate contains and manages the bean
isManaged
(Object
the bean to test
bean
)

Implements org.eclipse.jetty.util.component.Container.isManaged.

Test if this container manages a bean
public boolean

Returns:

whether this aggregate contains the bean in auto state
isUnmanaged
(Object
the bean to test
bean
)

public void
manage(Object
The bean to manage (must already have been added).
bean
)

Implements org.eclipse.jetty.util.component.Container.manage.

Manages a bean already contained by this aggregate, so that it is started/stopped/destroyed with this aggregate.
private void
private boolean
public boolean
removeBean(Object
the bean to remove
o
)

Implements org.eclipse.jetty.util.component.Container.removeBean.

Removes the given bean.
public void
removeBeans()

Removes all bean

public boolean
public void
protected void
start(LifeCycle
the lifecycle to start
l
)

Starts the given lifecycle.

protected void
stop(LifeCycle
the lifecycle to stop
l
)

Stops the given lifecycle.

public void
unmanage(Object
The bean to unmanage (must already have been added).
bean
)

Implements org.eclipse.jetty.util.component.Container.unmanage.

Unmanages a bean already contained by this aggregate, so that it is not started/stopped/destroyed with this aggregate.
private void
public void
updateBean(Object oldBean, final Object newBean)

public void
updateBean(Object oldBean, final Object newBean, boolean managed)

public void
updateBeans(Object[] oldBeans, final Object[] newBeans)

public void
updateBeans(final Collection<?> oldBeans, final Collection<?> newBeans)

Inherited from org.eclipse.jetty.util.component.AbstractLifeCycle:
getEventListenersgetStategetStateisFailedisRunningisStartedisStartingisStoppedisStoppingsetEventListenersstartstoptoString

Field Detail

_beansback to summary
private final List<ContainerLifeCycle.Bean> _beans
_destroyedback to summary
private boolean _destroyed
_doStartedback to summary
private boolean _doStarted
_listenersback to summary
private final List<Container.Listener> _listeners
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.util.component.AbstractLifeCycle.LOG.

Constructor Detail

ContainerLifeCycleback to summary
public ContainerLifeCycle()

Method Detail

addBeanback to summary
public boolean addBean(Object o)

Implements org.eclipse.jetty.util.component.Container.addBean.

Adds the given bean, detecting whether to manage it or not. If the bean is a LifeCycle, then it will be managed if it is not already started and not managed if it is already started. The addBean(Object, boolean) method should be used if this is not correct, or the manage(Object) and unmanage(Object) methods may be used after an add to change the status.

Parameters
o:Object

the bean object to add

Returns:boolean

true if the bean was added, false if it was already present

Annotations
@Override
addBeanback to summary
public boolean addBean(Object o, boolean managed)

Implements org.eclipse.jetty.util.component.Container.addBean.

Adds the given bean, explicitly managing it or not.

Parameters
o:Object

The bean object to add

managed:boolean

whether to managed the lifecycle of the bean

Returns:boolean

true if the bean was added, false if it was already present

Annotations
@Override
addBeanback to summary
private boolean addBean(Object o, ContainerLifeCycle.Managed managed)
addEventListenerback to summary
public boolean addEventListener(EventListener listener)

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.addEventListener.

Implements org.eclipse.jetty.util.component.Container.addEventListener, org.eclipse.jetty.util.component.LifeCycle.addEventListener.

Doc from org.eclipse.jetty.util.component.Container.addEventListener.

Add an event listener. EventListeners added by this method are also added as beans.

Parameters
listener:EventListener

the listener to add

Returns:boolean

true if the listener was added

Annotations
@Override
addManagedback to summary
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:LifeCycle

the managed lifecycle to add

containsback to summary
public boolean contains(Object bean)
Parameters
bean:Object

the bean to test

Returns:boolean

whether this aggregate contains the bean

destroyback to summary
public void destroy()

Implements org.eclipse.jetty.util.component.Destroyable.destroy.

Destroys the managed Destroyable beans in the reverse order they were added.

Annotations
@Override
doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

If there was a problem starting. Will cause a transition to FAILED state

doStopback to summary
protected void doStop() throws Exception

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

If there was a problem stopping. Will cause a transition to FAILED state

dumpback to summary
public String dump()

Overrides default org.eclipse.jetty.util.component.Dumpable.dump.

Annotations
@Override
@ManagedOperation:Dump the object to a string
dumpback to summary
public void dump(Appendable out, String indent) throws IOException

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Doc from org.eclipse.jetty.util.component.Dumpable.dump.

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.

Parameters
out:Appendable

The appendable to dump to

indent:String

The indent to apply after any new lines.

Annotations
@Override
Exceptions
IOException:
if unable to write to Appendable
dumpback to summary
public void dump(Appendable out) throws IOException

Dump this object to an Appendable with no indent.

Parameters
out:Appendable

The appendable to dump to.

Exceptions
IOException:
May be thrown by the Appendable
dumpObjectsback to summary
protected void dumpObjects(Appendable out, String indent, Object... items) throws IOException

Dump this object, it's contained beans and additional items to an Appendable

Parameters
out:Appendable

The appendable to dump to

indent:String

The indent to apply after any new lines

items:Object[]

Additional items to be dumped as contained.

Exceptions
IOException:
May be thrown by the Appendable
dumpStdErrback to summary
public void dumpStdErr()

Dumps to System#err.

Annotations
@ManagedOperation:Dump the object to stderr
See Also
dump()
getBeanback to summary
public <T> T getBean(Class<T> clazz)

Implements org.eclipse.jetty.util.component.Container.getBean.

Parameters
<T>

Doc from org.eclipse.jetty.util.component.Container.getBean. the Bean type

clazz:Class<T>

Doc from org.eclipse.jetty.util.component.Container.getBean.

the class of the bean

Returns:T

Doc from org.eclipse.jetty.util.component.Container.getBean.

the first bean (in order added) of a specific class (or subclass), or null if no such bean exist

Annotations
@Override
getBeanback to summary
private ContainerLifeCycle.Bean getBean(Object o)
getBeansback to summary
public Collection<Object> getBeans()

Implements org.eclipse.jetty.util.component.Container.getBeans.

Returns:Collection<Object>

Doc from org.eclipse.jetty.util.component.Container.getBeans.

the collection of beans known to this aggregate, in the order they were added.

Annotations
@Override
getBeansback to summary
public <T> Collection<T> getBeans(Class<T> clazz)

Implements org.eclipse.jetty.util.component.Container.getBeans.

Parameters
<T>

Doc from org.eclipse.jetty.util.component.Container.getBeans. the Bean type

clazz:Class<T>

Doc from org.eclipse.jetty.util.component.Container.getBeans.

the class of the beans

Returns:Collection<T>

Doc from org.eclipse.jetty.util.component.Container.getBeans.

a list of beans of the given class (or subclass), in the order they were added.

Annotations
@Override
getContainedBeansback to summary
public <T> Collection<T> getContainedBeans(Class<T> clazz)

Implements org.eclipse.jetty.util.component.Container.getContainedBeans.

Parameters
<T>

Doc from org.eclipse.jetty.util.component.Container.getContainedBeans. the Bean type

clazz:Class<T>

Doc from org.eclipse.jetty.util.component.Container.getContainedBeans.

the class of the beans

Returns:Collection<T>

Doc from org.eclipse.jetty.util.component.Container.getContainedBeans.

the list of beans of the given class from the entire Container hierarchy. The order is by depth first and then the order beans were added.

Annotations
@Override
getContainedBeansback to summary
protected <T> void getContainedBeans(Class<T> clazz, Collection<T> beans)
isAutoback to summary
public boolean isAuto(Object bean)
Parameters
bean:Object

the bean to test

Returns:boolean

whether this aggregate contains the bean in auto state

isManagedback to summary
public boolean isManaged(Object bean)

Implements org.eclipse.jetty.util.component.Container.isManaged.

Doc from org.eclipse.jetty.util.component.Container.isManaged.

Test if this container manages a bean

Parameters
bean:Object

the bean to test

Returns:boolean

whether this aggregate contains and manages the bean

Annotations
@Override
isUnmanagedback to summary
public boolean isUnmanaged(Object bean)
Parameters
bean:Object

the bean to test

Returns:boolean

whether this aggregate contains the bean in auto state

manageback to summary
public void manage(Object bean)

Implements org.eclipse.jetty.util.component.Container.manage.

Manages a bean already contained by this aggregate, so that it is started/stopped/destroyed with this aggregate.

Parameters
bean:Object

The bean to manage (must already have been added).

Annotations
@Override
manageback to summary
private void manage(ContainerLifeCycle.Bean bean)
removeback to summary
private boolean remove(ContainerLifeCycle.Bean bean)
removeBeanback to summary
public boolean removeBean(Object o)

Implements org.eclipse.jetty.util.component.Container.removeBean.

Doc from org.eclipse.jetty.util.component.Container.removeBean.

Removes the given bean. If the bean is-a EventListener, then also do an implicit removeEventListener(EventListener).

Parameters
o:Object

the bean to remove

Returns:boolean

whether the bean was removed

Annotations
@Override
removeBeansback to summary
public void removeBeans()

Removes all bean

removeEventListenerback to summary
public boolean removeEventListener(EventListener listener)

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.removeEventListener.

Implements org.eclipse.jetty.util.component.Container.removeEventListener, org.eclipse.jetty.util.component.LifeCycle.removeEventListener.

Doc from org.eclipse.jetty.util.component.Container.removeEventListener.

Remove an event listener.

Parameters
listener:EventListener

the listener to remove

Returns:boolean

true if the listener was removed

Annotations
@Override
setBeansback to summary
public void setBeans(Collection<Object> beans)
startback to summary
protected void start(LifeCycle l) throws Exception

Starts the given lifecycle.

Parameters
l:LifeCycle

the lifecycle to start

Exceptions
Exception:
if unable to start lifecycle
stopback to summary
protected void stop(LifeCycle l) throws Exception

Stops the given lifecycle.

Parameters
l:LifeCycle

the lifecycle to stop

Exceptions
Exception:
if unable to stop the lifecycle
unmanageback to summary
public void unmanage(Object bean)

Implements org.eclipse.jetty.util.component.Container.unmanage.

Unmanages a bean already contained by this aggregate, so that it is not started/stopped/destroyed with this aggregate.

Parameters
bean:Object

The bean to unmanage (must already have been added).

Annotations
@Override
unmanageback to summary
private void unmanage(ContainerLifeCycle.Bean bean)
updateBeanback to summary
public void updateBean(Object oldBean, final Object newBean)
updateBeanback to summary
public void updateBean(Object oldBean, final Object newBean, boolean managed)
updateBeansback to summary
public void updateBeans(Object[] oldBeans, final Object[] newBeans)
updateBeansback to summary
public void updateBeans(final Collection<?> oldBeans, final Collection<?> newBeans)
org.eclipse.jetty.util.component back to summary

private Class ContainerLifeCycle.Bean

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Object
private volatile ContainerLifeCycle.Managed

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_beanback to summary
private final Object _bean
_managedback to summary
private volatile ContainerLifeCycle.Managed _managed

Constructor Detail

Beanback to summary
private Bean(Object b)

Method Detail

isManageableback to summary
public boolean isManageable()
isManagedback to summary
public boolean isManaged()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.eclipse.jetty.util.component back to summary

pack-priv final Enum ContainerLifeCycle.Managed

extends Enum<ContainerLifeCycle.Managed>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final ContainerLifeCycle.Managed
public static final ContainerLifeCycle.Managed
public static final ContainerLifeCycle.Managed
public static final ContainerLifeCycle.Managed

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ContainerLifeCycle.Managed
public static ContainerLifeCycle.Managed[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

AUTOback to summary
public static final ContainerLifeCycle.Managed AUTO
MANAGEDback to summary
public static final ContainerLifeCycle.Managed MANAGED
POJOback to summary
public static final ContainerLifeCycle.Managed POJO
UNMANAGEDback to summary
public static final ContainerLifeCycle.Managed UNMANAGED

Constructor Detail

Managedback to summary
private Managed()

Method Detail

valueOfback to summary
public static ContainerLifeCycle.Managed valueOf(String name)
valuesback to summary
public static ContainerLifeCycle.Managed[] values()