org.eclipse.jetty.util.component

## Class AggregateLifeCycle

- java.lang.Object
- - org.eclipse.jetty.util.component.AbstractLifeCycle
  - - org.eclipse.jetty.util.component.AggregateLifeCycle

- All Implemented Interfaces:
    Destroyable, Dumpable, LifeCycle
  Direct Known Subclasses:
    AbstractConnector, AbstractHandler, DeploymentManager, HttpClient, WebSocketClientFactory

      public class AggregateLifeCycle
      extends AbstractLifeCycle
      implements Destroyable, Dumpable

  An AggregateLifeCycle is an `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.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `AbstractLifeCycle.AbstractLifeCycleListener`

    - ### Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

      `LifeCycle.Listener`

  - ### Field Summary

    - ### Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AggregateLifeCycle()`

  - ### Method Summary

    Methods
    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.

    - ### Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AggregateLifeCycle

          public AggregateLifeCycle()

  - ### Method Detail

    - #### doStart

          protected void doStart()
                          throws Exception

      Start the managed lifecycle beans in the order they were added.
      Overrides:
        `doStart` in class `AbstractLifeCycle`
      Throws:
        `Exception`
      See Also:
        `AbstractLifeCycle.doStart()`

    - #### doStop

          protected void doStop()
                         throws Exception

      Stop the joined lifecycle beans in the reverse order they were added.
      Overrides:
        `doStop` in class `AbstractLifeCycle`
      Throws:
        `Exception`
      See Also:
        `AbstractLifeCycle.doStart()`

    - #### destroy

          public void destroy()

      Destroy the joined Destroyable beans in the reverse order they were added.
      Specified by:
        `destroy` in interface `Destroyable`
      See Also:
        `Destroyable.destroy()`

    - #### contains

          public boolean contains(Object bean)

      Is the bean contained in the aggregate.
      Parameters:
        `bean` -
      Returns:
        True if the aggregate contains the bean

    - #### isManaged

          public boolean isManaged(Object bean)

      Is the bean joined to the aggregate.
      Parameters:
        `bean` -
      Returns:
        True if the aggregate contains the bean and it is joined

    - #### addBean

          public boolean addBean(Object o)

      Add an associated bean. If the bean is a `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.
      Parameters:
        `o` - the bean object to add
      Returns:
        true if the bean was added or false if it has already been added.

    - #### addBean

          public boolean addBean(Object o,
                        boolean managed)

      Add an associated lifecycle.
      Parameters:
        `o` - The lifecycle to add
        `managed` - True if the LifeCycle is to be joined, otherwise it will be disjoint.
      Returns:
        true if bean was added, false if already present.

    - #### manage

          public void manage(Object bean)

      Manage a bean by this aggregate, so that it is started/stopped/destroyed with the aggregate lifecycle.
      Parameters:
        `bean` - The bean to manage (must already have been added).

    - #### unmanage

          public void unmanage(Object bean)

      Unmanage a bean by this aggregate, so that it is not started/stopped/destroyed with the aggregate lifecycle.
      Parameters:
        `bean` - The bean to manage (must already have been added).

    - #### getBeans

          public Collection<Object> getBeans()

      Get dependent beans
      Returns:
        List of beans.

    - #### getBeans

          public <T> List<T> getBeans(Class<T> clazz)

      Get dependent beans of a specific class
      Parameters:
        `clazz` -
      Returns:
        List of beans.
      See Also:
        `addBean(Object)`

    - #### getBean

          public <T> T getBean(Class<T> clazz)

      Get dependent beans of a specific class. If more than one bean of the type exist, the first is returned.
      Parameters:
        `clazz` -
      Returns:
        bean or null
      See Also:
        `addBean(Object)`

    - #### removeBeans

          public void removeBeans()

      Remove all associated bean.

    - #### removeBean

          public boolean removeBean(Object o)

      Remove an associated bean.

    - #### dumpStdErr

          public void dumpStdErr()

    - #### dump

          public String dump()

      Specified by:
        `dump` in interface `Dumpable`

    - #### dump

          public static String dump(Dumpable dumpable)

    - #### dump

          public void dump(Appendable out)
                    throws IOException

      Throws:
        `IOException`

    - #### dumpThis

          protected void dumpThis(Appendable out)
                           throws IOException

      Throws:
        `IOException`

    - #### dumpObject

          public static void dumpObject(Appendable out,
                        Object o)
                                 throws IOException

      Throws:
        `IOException`

    - #### dump

          public void dump(Appendable out,
                  String indent)
                    throws IOException

      Specified by:
        `dump` in interface `Dumpable`
      Throws:
        `IOException`

    - #### dump

          public static void dump(Appendable out,
                  String indent,
                  Collection<?>... collections)
                           throws IOException

      Throws:
        `IOException`

Copyright © 1995-2015 Mort Bay Consulting. All Rights Reserved.