@ManagedObject(value="Implementation of Container and LifeCycle") public class ContainerLifeCycle extends AbstractLifeCycle implements Container, Destroyable, Dumpable
LifeCycle
implementation for a collection of contained beans.
Beans can be added 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 it's lifecycle must be managed externally.
When a LifeCycle
bean is added with out a managed state being specified, if it is already started, then it is assumed to be an unmanaged bean.
If it is not started then it is added in and auto managed state, which means that when this bean is itself started, it if must also start the added bean, then it
is switched from Auto to be a managed bean. Otherwise it becomes an unmanaged bean. Simply put an Auto 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.
AbstractLifeCycle.AbstractLifeCycleListener
Container.InheritedListener, Container.Listener
LifeCycle.Listener
Constructor and Description |
---|
ContainerLifeCycle() |
Modifier and Type | Method and Description |
---|---|
boolean |
addBean(Object o)
Adds the given bean, detecting whether to manage it or not.
|
boolean |
addBean(Object o,
boolean managed)
Adds the given bean, explicitly managing it or not.
|
boolean |
addBean(Object o,
org.eclipse.jetty.util.component.ContainerLifeCycle.Managed managed) |
boolean |
contains(Object bean) |
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.
|
String |
dump() |
void |
dump(Appendable out) |
void |
dump(Appendable out,
String indent) |
static void |
dump(Appendable out,
String indent,
Collection<?>... collections) |
static String |
dump(Dumpable dumpable) |
protected void |
dumpBeans(Appendable out,
String indent,
Collection<?>... collections) |
static void |
dumpObject(Appendable out,
Object o) |
void |
dumpStdErr()
Dumps to
System.err . |
protected void |
dumpThis(Appendable out) |
<T> T |
getBean(Class<T> clazz) |
Collection<Object> |
getBeans() |
<T> Collection<T> |
getBeans(Class<T> clazz) |
boolean |
isManaged(Object bean) |
void |
manage(Object bean)
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 |
removeBeans()
Removes all bean
|
void |
setBeans(Collection<Object> beans) |
void |
setStopTimeout(long stopTimeout) |
protected void |
start(LifeCycle l)
Starts the given lifecycle.
|
void |
unmanage(Object bean)
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 |
updateBeans(Object[] oldBeans,
Object[] newBeans) |
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
protected void doStart() throws Exception
doStart
in class AbstractLifeCycle
Exception
protected void start(LifeCycle l) throws Exception
l
- Exception
protected void doStop() throws Exception
doStop
in class AbstractLifeCycle
Exception
public void destroy()
destroy
in interface Destroyable
public boolean contains(Object bean)
bean
- the bean to testpublic boolean isManaged(Object bean)
bean
- the bean to testpublic boolean addBean(Object o)
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.public boolean addBean(Object o, boolean managed)
o
- The bean object to addmanaged
- whether to managed the lifecycle of the beanpublic boolean addBean(Object o, org.eclipse.jetty.util.component.ContainerLifeCycle.Managed managed)
public void manage(Object bean)
bean
- The bean to manage (must already have been added).public void unmanage(Object bean)
bean
- The bean to unmanage (must already have been added).public Collection<Object> getBeans()
getBeans
in interface Container
Container.getBean(Class)
public void setBeans(Collection<Object> beans)
public <T> Collection<T> getBeans(Class<T> clazz)
getBeans
in interface Container
clazz
- the class of the beansContainer.getBeans()
public <T> T getBean(Class<T> clazz)
public void removeBeans()
public boolean removeBean(Object o)
Container
removeBean
in interface Container
#removeBeans()
public void setStopTimeout(long stopTimeout)
setStopTimeout
in class AbstractLifeCycle
@ManagedOperation(value="Dump the object to stderr") public void dumpStdErr()
System.err
.dump()
@ManagedOperation(value="Dump the object to a string") public String dump()
public void dump(Appendable out) throws IOException
IOException
protected void dumpThis(Appendable out) throws IOException
IOException
public static void dumpObject(Appendable out, Object o) throws IOException
IOException
public void dump(Appendable out, String indent) throws IOException
dump
in interface Dumpable
IOException
protected void dumpBeans(Appendable out, String indent, Collection<?>... collections) throws IOException
IOException
public static void dump(Appendable out, String indent, Collection<?>... collections) throws IOException
IOException
Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.