SAP NetWeaver '04

com.sapportals.wcm.crt.component
Class ComponentStateHandler

[contained in: com.sap.netweaver.bc.crt.par - bc.crt_api.jar]
java.lang.Object
  |
  +--com.sapportals.wcm.crt.component.ComponentStateHandler
All Implemented Interfaces:
ILifecycleInfo

public class ComponentStateHandler
extends java.lang.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  java.lang.Class cc
           
protected  ConfigurationException configException
           
protected  long configurationTime
           
protected  boolean configured
           
protected  boolean contextualized
           
protected  java.util.Date creationDate
           
protected  boolean isConfigurable
           
protected  boolean isContextualizable
           
protected  boolean isReconfigurable
           
protected  boolean isStartable
           
protected  boolean isSuspendable
           
protected  boolean isThreadSafe
           
protected  java.util.Date nextAutoRestartDate
           
protected  int numWorkers
           
protected  java.util.Date reconfigDate
           
protected  boolean started
           
protected  long startTime
           
protected  StartupException startupException
           
protected  ComponentState state
           
protected  boolean stopped
           
protected  boolean suspended
           
protected  java.lang.Thread suspender
           
 
Constructor Summary
ComponentStateHandler(java.lang.Object component)
          Constructs a new state handler instance.
 
Method Summary
protected  void aquireWorker()
           
 long getConfigurationTime()
           
 java.util.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).
 java.util.Date getLastReconfigurationDate()
          Returns the date and time of the last reconfiguration of this component.
 java.util.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 java.lang.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 java.util.Date creationDate

reconfigDate

protected java.util.Date reconfigDate

nextAutoRestartDate

protected java.util.Date nextAutoRestartDate

startTime

protected long startTime

configurationTime

protected long configurationTime

numWorkers

protected transient int numWorkers

suspender

protected transient java.lang.Thread suspender
Constructor Detail

ComponentStateHandler

public ComponentStateHandler(java.lang.Object component)
Constructs a new state handler instance.
Parameters:
component - the object of the component
Method Detail

getCreationDate

public java.util.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
Following copied from interface: com.sapportals.wcm.crt.component.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
Following copied from interface: com.sapportals.wcm.crt.component.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

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 java.lang.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:
TBD: Description of the outgoing return value
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
Following copied from interface: com.sapportals.wcm.crt.component.ILifecycleInfo
Returns:
lastConfigurationException

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
Following copied from interface: com.sapportals.wcm.crt.component.ILifecycleInfo
Returns:
startupException

getLastReconfigurationDate

public java.util.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
Following copied from interface: com.sapportals.wcm.crt.component.ILifecycleInfo
Returns:
the date and time of the last reconfiguration of this component. Can be null .

getNextAutoRestartDate

public java.util.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
Following copied from interface: com.sapportals.wcm.crt.component.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()

SAP NetWeaver '04

Copyright © 2004 by SAP AG. All Rights Reserved.
SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.