-
- All Known Implementing Classes:
AdaptiveExecutionStrategy,AttributeContainerMap,ContainerLifeCycle,EatWhatYouKill,ExecutorThreadPool,KeyStoreScanner,MonitoredQueuedThreadPool,QueuedThreadPool,Scanner
public interface ContainerA Container
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceContainer.InheritedListenerInherited Listener.static interfaceContainer.ListenerA listener for Container events.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleanaddBean(java.lang.Object o)Add a bean.booleanaddBean(java.lang.Object o, boolean managed)Adds the given bean, explicitly managing it or not.static booleanaddBean(java.lang.Object parent, java.lang.Object child)A utility method to add a bean to a container.static booleanaddBean(java.lang.Object parent, java.lang.Object child, boolean managed)A utility method to add a bean to a container.booleanaddEventListener(java.util.EventListener listener)Add an event listener.<T> TgetBean(java.lang.Class<T> clazz)java.util.Collection<java.lang.Object>getBeans()<T> java.util.Collection<T>getBeans(java.lang.Class<T> clazz)default <T> java.util.Collection<T>getCachedBeans(java.lang.Class<T> clazz)<T> java.util.Collection<T>getContainedBeans(java.lang.Class<T> clazz)default java.util.List<java.util.EventListener>getEventListeners()Get the beans added to the container that are EventListeners.booleanisManaged(java.lang.Object bean)Test if this container manages a beanvoidmanage(java.lang.Object bean)Manages a bean already contained by this aggregate, so that it is started/stopped/destroyed with this aggregate.booleanremoveBean(java.lang.Object o)Removes the given bean.static booleanremoveBean(java.lang.Object parent, java.lang.Object child)A utility method to remove a bean from a container.booleanremoveEventListener(java.util.EventListener listener)Remove an event listener.voidunmanage(java.lang.Object bean)Unmanages a bean already contained by this aggregate, so that it is not started/stopped/destroyed with this aggregate.
-
-
-
Method Detail
-
addBean
boolean addBean(java.lang.Object o)
Add a bean. If the bean is-aEventListener, then also do an implicitaddEventListener(EventListener).- Parameters:
o- the bean object to add- Returns:
- true if the bean was added, false if it was already present
-
addBean
boolean addBean(java.lang.Object o, boolean managed)Adds the given bean, explicitly managing it or not. If the bean is-aEventListener, then also do an implicitaddEventListener(EventListener).- Parameters:
o- The bean object to addmanaged- whether to managed the lifecycle of the bean- Returns:
- true if the bean was added, false if it was already present
-
getBeans
java.util.Collection<java.lang.Object> getBeans()
- Returns:
- the collection of beans known to this aggregate, in the order they were added.
-
getBeans
<T> java.util.Collection<T> getBeans(java.lang.Class<T> clazz)
- Type Parameters:
T- the Bean type- Parameters:
clazz- the class of the beans- Returns:
- a list of beans of the given class (or subclass), in the order they were added.
- See Also:
getBeans(),getContainedBeans(Class)
-
getCachedBeans
default <T> java.util.Collection<T> getCachedBeans(java.lang.Class<T> clazz)
- Type Parameters:
T- the Bean type- Parameters:
clazz- the class of the beans- Returns:
- a list of beans of the given class (or subclass), which may be cached/shared.
- See Also:
getBeans(),getContainedBeans(Class)
-
getBean
<T> T getBean(java.lang.Class<T> clazz)
- Type Parameters:
T- the Bean type- Parameters:
clazz- the class of the bean- Returns:
- the first bean (in order added) of a specific class (or subclass), or null if no such bean exist
-
removeBean
boolean removeBean(java.lang.Object o)
Removes the given bean. If the bean is-aEventListener, then also do an implicitremoveEventListener(EventListener).- Parameters:
o- the bean to remove- Returns:
- whether the bean was removed
-
addEventListener
boolean addEventListener(java.util.EventListener listener)
Add an event listener. EventListeners added by this method are also added as beans.- Parameters:
listener- the listener to add- Returns:
- true if the listener was added
- See Also:
Container.Listener,LifeCycle.Listener,addBean(Object)
-
removeEventListener
boolean removeEventListener(java.util.EventListener listener)
Remove an event listener.- Parameters:
listener- the listener to remove- Returns:
- true if the listener was removed
- See Also:
removeBean(Object)
-
unmanage
void unmanage(java.lang.Object bean)
Unmanages a bean already contained by this aggregate, so that it is not started/stopped/destroyed with this aggregate.- Parameters:
bean- The bean to unmanage (must already have been added).
-
manage
void manage(java.lang.Object bean)
Manages a bean already contained by this aggregate, so that it is started/stopped/destroyed with this aggregate.- Parameters:
bean- The bean to manage (must already have been added).
-
isManaged
boolean isManaged(java.lang.Object bean)
Test if this container manages a bean- Parameters:
bean- the bean to test- Returns:
- whether this aggregate contains and manages the bean
-
getContainedBeans
<T> java.util.Collection<T> getContainedBeans(java.lang.Class<T> clazz)
- Type Parameters:
T- the Bean type- Parameters:
clazz- the class of the beans- Returns:
- 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.
-
getEventListeners
default java.util.List<java.util.EventListener> getEventListeners()
Get the beans added to the container that are EventListeners. This is essentially equivalent togetBeans(EventListener.class);, except that:- The result may be precomputed, so it can be more efficient
- The result is ordered by the order added.
- The result is immutable.
- Returns:
- An unmodifiable list of EventListener beans
- See Also:
getBeans(Class)
-
addBean
static boolean addBean(java.lang.Object parent, java.lang.Object child)A utility method to add a bean to a container.- Parameters:
parent- the parent container.child- the child bean.- Returns:
- true if the child was added as a bean, false if parent was not instance of
Containeror bean was already present.
-
addBean
static boolean addBean(java.lang.Object parent, java.lang.Object child, boolean managed)A utility method to add a bean to a container.- Parameters:
parent- the parent container.child- the child bean.managed- whether to managed the lifecycle of the bean.- Returns:
- true if the child was added as a bean, false if parent was not instance of
Containeror bean was already present.
-
removeBean
static boolean removeBean(java.lang.Object parent, java.lang.Object child)A utility method to remove a bean from a container.- Parameters:
parent- the parent container.child- the child bean.- Returns:
- true if parent was an instance of
Containerand the bean was removed.
-
-