public class CachingComponentAdapter extends DecoratingComponentAdapter implements LifecycleManager
ComponentAdapter implementation that caches the component instance.
This adapter supports components with a lifecycle, as it is a lifecycle manager
which will apply the delegate's lifecycle strategy to the cached component instance.
The lifecycle state is maintained so that the component instance behaves in the expected way:
it can't be started if already started, it can't be started or stopped if disposed, it can't
be stopped if not started, it can't be disposed if already disposed.
| Modifier and Type | Field and Description |
|---|---|
private boolean |
delegateHasLifecylce |
private boolean |
disposed |
private ObjectReference |
instanceReference |
private boolean |
started |
| Constructor and Description |
|---|
CachingComponentAdapter(ComponentAdapter delegate) |
CachingComponentAdapter(ComponentAdapter delegate,
ObjectReference instanceReference) |
| Modifier and Type | Method and Description |
|---|---|
void |
dispose(PicoContainer container)
Disposes the cached component instance
Invokes delegate dispose method if the delegate is a LifecycleManager
Invoke the "dispose" method on the container's components.
|
void |
flush()
Flushes the cache.
|
java.lang.Object |
getComponentInstance(PicoContainer container)
Retrieve the component instance.
|
boolean |
hasLifecycle()
Invokes delegate hasLifecylce method if the delegate is a LifecycleManager
Test if a container's component has a lifecycle.
|
void |
start(PicoContainer container)
Starts the cached component instance
Invokes delegate start method if the delegate is a LifecycleManager
Invoke the "start" method on the container's components.
|
void |
stop(PicoContainer container)
Stops the cached component instance
Invokes delegate stop method if the delegate is a LifecycleManager
Invoke the "stop" method on the container's components.
|
accept, changeMonitor, currentMonitor, dispose, getComponentImplementation, getComponentKey, getDelegate, hasLifecycle, start, stop, toString, verifyprivate ObjectReference instanceReference
private boolean disposed
private boolean started
private boolean delegateHasLifecylce
public CachingComponentAdapter(ComponentAdapter delegate)
public CachingComponentAdapter(ComponentAdapter delegate, ObjectReference instanceReference)
public java.lang.Object getComponentInstance(PicoContainer container) throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException
ComponentAdapterCachingComponentAdapter will always return the
same instance.getComponentInstance in interface ComponentAdaptergetComponentInstance in class DecoratingComponentAdaptercontainer - the PicoContainer, that is used to resolve any possible dependencies of the instance.PicoInitializationException - if the component could not be instantiated.PicoIntrospectionException - if the component has dependencies which could not be resolved, or
instantiation of the component lead to an ambigous situation within the
container.AssignabilityRegistrationExceptionNotConcreteRegistrationExceptionpublic void flush()
public void start(PicoContainer container)
start in interface LifecycleManagerstart in class DecoratingComponentAdaptercontainer - the container to "start" its components' lifecyclepublic void stop(PicoContainer container)
stop in interface LifecycleManagerstop in class DecoratingComponentAdaptercontainer - the container to "stop" its components' lifecyclepublic void dispose(PicoContainer container)
dispose in interface LifecycleManagerdispose in class DecoratingComponentAdaptercontainer - the container to "dispose" its components' lifecyclepublic boolean hasLifecycle()
DecoratingComponentAdapterhasLifecycle in interface LifecycleManagerhasLifecycle in class DecoratingComponentAdaptertrue if the component has a lifecycle