com.sapportals.wcm.crt.component

Class ComponentStateHandler

java.lang.Object
  extended by com.sapportals.wcm.crt.component.ComponentStateHandler
All Implemented Interfaces:
ILifecycleInfo

public class ComponentStateHandler
extends Object
implements ILifecycleInfo

This class must be used for state and life-cycle handling in component implementations. All of the relevant pre and post methods MUST be called.

Example:

 public class TestComponent implements IComponent, IConfigurable, IStartable, ILifecycleInfo {

   private final ComponentStateHandler h;

   public TestComponent() {
     this.h = new ComponentStateHandler(TestComponent.class);
   }

   public ComponentState getState() {
     return this.h.getState();
   }

   // ... other ILifecycleInfo methods ...

   public configure(IConfiguration config) throws ConfigurationException {
     this.h.preConfigure();
     try {
       // ...
       throw new ConfigurationException("missing parameter");
     }
     catch (ConfigurationException ex) {
       throw this.h.postConfigure(ex);
     }
     catch (Exception ex) {
       throw new ConfigurationException(this.h.postConfigure(ex));
     }
     this.h.postConfigure();
   }

   public start() throws StartupException {
     this.h.preStart();
     try {
       // ...
       throw new StartupException("failed to start");
     }
     catch (StartupException ex) {
       throw this.h.postStart(ex);
     }
     catch (Exception ex) {
       throw new StartupException(this.h.postStartUp(ex));
     }
     this.h.postStart();
   }

   public someServiceMethod() throws ServiceException {
    try {
       if (!this.h.preService()) {
        throw new ServiceException("Service not available");
       }
       // ...
     }
     finally {
       this.h.postService();
     }
   }
 }
 

Copyright (c) SAP AG 2001-2002

See Also:
ComponentState

Field Summary
protected  Class cc
           
protected  ConfigurationException configException
           
protected  long configurationTime
           
protected  boolean configured
           
protected  boolean contextualized
           
protected  Date creationDate
           
protected  boolean isConfigurable
           
protected  boolean isContextualizable
           
protected  boolean isReconfigurable
           
protected  boolean isStartable
           
protected  boolean isSuspendable
           
protected  boolean isThreadSafe
           
protected  Date nextAutoRestartDate
           
protected  int numWorkers
           
protected  Date reconfigDate
           
protected  boolean started
           
protected  long startTime
           
protected  StartupException startupException
           
protected  ComponentState state
           
protected  boolean stopped
           
protected  boolean suspended
           
protected  Thread suspender
           
 
Constructor Summary
ComponentStateHandler(Object component)
          Constructs a new state handler instance.
 
Method Summary
protected  void aquireWorker()
           
 long getConfigurationTime()
           
 Date getCreationDate()
          Returns the date and time of the creation of the component instance.
 ConfigurationException getLastConfigurationException()
          Returns the exception thrown in the last call to IConfigurable.configure(IConfiguration), or IReconfigurable.reconfigure(IConfiguration).
 Date getLastReconfigurationDate()
          Returns the date and time of the last reconfiguration of this component.
 Date getNextAutoRestartDate()
          Returns the date and time of the next automatic restart of the component.
 long getStartTime()
           
 StartupException getStartupException()
          Returns the exception thrown in the last call to IStartable.start(), Can be null .
 ComponentState getState()
          Returns the current life-cycle state of the component.
 void postConfigure()
           
 ConfigurationException postConfigure(ConfigurationException x)
           
 void postContextualize()
           
 ContextException postContextualize(ContextException x)
           
 void postReconfigure()
           
 ConfigurationException postReconfigure(ConfigurationException x)
           
 void postResume()
           
 void postService()
          This method should be balanced with a preService , and should occur in a finally statement so that the balance is guaranteed.
 void postStart()
           
 StartupException postStart(ConfigurationException x)
           
 StartupException postStart(StartupException x)
           
 void postStop()
           
 void postSuspend()
           
 void preConfigure()
           
 void preContextualize()
           
 void preReconfigure()
           
 void preResume()
           
 boolean preService()
          Returns true if a component specific service method can be called.
 void preStart()
           
 void preStop()
           
 void preSuspend()
           
protected  void releaseWorker()
           
protected  void startMonitor()
           
protected  void stopMonitor()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cc

protected final Class cc

isContextualizable

protected final boolean isContextualizable

isConfigurable

protected final boolean isConfigurable

isStartable

protected final boolean isStartable

isSuspendable

protected final boolean isSuspendable

isReconfigurable

protected final boolean isReconfigurable

isThreadSafe

protected final boolean isThreadSafe

contextualized

protected boolean contextualized

configured

protected boolean configured

started

protected boolean started

stopped

protected boolean stopped

suspended

protected boolean suspended

state

protected ComponentState state

configException

protected ConfigurationException configException

startupException

protected StartupException startupException

creationDate

protected Date creationDate

reconfigDate

protected Date reconfigDate

nextAutoRestartDate

protected Date nextAutoRestartDate

startTime

protected long startTime

configurationTime

protected long configurationTime

numWorkers

protected transient int numWorkers

suspender

protected transient Thread suspender
Constructor Detail

ComponentStateHandler

public ComponentStateHandler(Object component)
Constructs a new state handler instance.

Parameters:
component - the object of the component
Method Detail

getCreationDate

public Date getCreationDate()
Description copied from interface: ILifecycleInfo
Returns the date and time of the creation of the component instance. Can be null . This property usually makes sense only for components that implement the IThreadSafe interface.

Specified by:
getCreationDate in interface ILifecycleInfo
Returns:
the date and time of the creation of the component instance. Can be null .

getState

public ComponentState getState()
Description copied from interface: ILifecycleInfo
Returns the current life-cycle state of the component. Can be null .

Specified by:
getState in interface ILifecycleInfo
Returns:
the current life-cycle state of the component. Can be null .

preContextualize

public void preContextualize()

postContextualize

public ContextException postContextualize(ContextException x)
                                   throws ContextException
Throws:
ContextException

postContextualize

public void postContextualize()

preConfigure

public void preConfigure()

postConfigure

public ConfigurationException postConfigure(ConfigurationException x)

postConfigure

public void postConfigure()

preStart

public void preStart()

postStart

public StartupException postStart(StartupException x)

postStart

public StartupException postStart(ConfigurationException x)

postStart

public void postStart()

preStop

public void preStop()

postStop

public void postStop()

preSuspend

public void preSuspend()

postSuspend

public void postSuspend()

preResume

public void preResume()
               throws IllegalStateException
Throws:
IllegalStateException

postResume

public void postResume()

preReconfigure

public void preReconfigure()

postReconfigure

public ConfigurationException postReconfigure(ConfigurationException x)

postReconfigure

public void postReconfigure()

preService

public boolean preService()
Returns true if a component specific service method can be called. The component should throw a dedicated exception if false is returned.

This method should be used very carefully to avoid unintended compromise of the service.It should always be balanced with a postService .

Returns:
true if a component specific service method can be called, otherwise return false
See Also:
postService()

postService

public void postService()
This method should be balanced with a preService , and should occur in a finally statement so that the balance is guaranteed. The following is an example.
 stateHandler.preService();
 try {
   // do something
 }
 finally {
   stateHandler.postService();
 }
 

See Also:
preService()

getLastConfigurationException

public ConfigurationException getLastConfigurationException()
Description copied from interface: ILifecycleInfo
Returns the exception thrown in the last call to IConfigurable.configure(IConfiguration), or IReconfigurable.reconfigure(IConfiguration). Can be null .

Specified by:
getLastConfigurationException in interface ILifecycleInfo
Returns:
the last configuration exception. Can be null.

getStartupException

public StartupException getStartupException()
Description copied from interface: ILifecycleInfo
Returns the exception thrown in the last call to IStartable.start(), Can be null .

Specified by:
getStartupException in interface ILifecycleInfo
Returns:
the startup exception. Can be null.

getLastReconfigurationDate

public Date getLastReconfigurationDate()
Description copied from interface: ILifecycleInfo
Returns the date and time of the last reconfiguration of this component. Can be null .

Specified by:
getLastReconfigurationDate in interface ILifecycleInfo
Returns:
the date and time of the last reconfiguration of this component. Can be null .

getNextAutoRestartDate

public Date getNextAutoRestartDate()
Description copied from interface: ILifecycleInfo
Returns the date and time of the next automatic restart of the component. Can be null .

Specified by:
getNextAutoRestartDate in interface ILifecycleInfo
Returns:
the date and time of the next automatic restart of the component. Can be null .
See Also:
AutoRestartException

getStartTime

public long getStartTime()

getConfigurationTime

public long getConfigurationTime()

startMonitor

protected void startMonitor()

stopMonitor

protected void stopMonitor()

aquireWorker

protected void aquireWorker()

releaseWorker

protected void releaseWorker()
Access Rights

This class can be accessed from:


SC DC Public Part ACH
[sap.com] KMC-CM [sap.com] tc/km/frwk api EP-KM-CM
[sap.com] KMC-WPC [sap.com] tc/kmc/wpc/wpcfacade api EP-PIN-WPC-WCM


Copyright 2014 SAP AG Complete Copyright Notice