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 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.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| pack-priv static enum |
| Modifier and Type | Field and Description |
|---|---|
| private final List | |
| private boolean | |
| private boolean | |
| private final List | |
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if the bean was added, false if it was already presentthe bean object to add o)Implements org. |
| public boolean | Returns: true if the bean was added, false if it was already presentThe bean object to add o, boolean whether to managed the lifecycle of the bean managed)Implements org. |
| private boolean | |
| public boolean | addEventListener(EventListener
the listener to add listener)Overrides org. Implements org. |
| public void | |
| public boolean | |
| public void | destroy()
Implements org. |
| protected void | doStart()
Overrides org. |
| protected void | doStop()
Overrides org. |
| public String | |
| public void | dump(Appendable
The appendable to dump to out, String The indent to apply after any new lines. indent)Implements org. |
| public void | |
| 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. |
| private ContainerLifeCycle. | |
| public Collection | |
| public <T> Collection | getBeans(Class<T>
the class of the beans clazz)Implements org. |
| public <T> Collection | getContainedBeans(Class<T>
the class of the beans clazz)Implements org. |
| protected <T> void | |
| public boolean | |
| public boolean | Returns: whether this aggregate contains and manages the beanthe bean to test bean)Implements org. |
| public boolean | Returns: whether this aggregate contains the bean in auto statethe bean to test bean)
|
| public void | manage(Object
The bean to manage (must already have been added). bean)Implements org. |
| private void | |
| private boolean | |
| public boolean | removeBean(Object
the bean to remove o)Implements org. |
| public void | |
| public boolean | removeEventListener(EventListener
the listener to remove listener)Overrides org. Implements org. |
| public void | |
| protected void | |
| protected void | |
| public void | unmanage(Object
The bean to unmanage (must already have been added). bean)Implements org. |
| private void | |
| public void | |
| public void | |
| public void | |
| public void |
| _beans | back to summary |
|---|---|
| private final List<ContainerLifeCycle. | |
| _destroyed | back to summary |
|---|---|
| private boolean _destroyed | |
| _doStarted | back to summary |
|---|---|
| private boolean _doStarted | |
| _listeners | back to summary |
|---|---|
| private final List<Container. | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG Hides org. | |
| ContainerLifeCycle | back to summary |
|---|---|
| public ContainerLifeCycle() | |
| addBean | back to summary |
|---|---|
| public boolean addBean(Object o) Implements org. Adds the given bean, detecting whether to manage it or not.
If the bean is a | |
| addBean | back to summary |
|---|---|
| public boolean addBean(Object o, boolean managed) Implements org. Adds the given bean, explicitly managing it or not. | |
| addBean | back to summary |
|---|---|
| private boolean addBean(Object o, ContainerLifeCycle. | |
| addEventListener | back to summary |
|---|---|
| public boolean addEventListener(EventListener listener) Overrides org. Implements org. Doc from org. Add an event listener. EventListeners added by this method are also added as beans.
| |
| addManaged | back 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
| |
| contains | back to summary |
|---|---|
public boolean contains(Object bean)
| |
| destroy | back to summary |
|---|---|
| public void destroy() Implements org. Destroys the managed Destroyable beans in the reverse order they were added.
| |
| doStart | back to summary |
|---|---|
| protected void doStart() throws Exception Overrides org. Starts the managed lifecycle beans in the order they were added.
| |
| doStop | back to summary |
|---|---|
| protected void doStop() throws Exception Overrides org. Stops the managed lifecycle beans in the reverse order they were added.
| |
| dump | back to summary |
|---|---|
| public String dump() Overrides default org.
| |
| dump | back to summary |
|---|---|
| public void dump(Appendable out, String indent) throws IOException Implements org. Doc from org. 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.
| |
| dump | back to summary |
|---|---|
| public void dump(Appendable out) throws IOException Dump this object to an Appendable with no indent.
| |
| dumpObjects | back 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
| |
| dumpStdErr | back to summary |
|---|---|
| public void dumpStdErr() Dumps to
| |
| getBean | back to summary |
|---|---|
| public <T> T getBean(Class<T> clazz) Implements org.
| |
| getBean | back to summary |
|---|---|
| private ContainerLifeCycle. | |
| getBeans | back to summary |
|---|---|
| public Collection Implements org.
| |
| getBeans | back to summary |
|---|---|
| public <T> Collection Implements org.
| |
| getContainedBeans | back to summary |
|---|---|
| public <T> Collection Implements org.
| |
| getContainedBeans | back to summary |
|---|---|
| protected <T> void getContainedBeans(Class<T> clazz, Collection<T> beans) | |
| isAuto | back to summary |
|---|---|
public boolean isAuto(Object bean)
| |
| isManaged | back to summary |
|---|---|
| public boolean isManaged(Object bean) Implements org. Doc from org. Test if this container manages a bean | |
| isUnmanaged | back to summary |
|---|---|
public boolean isUnmanaged(Object bean)
| |
| manage | back to summary |
|---|---|
| public void manage(Object bean) Implements org. Manages a bean already contained by this aggregate, so that it is started/stopped/destroyed with this aggregate. | |
| manage | back to summary |
|---|---|
| private void manage(ContainerLifeCycle. | |
| remove | back to summary |
|---|---|
| private boolean remove(ContainerLifeCycle. | |
| removeBean | back to summary |
|---|---|
| public boolean removeBean(Object o) Implements org. Doc from org. Removes the given bean.
If the bean is-a | |
| removeBeans | back to summary |
|---|---|
| public void removeBeans() Removes all bean | |
| removeEventListener | back to summary |
|---|---|
| public boolean removeEventListener(EventListener listener) Overrides org. Implements org. Doc from org. Remove an event listener.
| |
| setBeans | back to summary |
|---|---|
| public void setBeans(Collection<Object> beans) | |
| start | back to summary |
|---|---|
| protected void start(LifeCycle l) throws Exception Starts the given lifecycle. | |
| stop | back to summary |
|---|---|
| protected void stop(LifeCycle l) throws Exception Stops the given lifecycle. | |
| unmanage | back to summary |
|---|---|
| public void unmanage(Object bean) Implements org. Unmanages a bean already contained by this aggregate, so that it is not started/stopped/destroyed with this aggregate. | |
| unmanage | back to summary |
|---|---|
| private void unmanage(ContainerLifeCycle. | |
| updateBean | back to summary |
|---|---|
| public void updateBean(Object oldBean, final Object newBean) | |
| updateBean | back to summary |
|---|---|
| public void updateBean(Object oldBean, final Object newBean, boolean managed) | |
| updateBeans | back to summary |
|---|---|
| public void updateBeans(Object[] oldBeans, final Object[] newBeans) | |
| updateBeans | back to summary |
|---|---|
| public void updateBeans(final Collection<?> oldBeans, final Collection<?> newBeans) | |
| Modifier and Type | Field and Description |
|---|---|
| private final Object | |
| private volatile ContainerLifeCycle. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public boolean | |
| public String |
| _bean | back to summary |
|---|---|
| private final Object _bean | |
| _managed | back to summary |
|---|---|
| private volatile ContainerLifeCycle. | |
| Bean | back to summary |
|---|---|
| private Bean(Object b) | |
| isManageable | back to summary |
|---|---|
| public boolean isManageable() | |
| isManaged | back to summary |
|---|---|
| public boolean isManaged() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Modifier and Type | Field and Description |
|---|---|
| public static final ContainerLifeCycle. | |
| public static final ContainerLifeCycle. | |
| public static final ContainerLifeCycle. | |
| public static final ContainerLifeCycle. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static ContainerLifeCycle. | |
| public static ContainerLifeCycle. |
| AUTO | back to summary |
|---|---|
| public static final ContainerLifeCycle. | |
| MANAGED | back to summary |
|---|---|
| public static final ContainerLifeCycle. | |
| POJO | back to summary |
|---|---|
| public static final ContainerLifeCycle. | |
| UNMANAGED | back to summary |
|---|---|
| public static final ContainerLifeCycle. | |
| Managed | back to summary |
|---|---|
| private Managed() | |
| valueOf | back to summary |
|---|---|
| public static ContainerLifeCycle. | |
| values | back to summary |
|---|---|
| public static ContainerLifeCycle. | |