|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.sape.carbon.core.component.proxy.AbstractInterceptor | +--org.sape.carbon.core.component.lifecycle.DefaultLifecycleInterceptor
This is the default implementation of the lifecycle interceptor interface. This class takes on the responsibility of delegating Copyright 2002 Sapient
Field Summary | |
private long |
blockedCallTimeout
timeout for blocking calls. |
private Component |
componentProxy
reference to the complete component |
private LifecycleStateEnum |
currentState
The current state associated with the Component. |
private long |
destroyerThreadTimeout
timeout for the destroyer thread. |
protected static Class[] |
EXPOSED_INTERFACES
Array of interfaces this proxy adds to a component. |
private FunctionalInterface |
functionalImplementation
A reference to the Component instance that is being managed. |
static String |
LIFECYCLE_CHANGE_EVENT_NAME
Name of lifecycle change event. |
private org.apache.commons.logging.Log |
log
Provides handle to Apache-commons logger. |
private ComponentProxyInvocationHandler |
proxyInvocationHandler
A reference to the component proxy invocation handler. |
private Object |
suspendedLock
lock object synchronized upon to block calls while in a suspended state, used in waitForResume and internalResumeComponent methods |
private static Set |
VALID_ENTRY_STATES_CONFIGURE
Defines the valid configure states |
private static Set |
VALID_ENTRY_STATES_INITIALIZE
Defines the valid initialize states |
private static Set |
VALID_ENTRY_STATES_RESUME
Defines the valid resume states |
private static Set |
VALID_ENTRY_STATES_START
Defines the valid start states |
private static Set |
VALID_ENTRY_STATES_STOP
Defines the valid stop states |
private static Set |
VALID_ENTRY_STATES_SUSPEND
Defines the valid suspend states |
Fields inherited from class org.sape.carbon.core.component.proxy.AbstractInterceptor |
nextInterceptor, nextInterceptorIsProxy, nextInvocationHandler |
Constructor Summary | |
DefaultLifecycleInterceptor(FunctionalInterface componentInstance,
ComponentProxyInvocationHandler proxyInvocationHandler,
DefaultLifecycleInterceptorConfiguration configuration)
Creates a new DefaultLifecycleInterceptor. |
Method Summary | |
private void |
callComponentConfigure(ComponentConfiguration configuration)
Calls component's lifecycle method. |
private void |
callComponentResume()
Calls component's lifecycle method. |
private void |
callComponentStart()
Calls component's lifecycle method. |
private void |
callComponentStop()
Calls component's lifecycle method. |
private void |
callComponentSuspend()
Calls component's lifecycle method. |
void |
configureComponent(ComponentConfiguration configuration)
Provides a Component with its Configuration. |
void |
destroyComponent()
Tells the Component prepare to die. |
protected String |
getComponentName()
Utility method used to get the component's name |
Class[] |
getExposedInterfaces()
This should return the list of interfaces that a decorator wishes to expose through the component proxy. |
LifecycleStateEnum |
getLifecycleState()
Gets the current lifecycle state of the component. |
String |
getLifecycleStateString()
Returns a string representation of the Lifecycle State |
void |
initializeComponent(Component thisComponent)
Run ONLY ONCE during the life of a Component, immediately after the Component is created. |
protected void |
internalResumeComponent()
Helper method to do the work of resuming a component. |
protected void |
internalStopComponent()
Helper method to do the work of suspending a component. |
protected void |
internalSuspendComponent()
Helper method to do the work of suspending a component. |
Object |
invoke(Invocation invocation)
This method must implement the invocation of any necessary actions and the chaining the next interceptor. |
protected void |
killInvalidComponent()
This method is called when an exception other than NonFatalStateTransitionException is thrown from a component's lifecycle method which signals that the component is corrupt and should be destroyed. |
protected void |
logNotSupported(Class unImplementedInterface)
Utility method to log trace details when a component does not support an attempted lifecycle operation. |
void |
resumeComponent()
Tells the Component to resume its service. |
void |
setComponentReference(Component componentProxy)
This implementation does not make use of the componentProxy reference |
protected void |
setLifecycleState(LifecycleStateEnum state)
Sets the current lifecycle state |
void |
startComponent()
Tells the Component to begin providing its service. |
protected void |
startLifecycleMethod()
Acquires the component's monitor for writing. |
void |
stopComponent()
Tells the Component to cease providing its service. |
protected void |
stopLifecycleMethod()
Releases the component's monitor |
void |
suspendComponent()
Tells the Component to suspend its service. |
protected void |
validateEntryState(LifecycleStateEnum entryState,
Set validStates)
Checks if a given state exists in a set of valid states. |
protected void |
waitForResume()
Waits for the component to return from the LifecycleStateEnum.SUSPENDED state to the LifecycleStateEnum.RUNNING state. |
Methods inherited from class org.sape.carbon.core.component.proxy.AbstractInterceptor |
callNextInterceptor, setNextInterceptor |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.sape.carbon.core.component.proxy.Interceptor |
setNextInterceptor |
Field Detail |
protected static final Class[] EXPOSED_INTERFACES
private org.apache.commons.logging.Log log
public static final String LIFECYCLE_CHANGE_EVENT_NAME
private final FunctionalInterface functionalImplementation
private LifecycleStateEnum currentState
private final ComponentProxyInvocationHandler proxyInvocationHandler
private Component componentProxy
private final Object suspendedLock
private long blockedCallTimeout
private long destroyerThreadTimeout
private static final Set VALID_ENTRY_STATES_INITIALIZE
private static final Set VALID_ENTRY_STATES_START
private static final Set VALID_ENTRY_STATES_STOP
private static final Set VALID_ENTRY_STATES_SUSPEND
private static final Set VALID_ENTRY_STATES_RESUME
private static final Set VALID_ENTRY_STATES_CONFIGURE
Constructor Detail |
public DefaultLifecycleInterceptor(FunctionalInterface componentInstance, ComponentProxyInvocationHandler proxyInvocationHandler, DefaultLifecycleInterceptorConfiguration configuration)
componentInstance
- instance of the componentproxyInvocationHandler
- invocation handler for the componentconfiguration
- configuration for the interceptorMethod Detail |
public Object invoke(Invocation invocation) throws Throwable
invoke
in interface Interceptor
invocation
- the invocation to execute
Throwable
- indicates an error in the invocation chainpublic Class[] getExposedInterfaces()
getExposedInterfaces
in interface Decorator
public LifecycleStateEnum getLifecycleState()
getLifecycleState
in interface LifecycleInterceptor
public String getLifecycleStateString()
getLifecycleStateString
in interface LifecycleInterceptor
protected void setLifecycleState(LifecycleStateEnum state)
state
- the new statepublic void initializeComponent(Component thisComponent) throws InvalidStateException, OperationNotSupportedException, StateTransitionException
Valid Entry States: CREATING
Interim State: INITIALIZING
Exit State: STOPPED
initializeComponent
in interface LifecycleInterceptor
thisComponent
- component to be initialized
InvalidStateException
- When the entry state is not allowed
OperationNotSupportedException
- When component does not support
the requested operation
StateTransitionException
- When an error occured while trying to
complete the lifecycle operationpublic void startComponent() throws InvalidStateException, OperationNotSupportedException, StateTransitionException
Valid Entry States: STOPPED
Interim State: STARTING
Exit State: RUNNING
startComponent
in interface LifecycleInterceptor
InvalidStateException
- When the entry state is not allowed
OperationNotSupportedException
- When component does not support
the requested operation
StateTransitionException
- When an error occured while trying to
complete the lifecycle operationpublic void stopComponent() throws InvalidStateException, OperationNotSupportedException, StateTransitionException
Valid Entry States: RUNNING, SUSPENDED
Interim State: STOPPING
Exit State: STOPPED
stopComponent
in interface LifecycleInterceptor
InvalidStateException
- When the entry state is not allowed
OperationNotSupportedException
- When component does not support
the requested operation
StateTransitionException
- When an error occured while trying to
complete the lifecycle operationpublic void suspendComponent() throws InvalidStateException, OperationNotSupportedException, StateTransitionException
Valid Entry States: RUNNING
Interim State: SUSPENDING
Exit State: SUSPENDED
suspendComponent
in interface LifecycleInterceptor
InvalidStateException
- When the entry state is not allowed
OperationNotSupportedException
- When component does not support
the requested operation
StateTransitionException
- When an error occured while trying to
complete the lifecycle operationpublic void resumeComponent() throws InvalidStateException, OperationNotSupportedException, StateTransitionException
Valid Entry States: SUSPENDED
Interim State: RESUMING
Exit State: RUNNING
resumeComponent
in interface LifecycleInterceptor
InvalidStateException
- When the entry state is not allowed
OperationNotSupportedException
- When component does not support
the requested operation
StateTransitionException
- When an error occured while trying to
complete the lifecycle operationpublic void configureComponent(ComponentConfiguration configuration) throws InvalidStateException, OperationNotSupportedException, StateTransitionException
Valid Entry States: RUNNING, SUSPENDED, STOPPED
Interim State: CONFIGURING
Exit States: RUNNING, SUSPENDED, STOPPED (to match entry state)
configureComponent
in interface LifecycleInterceptor
configuration
- Configuration object to be applied to component
InvalidStateException
- When the entry state is not allowed
OperationNotSupportedException
- When component does not support
the requested operation
StateTransitionException
- When an error occured while trying to
complete the lifecycle operationpublic void destroyComponent() throws OperationNotSupportedException, StateTransitionException
Valid Entry States: All states are valid for entry. If the component is in the RUNNING state, it will be stopped first.
Interim State: DESTROYING
Exit State: DESTROYED
destroyComponent
in interface LifecycleInterceptor
InvalidStateException
- When the entry state is not allowed
OperationNotSupportedException
- When component does not support
the requested operation
StateTransitionException
- When an error occured while trying to
complete the lifecycle operationpublic void setComponentReference(Component componentProxy)
setComponentReference
in interface Decorator
componentProxy
- a reference to the component that
this interceptor is assistingprotected void startLifecycleMethod()
Example invocation:
startLifecycleMethod();
try {
...
} finally {
stopLifecycleMethod();
}
StateTransitionException
- if the Thread is interruptedComponentProxyInvocationHandler.getMonitor()
protected void stopLifecycleMethod()
protected void internalSuspendComponent() throws OperationNotSupportedException, StateTransitionException
StateTransitionException
- if an exception is caught in the
functional implementations suspend method
OperationNotSupportedException
- not thrown by this imlementation,
but provided for overriding methodsprotected void internalResumeComponent() throws OperationNotSupportedException, StateTransitionException
StateTransitionException
- if an exception is caught in the
functional implementations resume method
OperationNotSupportedException
- not thrown by this imlementation,
but provided for overriding methodsprotected void internalStopComponent() throws OperationNotSupportedException, StateTransitionException
StateTransitionException
- if an exception is caught in the
functional implementations suspend method
OperationNotSupportedException
- not thrown by this imlementation,
but provided for overriding methodsprotected void waitForResume() throws InvalidStateException, ComponentUnavailableException
Override this method to disable or change this functionality.
ComponentUnavailableException
- if it does not change states in a
timely manner or if
InvalidStateException
- if the entry state is not within
the Set of validStatesprotected final void validateEntryState(LifecycleStateEnum entryState, Set validStates)
entryState
- the entry state to be validatedvalidStates
- a set of validStates
InvalidStateException
- if the entry state is not within
the Set of validStatesprotected final void logNotSupported(Class unImplementedInterface)
unImplementedInterface
- the interface which held the lifecycle
method that was not implemented by the componentprotected final String getComponentName()
protected void killInvalidComponent()
This method is called when an exception other than NonFatalStateTransitionException is thrown from a component's lifecycle method which signals that the component is corrupt and should be destroyed.
Override this method to change what happens to a component if it fails to transition state.
private void callComponentStart()
private void callComponentStop()
private void callComponentConfigure(ComponentConfiguration configuration)
configuration
- configuration for this component that will be
passed to its lifecycle methodprivate void callComponentSuspend()
private void callComponentResume()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |