|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.picocontainer.DefaultPicoContainer
org.picocontainer.gems.containers.ReusablePicoContainer
public class ReusablePicoContainer
Normal PicoContainers are meant to be created, started, stopped, disposed and garbage collected. The goal of this container is to reduce the number of registration calls (and therefore objects created) in areas where performance is key (for example, this might be used in NanoContainer request containers).
It accomplishes its goal in two ways:
(1) Once a container is disposed
of, start() may be called again, allowing for recycling of the container. (This is default
behavior with a picocontainer)
(2) All instance registrations will be unregistered when stop is called. (For example, HttpServletRequest would be removed), and all component adapter instance values are flushed.
It is still up to the builder of this container to decide where to store its reference. Since it is reusable, it needs to be stored someplace that doesn't easily expire. Probably the most common storage location would be ThreadLocal storage. HttpSession might be another valid storage location.
Field Summary |
---|
Fields inherited from class org.picocontainer.DefaultPicoContainer |
---|
componentFactory, componentMonitor, lifecycleStrategy, orderedComponentAdapters |
Constructor Summary | |
---|---|
ReusablePicoContainer()
|
|
ReusablePicoContainer(ComponentFactory componentFactory)
|
|
ReusablePicoContainer(ComponentFactory componentFactory,
LifecycleStrategy lifecycleStrategy,
PicoContainer parent)
|
|
ReusablePicoContainer(ComponentFactory componentFactory,
LifecycleStrategy lifecycleStrategy,
PicoContainer parent,
ComponentMonitor componentMonitor)
|
|
ReusablePicoContainer(ComponentFactory componentFactory,
PicoContainer parent)
|
|
ReusablePicoContainer(ComponentMonitor monitor)
|
|
ReusablePicoContainer(ComponentMonitor monitor,
LifecycleStrategy lifecycleStrategy,
PicoContainer parent)
|
|
ReusablePicoContainer(ComponentMonitor monitor,
PicoContainer parent)
|
|
ReusablePicoContainer(LifecycleStrategy lifecycleStrategy,
PicoContainer parent)
|
|
ReusablePicoContainer(PicoContainer parent)
|
Method Summary | ||
---|---|---|
MutablePicoContainer |
addAdapter(ComponentAdapter<?> componentAdapter)
Register a component via a ComponentAdapter. |
|
MutablePicoContainer |
addAdapter(ComponentAdapter<?> componentAdapter,
Properties properties)
|
|
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 |
makeChildContainer()
Make a child container, using the same implementation of MutablePicoContainer as the parent. |
|
|
removeComponent(Object componentKey)
Unregister a component by key. |
|
|
removeComponentByInstance(T componentInstance)
Unregister a component by instance. |
|
void |
stop()
Stop the components of this PicoContainer and all its logical child containers. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ReusablePicoContainer()
public ReusablePicoContainer(ComponentFactory componentFactory, LifecycleStrategy lifecycleStrategy, PicoContainer parent, ComponentMonitor componentMonitor)
public ReusablePicoContainer(ComponentFactory componentFactory, LifecycleStrategy lifecycleStrategy, PicoContainer parent)
public ReusablePicoContainer(ComponentFactory componentFactory, PicoContainer parent)
public ReusablePicoContainer(ComponentFactory componentFactory)
public ReusablePicoContainer(ComponentMonitor monitor, LifecycleStrategy lifecycleStrategy, PicoContainer parent)
public ReusablePicoContainer(ComponentMonitor monitor, PicoContainer parent)
public ReusablePicoContainer(ComponentMonitor monitor)
public ReusablePicoContainer(LifecycleStrategy lifecycleStrategy, PicoContainer parent)
public ReusablePicoContainer(PicoContainer parent)
Method Detail |
---|
public MutablePicoContainer addComponent(Object componentKey, Object componentImplementationOrInstance, Parameter... parameters) throws PicoCompositionException
DefaultPicoContainer
new ComponentParameter(), new ComponentParameter("someService")
The default constructor for the component parameter indicates auto-wiring should take place for
that parameter.
new Parameter[0]
ComponentFactory
passed to the container's constructor.
addComponent
in interface MutablePicoContainer
addComponent
in class DefaultPicoContainer
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
DefaultPicoContainer
addComponent(componentImplementation, componentImplementation)
.
The returned ComponentAdapter will be an InstanceAdapter
.
addComponent
in interface MutablePicoContainer
addComponent
in class DefaultPicoContainer
implOrInstance
- Component implementation or instance
PicoCompositionException
- if registration fails.public void stop()
DefaultPicoContainer
lifecycle manager
.
The actual lifecycle strategy
supported
depends on the concrete implementation of the adapter.
stop
in interface Startable
stop
in class DefaultPicoContainer
Behavior
,
LifecycleStrategy
,
DefaultPicoContainer.makeChildContainer()
,
DefaultPicoContainer.addChildContainer(PicoContainer)
,
DefaultPicoContainer.removeChildContainer(PicoContainer)
public MutablePicoContainer addAdapter(ComponentAdapter<?> componentAdapter, Properties properties)
DefaultPicoContainer
addAdapter
in class DefaultPicoContainer
public MutablePicoContainer addAdapter(ComponentAdapter<?> componentAdapter)
DefaultPicoContainer
ComponentFactory
passed to the constructor of this container.
addAdapter
in interface MutablePicoContainer
addAdapter
in class DefaultPicoContainer
componentAdapter
- the adapter
public <T> ComponentAdapter<T> removeComponent(Object componentKey)
DefaultPicoContainer
removeComponent
in interface MutablePicoContainer
removeComponent
in class DefaultPicoContainer
componentKey
- key of the component to unregister.
public <T> ComponentAdapter<T> removeComponentByInstance(T componentInstance)
DefaultPicoContainer
removeComponentByInstance
in interface MutablePicoContainer
removeComponentByInstance
in class DefaultPicoContainer
componentInstance
- the component instance to unregister.
public MutablePicoContainer makeChildContainer()
MutablePicoContainer
makeChildContainer
in interface MutablePicoContainer
makeChildContainer
in class DefaultPicoContainer
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |