public abstract class AbstractDelegatingMutablePicoContainer extends AbstractDelegatingPicoContainer implements MutablePicoContainer
Constructor and Description |
---|
AbstractDelegatingMutablePicoContainer(MutablePicoContainer delegate) |
Modifier and Type | Method and Description |
---|---|
MutablePicoContainer |
addAdapter(ComponentAdapter<?> componentAdapter)
Register a component via a ComponentAdapter.
|
MutablePicoContainer |
addChildContainer(PicoContainer child)
Add a child container.
|
MutablePicoContainer |
addComponent(Object implOrInstance)
Register an arbitrary object.
|
MutablePicoContainer |
addComponent(Object componentKey,
Object componentImplementationOrInstance,
Parameter... parameters)
Register a component and creates specific instructions on which constructor to use, along with
which components and/or constants to provide as constructor arguments.
|
MutablePicoContainer |
addConfig(String name,
Object val)
Register a config item.
|
MutablePicoContainer |
as(Properties... properties)
You can set for the following operation only the characteristic of registration of a component on the fly.
|
MutablePicoContainer |
change(Properties... properties)
You can change the characteristic of registration of all subsequent components in this container.
|
void |
dispose()
Dispose this component.
|
MutablePicoContainer |
getDelegate() |
LifecycleState |
getLifecycleState()
Allow querying of the current lifecycle state of a MutablePicoContainer.
|
String |
getName()
Retrieve the name set (if any).
|
MutablePicoContainer |
makeChildContainer()
Make a child container, using both the same implementation of MutablePicoContainer as the parent
and identical behaviors as well.
|
boolean |
removeChildContainer(PicoContainer child)
Remove a child container from this container.
|
<T> ComponentAdapter<T> |
removeComponent(Object componentKey)
Unregister a component by key.
|
<T> ComponentAdapter<T> |
removeComponentByInstance(T componentInstance)
Unregister a component by instance.
|
void |
setLifecycleState(LifecycleState lifecycleState)
To assist ThreadLocal usage, LifecycleState can be set.
|
void |
setName(String name)
Name the container instance, to assist debugging or other indexing.
|
void |
start()
Start this component.
|
void |
stop()
Stop this component.
|
accept, equals, getComponent, getComponent, getComponent, getComponent, getComponentAdapter, getComponentAdapter, getComponentAdapter, getComponentAdapters, getComponentAdapters, getComponentAdapters, getComponents, getComponents, getConverters, getParent, toString
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
accept, getComponent, getComponent, getComponent, getComponent, getComponentAdapter, getComponentAdapter, getComponentAdapter, getComponentAdapters, getComponentAdapters, getComponentAdapters, getComponents, getComponents, getParent
public AbstractDelegatingMutablePicoContainer(MutablePicoContainer delegate)
public MutablePicoContainer addComponent(Object componentKey, Object componentImplementationOrInstance, Parameter... parameters) throws PicoCompositionException
MutablePicoContainer
new ComponentParameter(), new ComponentParameter("someService")
The default constructor for the component parameter indicates auto-wiring should take place for
that parameter.
new Parameter[0]
addComponent
in interface MutablePicoContainer
componentKey
- a key that identifies the component. Must be unique within the container. The type
of the key object has no semantic significance unless explicitly specified in the
documentation of the implementing container.componentImplementationOrInstance
- the component's implementation class. This must be a concrete class (ie, a
class that can be instantiated). Or an intance of the compoent.parameters
- the parameters that gives the container hints about what arguments to pass
to the constructor when it is instantiated. Container implementations may ignore
one or more of these hints.PicoCompositionException
- if registration of the component fails.Parameter
,
ConstantParameter
,
ComponentParameter
public MutablePicoContainer addComponent(Object implOrInstance) throws PicoCompositionException
MutablePicoContainer
addComponent(componentImplementation, componentImplementation)
.addComponent
in interface MutablePicoContainer
implOrInstance
- Component implementation or instancePicoCompositionException
- if registration fails.public MutablePicoContainer addConfig(String name, Object val)
MutablePicoContainer
addConfig
in interface MutablePicoContainer
name
- the name of the config itemval
- the value of the config itempublic MutablePicoContainer addAdapter(ComponentAdapter<?> componentAdapter) throws PicoCompositionException
MutablePicoContainer
addAdapter
in interface MutablePicoContainer
componentAdapter
- the adapterPicoCompositionException
- if registration fails.public <T> ComponentAdapter<T> removeComponent(Object componentKey)
MutablePicoContainer
removeComponent
in interface MutablePicoContainer
componentKey
- key of the component to unregister.public <T> ComponentAdapter<T> removeComponentByInstance(T componentInstance)
MutablePicoContainer
removeComponentByInstance
in interface MutablePicoContainer
componentInstance
- the component instance to unregister.public MutablePicoContainer addChildContainer(PicoContainer child)
MutablePicoContainer
addChildContainer
in interface MutablePicoContainer
child
- the child containerpublic boolean removeChildContainer(PicoContainer child)
MutablePicoContainer
removeChildContainer
in interface MutablePicoContainer
child
- the child containertrue
if the child container has been removed.public MutablePicoContainer change(Properties... properties)
MutablePicoContainer
change
in interface MutablePicoContainer
public MutablePicoContainer as(Properties... properties)
MutablePicoContainer
as
in interface MutablePicoContainer
public void dispose()
Disposable
dispose
in interface Disposable
public MutablePicoContainer makeChildContainer()
MutablePicoContainer
Note that for long-lived parent containers, you need to unregister child containers made with this call before disposing or you will leak memory. (Experience speaking here! )
Incorrect Example:
MutablePicoContainer parent = new PicoBuilder().withCaching().withLifecycle().build(); MutablePicoContainer child = parent.makeChildContainer(); child = null; //Child still retains in memory because parent still holds reference.
Correct Example:
MutablePicoContainer parent = new PicoBuilder().withCaching().withLifecycle().build(); MutablePicoContainer child = parent.makeChildContainer(); parent.removeChildContainer(child); //Remove the bi-directional references. child = null;
makeChildContainer
in interface MutablePicoContainer
public void start()
Startable
public void stop()
Startable
Disposable
if you need a single call at the definite end of the lifecycle.public MutablePicoContainer getDelegate()
getDelegate
in class AbstractDelegatingPicoContainer
public void setName(String name)
MutablePicoContainer
setName
in interface MutablePicoContainer
name
- the name to call it.public void setLifecycleState(LifecycleState lifecycleState)
MutablePicoContainer
setLifecycleState
in interface MutablePicoContainer
lifecycleState
- the lifecyle state to use.public LifecycleState getLifecycleState()
getLifecycleState
in interface MutablePicoContainer
public String getName()
getName
in interface MutablePicoContainer
setName
.Copyright © 2003–2015 Codehaus. All rights reserved.