org.sape.carbon.core.config.interceptor
Class DefaultConfigurationInterceptor

java.lang.Object
  |
  +--org.sape.carbon.core.util.reflection.GenericProxy
        |
        +--org.sape.carbon.core.config.interceptor.DefaultConfigurationInterceptor
All Implemented Interfaces:
ConfigurationInterceptor, Decorator, EventListener, Interceptor, InvocationHandler, NodeEventListener

public class DefaultConfigurationInterceptor
extends GenericProxy
implements ConfigurationInterceptor, Interceptor, NodeEventListener

The default implementation of ConfigurationInterceptor. This implementation is a java.lang.reflect.InvocationHandler that can handle method calls on both the ConfigurationInterceptor interface and the component's configuration interface. All set requests to the configuration interface manipulate the working configuration. All get requests to the configuration interface manipulate the live configuration. The ConfigurationInterceptor interface handles the management of the working and live configurations.

Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.6 $($Author: dvoet $ / $Date: 2003/10/27 19:54:41 $)
Author:
Greg Hinkle, January 2002

Field Summary
private static String CLONE
          Name of the clone method.
private static Method CONFIGURE_METHOD
          Holds a reference to the configureComponent method of the class.
private static String GET
          Get prefix for properties.
private static String GET_DATA_STRUCTURE
          Name of the get data structure method.
private static Method INVOKE_METHOD
          Holds a reference to the invoke method of the Invocation class.
private static String IS
          Is prefix for boolean properties.
protected  ComponentConfiguration liveConfiguration
          The component's live configuration
private  org.apache.commons.logging.Log log
           
protected  Interceptor nextInterceptor
          Next interceptor in the chain.
private  Thread persistingThread
           
protected  ComponentProxyInvocationHandler proxyInvocationHandler
          The invocation handler.
private static String SET
          Set prefix for properties.
private static String SET_NAME
          Name of the set configuration name method.
protected  Component thisComponent
          Component being proxied.
private static Collection UNSUPPORTED_OPERATIONS
          Holds the list of operations not support by the interceptor.
protected  ComponentConfiguration workingConfiguration
          The component's working configuration, possibly in an interim/invalid state
 
Fields inherited from class org.sape.carbon.core.util.reflection.GenericProxy
 
Constructor Summary
protected DefaultConfigurationInterceptor(ComponentConfiguration componentConfiguration, ComponentProxyInvocationHandler proxyInvocationHandler, ConfigurationInterceptorConfiguration config)
          This constructor is protected to allow extension but not direct instantiation.
 
Method Summary
 void applyConfiguration()
          Makes the current working configuration live.
private  void configureComponent(ComponentConfiguration newConfiguration)
          Calls the lifecycle assistant to configure the component.
 Class[] getExposedInterfaces()
          This implementation returns the ConfigurationInterceptor interface and the component's configuration interface
 ComponentConfiguration getLiveConfiguration()
          This implementation returns a copy of the component's live configuration.
 ComponentConfiguration getWorkingConfiguration()
          This implementation returns a copy of the component's working configuration.
protected  Object handleInvoke(Object proxy, Method m, Object[] args)
          This implementation delegates to: The live configuration object when get methods are invoked on the configuration interface The working configuration object when set methods are invoked on the configuration interface This class for methods called on the ConfigurationInterceptor interface
private  void initializeWorkingConfiguration()
          This method will create a working configuration if it does not exist
 Object invoke(Invocation invocation)
          This implementation watches for calls to the configure lifecycle method.
 void nodeChanged(Node changedNode)
          This implementation causes the component to be reconfigured if the interceptor is configured to auto refresh the component.
 void nodeRemoved(String removedNodeName)
          This impelementation does nothing when a component's config is removed
 void persistConfiguration()
          Persists the current live configuration in the Config Service.
 void refreshConfiguration()
          Same as revertConfiguration, but the configuration node containing this component's configuration is refreshed first.
 void revertConfiguration()
          Reverts the components live configuration back to its state as of the last call to persistConfiguration or the loading of the component if persistConfiguration was never called.
 void setComponentReference(Component component)
          Called after creation to pass a reference to the component to each of its decorators.
 void setNextInterceptor(Interceptor interceptor)
          This method sets the next interceptor as the next in the chain from the current interceptor.
 
Methods inherited from class org.sape.carbon.core.util.reflection.GenericProxy
invoke, proxyEquals, proxyHashCode, proxyToString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log

liveConfiguration

protected ComponentConfiguration liveConfiguration
The component's live configuration


workingConfiguration

protected ComponentConfiguration workingConfiguration
The component's working configuration, possibly in an interim/invalid state


proxyInvocationHandler

protected ComponentProxyInvocationHandler proxyInvocationHandler
The invocation handler.


thisComponent

protected Component thisComponent
Component being proxied.


nextInterceptor

protected Interceptor nextInterceptor
Next interceptor in the chain.


persistingThread

private Thread persistingThread

SET

private static final String SET
Set prefix for properties.

See Also:
Constant Field Values

GET

private static final String GET
Get prefix for properties.

See Also:
Constant Field Values

IS

private static final String IS
Is prefix for boolean properties.

See Also:
Constant Field Values

CLONE

private static final String CLONE
Name of the clone method.

See Also:
Constant Field Values

GET_DATA_STRUCTURE

private static final String GET_DATA_STRUCTURE
Name of the get data structure method.

See Also:
Constant Field Values

SET_NAME

private static final String SET_NAME
Name of the set configuration name method.

See Also:
Constant Field Values

UNSUPPORTED_OPERATIONS

private static final Collection UNSUPPORTED_OPERATIONS
Holds the list of operations not support by the interceptor.


CONFIGURE_METHOD

private static final Method CONFIGURE_METHOD
Holds a reference to the configureComponent method of the class.


INVOKE_METHOD

private static final Method INVOKE_METHOD
Holds a reference to the invoke method of the Invocation class.

Constructor Detail

DefaultConfigurationInterceptor

protected DefaultConfigurationInterceptor(ComponentConfiguration componentConfiguration,
                                          ComponentProxyInvocationHandler proxyInvocationHandler,
                                          ConfigurationInterceptorConfiguration config)
This constructor is protected to allow extension but not direct instantiation. Instantiation is handled by the ConfigurationInterceptorFactory in this package.

Parameters:
componentConfiguration - the configuration object this interceptor will manage
proxyInvocationHandler - the proxy invocation handler
Method Detail

getExposedInterfaces

public Class[] getExposedInterfaces()
This implementation returns the ConfigurationInterceptor interface and the component's configuration interface

Specified by:
getExposedInterfaces in interface Decorator
Returns:
Class[] an array of interfaces

setNextInterceptor

public void setNextInterceptor(Interceptor interceptor)
This method sets the next interceptor as the next in the chain from the current interceptor.

Specified by:
setNextInterceptor in interface Interceptor
Parameters:
interceptor - the next interceptor in the chain

setComponentReference

public void setComponentReference(Component component)
Description copied from interface: Decorator
Called after creation to pass a reference to the component to each of its decorators. The component reference should not be used within this method because not all other interceptors have this reference yet and they may rely on this reference thus leading to null pointer exceptions.

Specified by:
setComponentReference in interface Decorator
Parameters:
component - a reference to the component that this interceptor is assisting
See Also:
Decorator.setComponentReference(Component)

persistConfiguration

public void persistConfiguration()
                          throws ConfigurationException
Description copied from interface: ConfigurationInterceptor
Persists the current live configuration in the Config Service.

Specified by:
persistConfiguration in interface ConfigurationInterceptor
Throws:
ConfigurationException - indictes an error persisting the configuration
See Also:
ConfigurationInterceptor.persistConfiguration()

revertConfiguration

public void revertConfiguration()
Description copied from interface: ConfigurationInterceptor
Reverts the components live configuration back to its state as of the last call to persistConfiguration or the loading of the component if persistConfiguration was never called. The working configuration is discarded.

Specified by:
revertConfiguration in interface ConfigurationInterceptor
See Also:
ConfigurationInterceptor.revertConfiguration()

applyConfiguration

public void applyConfiguration()
Description copied from interface: ConfigurationInterceptor
Makes the current working configuration live.

Specified by:
applyConfiguration in interface ConfigurationInterceptor
See Also:
ConfigurationInterceptor.applyConfiguration()

getWorkingConfiguration

public ComponentConfiguration getWorkingConfiguration()
This implementation returns a copy of the component's working configuration. Changes to this object have not effect on the actual working configuration.

Specified by:
getWorkingConfiguration in interface ConfigurationInterceptor
Returns:
ComponentConfiguration the object implementing the component's configuration interface that represents the working copy of the component's configuration
See Also:
ConfigurationInterceptor.getWorkingConfiguration()

getLiveConfiguration

public ComponentConfiguration getLiveConfiguration()
This implementation returns a copy of the component's live configuration. Changes to this object have not effect on the actual live configuration.

Specified by:
getLiveConfiguration in interface ConfigurationInterceptor
Returns:
ComponentConfiguration the object implementing the component's configuration interface that represents the live copy of the component's configuration
See Also:
ConfigurationInterceptor.getWorkingConfiguration()

refreshConfiguration

public void refreshConfiguration()
Description copied from interface: ConfigurationInterceptor
Same as revertConfiguration, but the configuration node containing this component's configuration is refreshed first.

Specified by:
refreshConfiguration in interface ConfigurationInterceptor
See Also:
ConfigurationInterceptor.refreshConfiguration()

invoke

public Object invoke(Invocation invocation)
              throws Throwable
This implementation watches for calls to the configure lifecycle method. When the configure method is called, this method will replace the live configuration with the configuration passed to the configure method. (Should it discard the working copy?)

Specified by:
invoke in interface Interceptor
Parameters:
invocation - the invocation to execute
Returns:
the results of the invocation's execution
Throws:
Throwable - indicates an error with the configruation

nodeChanged

public void nodeChanged(Node changedNode)
This implementation causes the component to be reconfigured if the interceptor is configured to auto refresh the component. This implementation will not refresh the component's configuration if the event is triggered by a call to persistConfiguration because it must already have been applied.

Specified by:
nodeChanged in interface NodeEventListener
Parameters:
changedNode - node that was changed

nodeRemoved

public void nodeRemoved(String removedNodeName)
This impelementation does nothing when a component's config is removed

Specified by:
nodeRemoved in interface NodeEventListener
Parameters:
removedNodeName - name of the removed node

handleInvoke

protected Object handleInvoke(Object proxy,
                              Method m,
                              Object[] args)
                       throws Throwable
This implementation delegates to:

initializeWorkingConfiguration

private void initializeWorkingConfiguration()
This method will create a working configuration if it does not exist


configureComponent

private void configureComponent(ComponentConfiguration newConfiguration)
Calls the lifecycle assistant to configure the component.

Parameters:
newConfiguration - the new config to pass to the component


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.