public class AggregateLifeCycle extends AbstractLifeCycle implements Destroyable, Dumpable
LifeCycle
implementation for a collection of contained beans.
Beans can be added the AggregateLifeCycle 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 bean is added, if it is a LifeCycle
and it is already started, then it is assumed to be an unmanaged bean.
Otherwise 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 AggregateLifeCycle
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
LifeCycle.Listener
_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
Constructor and Description |
---|
AggregateLifeCycle() |
Modifier and Type | Method and Description |
---|---|
boolean |
addBean(Object o)
Add an associated bean.
|
boolean |
addBean(Object o,
boolean managed)
Add an associated lifecycle.
|
boolean |
contains(Object bean)
Is the bean contained in the aggregate.
|
void |
destroy()
Destroy the joined Destroyable beans in the reverse order they were added.
|
protected void |
doStart()
Start the managed lifecycle beans in the order they were added.
|
protected void |
doStop()
Stop the joined 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) |
static void |
dumpObject(Appendable out,
Object o) |
void |
dumpStdErr() |
protected void |
dumpThis(Appendable out) |
<T> T |
getBean(Class<T> clazz)
Get dependent beans of a specific class.
|
Collection<Object> |
getBeans()
Get dependent beans
|
<T> List<T> |
getBeans(Class<T> clazz)
Get dependent beans of a specific class
|
boolean |
isManaged(Object bean)
Is the bean joined to the aggregate.
|
void |
manage(Object bean)
Manage a bean by this aggregate, so that it is started/stopped/destroyed with the
aggregate lifecycle.
|
boolean |
removeBean(Object o)
Remove an associated bean.
|
void |
removeBeans()
Remove all associated bean.
|
void |
unmanage(Object bean)
Unmanage a bean by this aggregate, so that it is not started/stopped/destroyed with the
aggregate lifecycle.
|
addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
protected void doStart() throws Exception
doStart
in class AbstractLifeCycle
Exception
AbstractLifeCycle.doStart()
protected void doStop() throws Exception
doStop
in class AbstractLifeCycle
Exception
AbstractLifeCycle.doStart()
public void destroy()
destroy
in interface Destroyable
Destroyable.destroy()
public boolean contains(Object bean)
bean
- public boolean isManaged(Object bean)
bean
- public boolean addBean(Object o)
LifeCycle
, then it will be managed if it is not
already started and umanaged 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.o
- the bean object to addpublic boolean addBean(Object o, boolean managed)
o
- The lifecycle to addmanaged
- True if the LifeCycle is to be joined, otherwise it will be disjoint.public void manage(Object bean)
bean
- The bean to manage (must already have been added).public void unmanage(Object bean)
bean
- The bean to manage (must already have been added).public Collection<Object> getBeans()
public <T> List<T> getBeans(Class<T> clazz)
clazz
- addBean(Object)
public <T> T getBean(Class<T> clazz)
clazz
- addBean(Object)
public void removeBeans()
public boolean removeBean(Object o)
public void dumpStdErr()
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
public static void dump(Appendable out, String indent, Collection<?>... collections) throws IOException
IOException
Copyright © 1995-2015 Mort Bay Consulting. All Rights Reserved.