org.objectweb.jass.as
Class ActivityService

java.lang.Object
  extended byorg.objectweb.jass.as.ActivityService
All Implemented Interfaces:
ActivityManager, UserActivity

public class ActivityService
extends java.lang.Object
implements ActivityManager

Implements the access interface to the AS (UserActivity) available to HLSs.

Author:
fran Date: Feb 12, 2004 org.objectweb.jass.asUserActivityImpl.java

Field Summary
static java.lang.String CHILDLIFETIME_SS_NAME
           
static int DEFAULT_TIMEOUT
           
static java.lang.String SYNCHRONIZATION_SS_NAME
           
 
Constructor Summary
ActivityService()
          Default Constructor.
 
Method Summary
 void associateActivityToCurrentThread(ActivityCoordinator activity)
           
 void begin(int timeout)
          Create a new Activity and associate it with the current thread.
 Outcome broadcast(java.lang.String signalSetName)
          Causes the SignalSet specified by signalSetName to start producing signals for all registered Actions.
 Outcome complete()
          Causes the active Activity context to be completed with its current CompletionStatus.
 Outcome completeWithStatus(int completionStatus)
          Causes the active Activity context to complete with the specified CompletionStatus.
 ActivityCoordinator disassociateActivityFromCurrentThread()
           
 void forget(GlobalId globalId)
          NOT YET IMPLEMENTED
 int getCompletionStatus()
          Returns the current value of the CompletionStatus of the active Activity.
 ActivityCoordinator getCoordinator()
          Returns the ActivityCoordinator of the active Activity, or null if there is no Activity associated with the calling thread.
 GlobalId getGlobalId()
          Returns the GlobalId of the active Activity.
static int getInstances()
           
 java.lang.String getName()
          Returns a printable string describing the active Activity.
 int getNumberOfActivities()
          Return the number of activities in the activities HashMap.
 ActivityCoordinator getParentCoordinator()
          Returns the ActivityCoordinator of the parent of the active Activity, or null if the active Activity is a top-level Activity.
 PropertyGroup getPropertyGroup(java.lang.String name)
          NOT YET IMPLEMENTED
 ServiceManager getService()
          Returns the registered ServiceManager for this UserActivity instance.
 int getStatus()
          Returns the current value of the Status of the active Activity.
 int getTimeout()
          Returns the default timeout value.
 GlobalId hibernate()
          Not yet implemented.
 void linkActivityToId(java.lang.String actId, ActivityCoordinator activity)
           
 void reactivate(GlobalId globalId)
          Not yet implemented.
 GlobalId[] recover()
          NOT YET IMPLEMENTED
 ActivityCoordinator recreate(GlobalId activity, GlobalId parent, boolean resume)
          NOT YET IMPLEMENTED
 void registerService(ServiceManager service)
          Registers a ServiceManager for the type of high-level service (HLS) whose activities are to be demarcated through the target UserActivity instance.
 void resume(ActivityToken activityToken)
          Resumes the association of the Activity, and any nested Activities and transactions, represented by the ActivityToken with the calling thread of execution.
 void resumeAll(ActivityToken activityToken)
          Not yet implemented.
 void resumeGroup(ActivityToken activityToken)
          Not yet implemented.
static void setActivityIdGenerator(ActivityIdGenerator generator)
          Sets the Activity Id Generator for all Activity Service instances.
 void setCompletionStatus(int completionStatus)
          OK Sets the CompletionStatus of the active Activity.
 void setTimeout(int timeout)
          Sets the default timeout, in seconds, after which an Activity may be automatically completed by the Activity service.
 ActivityToken suspend()
          Suspends the association of the current Activity from the calling thread of execution along with any child Activities of the same ContextGroup nested within that Activity.
 ActivityToken suspendAll()
          Not yet implemented.
 ActivityToken suspendGroup()
          Not yet implemented.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TIMEOUT

public static int DEFAULT_TIMEOUT

SYNCHRONIZATION_SS_NAME

public static java.lang.String SYNCHRONIZATION_SS_NAME

CHILDLIFETIME_SS_NAME

public static java.lang.String CHILDLIFETIME_SS_NAME
Constructor Detail

ActivityService

public ActivityService()
Default Constructor. It takes count of the number of service instances created.

Method Detail

begin

public void begin(int timeout)
           throws InvalidStateException,
                  ServiceNotRegisteredException,
                  TimeoutRangeException,
                  SystemException
Create a new Activity and associate it with the current thread.

Specified by:
begin in interface UserActivity
Parameters:
timeout - - the period (in seconds) within which the Activity must be completed. If it is not completed within this period then it is subject to being completed by the Activity service with the CompletionStatusFail status.
Throws:
InvalidStateException - - Thrown if the parent Activity has been marked as CompletionStatusFailOnly.
ServiceNotRegisteredException - - Thrown if no ServiceManager has been registered.
TimeoutRangeException - - Thrown if timeout is less than -1 or if it is outside an administratively configured range in the deployed system.
SystemException

completeWithStatus

public Outcome completeWithStatus(int completionStatus)
                           throws NoActivityException,
                                  ActivityPendingException,
                                  ContextPendingException,
                                  ServiceNotRegisteredException,
                                  NotOriginatorException,
                                  InvalidStateException,
                                  ActivityNotProcessedException,
                                  SystemException
Causes the active Activity context to complete with the specified CompletionStatus. If a CompletionSignalSet is used by the registered ServiceManager, then it will be driven by the Activity service to obtain completion signals to distribute to any registered Actions. If the Activity is nested within a parent, then the parent Activity becomes associated with the thread on completion of this operation. If there are any child active or suspended Activities or transactions and the CompletionStatus is CompletionStatusFail or CompletionStatusFailOnly then those child Activites will have their CompletionStatuses set to CompletionStatusFailOnly and any child transaction will be called to setRollbackOnly.

Specified by:
completeWithStatus in interface UserActivity
Parameters:
completionStatus -
Returns:
Throws:
NoActivityException
ActivityPendingException
ContextPendingException
ServiceNotRegisteredException
NotOriginatorException
InvalidStateException
ActivityNotProcessedException
SystemException

complete

public Outcome complete()
                 throws NoActivityException,
                        ActivityPendingException,
                        ContextPendingException,
                        ServiceNotRegisteredException,
                        NotOriginatorException,
                        ActivityNotProcessedException,
                        SystemException
Causes the active Activity context to be completed with its current CompletionStatus. If a CompletionSignalSet is used by the registered ServiceManager, then it will be driven by the Activity service to obtain completion signals to distribute to any registered Actions. If the Activity is nested within a parent, then the parent Activity becomes associated with the thread on completion of this operation. If there are any child active or suspended Activities or transactions and the CompletionStatus is CompletionStatusFail or CompletionStatusFailOnly then those child Activites will have their CompletionStatus set to CompletionStatusFailOnly and any child transaction will be called to setRollbackOnly.

Specified by:
complete in interface UserActivity
Returns:
The Outcome returned is both set by and given meaning by the SignalSet used for completion. In the absence of a CompletionSignalSet a null Outcome object reference is returned.
Throws:
NoActivityException
ActivityPendingException
ContextPendingException
ServiceNotRegisteredException
NotOriginatorException
ActivityNotProcessedException
SystemException

setCompletionStatus

public void setCompletionStatus(int completionStatus)
                         throws NoActivityException,
                                InvalidStateException,
                                ServiceNotRegisteredException,
                                SystemException
OK Sets the CompletionStatus of the active Activity. This method may be called multiple times before the Activity is completed, and the CompletionStatus may be changed between CompletionStatusSuccess and CompletionStatusFail to indicate a point in time value. Once the CompletionStatus has been set to CompletionStatusFailOnly, it may not be changed again.

Specified by:
setCompletionStatus in interface UserActivity
Parameters:
completionStatus - - the CompletionStatus value to set.
Throws:
NoActivityException - - Thrown if there is no Activity associated with the calling thread of execution.
InvalidStateException - - Thrown if an attempt is made to update a CompletionStatus of CompletionStatusFailOnly or if a null or invalid value is specified by completionStatus.
ServiceNotRegisteredException - - Thrown if no ServiceManager has been registered.
SystemException

getCompletionStatus

public int getCompletionStatus()
                        throws ServiceNotRegisteredException,
                               NoActivityException,
                               SystemException
Returns the current value of the CompletionStatus of the active Activity.

Specified by:
getCompletionStatus in interface UserActivity
Returns:
The CompletionStatus of the active Activity.
Throws:
ServiceNotRegisteredException - - Thrown if there is no Activity associated with the calling thread of execution.
NoActivityException - - Thrown if no ServiceManager has been registered.
SystemException - - Thrown if the Activity service encounters an unexpected error condition.

getStatus

public int getStatus()
              throws ServiceNotRegisteredException,
                     SystemException
Returns the current value of the Status of the active Activity.

Specified by:
getStatus in interface UserActivity
Returns:
The Status of the active Activity.
Throws:
ServiceNotRegisteredException - Thrown if no ServiceManager has been registered.
SystemException - Thrown if the Activity service encounters an unexpected error condition.

getName

public java.lang.String getName()
                         throws ServiceNotRegisteredException,
                                SystemException
Returns a printable string describing the active Activity.

Specified by:
getName in interface UserActivity
Returns:
a printable string describing the active Activity. If no Activity is associated with the calling thread then null is returned.
Throws:
ServiceNotRegisteredException - Thrown if no ServiceManager has been registered.
SystemException - - Thrown if the Activity service encounters an unexpected error condition.

setTimeout

public void setTimeout(int timeout)
                throws ServiceNotRegisteredException,
                       TimeoutRangeException,
                       SystemException
Sets the default timeout, in seconds, after which an Activity may be automatically completed by the Activity service.

Specified by:
setTimeout in interface UserActivity
Parameters:
timeout - - the default timeout period (in seconds) used by any future Activities begun with a timeout value of zero. This default is used for an Activity that is begun with a timeout parameter value of 0. A value of -1 indicates no timeout. A value of 0 for the default timeout indicates that a system-managed value or implementation-specific default should be used. The timeout is a useful mechanism for protecting against clients that fail to end an Activity in a timely fashion.
Throws:
ServiceNotRegisteredException - - Thrown if no ServiceManager has been registered.
TimeoutRangeException - - Thrown if timeout is less than -1 or if it is outside an administratively configured range in the deployed system.
SystemException - - Thrown if the Activity service encounters an unexpected error condition.

getTimeout

public int getTimeout()
               throws ServiceNotRegisteredException,
                      SystemException
Returns the default timeout value.

Specified by:
getTimeout in interface UserActivity
Returns:
The default timeout value, in seconds.
Throws:
ServiceNotRegisteredException - - Thrown if no ServiceManager has been registered.
SystemException

getGlobalId

public GlobalId getGlobalId()
                     throws ServiceNotRegisteredException,
                            SystemException
Returns the GlobalId of the active Activity.

Specified by:
getGlobalId in interface UserActivity
Returns:
The GlobalId of the active Activity, or null if there is no Activity associated with the thread.
Throws:
ServiceNotRegisteredException
SystemException

broadcast

public Outcome broadcast(java.lang.String signalSetName)
                  throws NoActivityException,
                         SignalSetUnknownException,
                         ServiceNotRegisteredException,
                         InvalidActivityException,
                         ActivityNotProcessedException,
                         SystemException
Causes the SignalSet specified by signalSetName to start producing signals for all registered Actions. This method is used to distribute Signals to Actions at times other than during completion. Pre-defined SignalSets, such as Synchronization, cannot be requested to produce signals via this method.

Specified by:
broadcast in interface UserActivity
Parameters:
signalSetName - - the name of the SignalSet that is to produce the signals.
Returns:
The Outcome returned is both set by and given meaning by the SignalSet. A null Outcome object reference may be returned if the SignalSet does not produce an Outcome.
Throws:
NoActivityException- - Thrown if there is no Activity associated with the calling thread of execution.
SignalSetUnknownException
ServiceNotRegisteredException - - Thrown if no ServiceManager has been registered.
InvalidActivityException - Thrown if an attempt is made to use the Synchronization or ChildLifetime SignalSets, or if the Activity is in the process of completion.
ActivityNotProcessedException
SystemException
NoActivityException

getCoordinator

public ActivityCoordinator getCoordinator()
                                   throws ServiceNotRegisteredException,
                                          NoImplementException,
                                          SystemException
Returns the ActivityCoordinator of the active Activity, or null if there is no Activity associated with the calling thread.

Specified by:
getCoordinator in interface UserActivity
Returns:
ActivityCoordinator of the active Activity
Throws:
ServiceNotRegisteredException
NoImplementException
SystemException

getParentCoordinator

public ActivityCoordinator getParentCoordinator()
                                         throws ServiceNotRegisteredException,
                                                NoImplementException,
                                                SystemException
Returns the ActivityCoordinator of the parent of the active Activity, or null if the active Activity is a top-level Activity. In some execution environments, such as a J2EE client, this method need not be implemented and calling it may result in a NoImplementationException.

Specified by:
getParentCoordinator in interface UserActivity
Returns:
The ActivityCoordinator of the active Activity. If there is no Activity associated with the calling thread then a null object reference is returned.
Throws:
ServiceNotRegisteredException - - Thrown if no ServiceManager has been registered.
NoImplementException - - Thrown if the Activity service does not provide an implementation of this method in the calling environment, for example if a J2EE client calls this method.
SystemException

getPropertyGroup

public PropertyGroup getPropertyGroup(java.lang.String name)
                               throws PropertyGroupUnknownException,
                                      ServiceNotRegisteredException,
                                      NoActivityException,
                                      SystemException
NOT YET IMPLEMENTED

Specified by:
getPropertyGroup in interface UserActivity
Throws:
PropertyGroupUnknownException
ServiceNotRegisteredException
NoActivityException
SystemException

registerService

public void registerService(ServiceManager service)
                     throws PropertyGroupUnknownException,
                            ServiceAlreadyRegisteredException,
                            SystemException
Registers a ServiceManager for the type of high-level service (HLS) whose activities are to be demarcated through the target UserActivity instance. The Activity service uses the properties of the registered ServiceManager to create and operate on Activities specific to that service. The UserActivity (or specialised ActivityManager) instance requires a ServiceManager to be registered with it before it may be used to begin new Activities.

Specified by:
registerService in interface UserActivity
Parameters:
service - - the ServiceManager for the HLS whose activities are to be demarcated through the target UserActivity instance.
Throws:
PropertyGroupUnknownException - - Thrown if the ServiceManager cannot obtain a PropertyGroupManager for one or more of the PropertyGroups it uses.
ServiceAlreadyRegisteredException - - Thrown if a ServiceManager has already been registered with the UserActivity instance.
SystemException

getService

public ServiceManager getService()
                          throws SystemException
Returns the registered ServiceManager for this UserActivity instance.

Specified by:
getService in interface UserActivity
Returns:
The ServiceManager for this UserActivity instance, or null if none has been registered.
Throws:
SystemException

recreate

public ActivityCoordinator recreate(GlobalId activity,
                                    GlobalId parent,
                                    boolean resume)
                             throws ServiceNotRegisteredException,
                                    ActivityCompletedException,
                                    java.lang.IllegalArgumentException,
                                    SystemException
NOT YET IMPLEMENTED

Specified by:
recreate in interface UserActivity
Throws:
ServiceNotRegisteredException
ActivityCompletedException
java.lang.IllegalArgumentException
SystemException

recover

public GlobalId[] recover()
                   throws ServiceNotRegisteredException,
                          SystemException
NOT YET IMPLEMENTED

Specified by:
recover in interface UserActivity
Throws:
ServiceNotRegisteredException
SystemException

forget

public void forget(GlobalId globalId)
            throws ServiceNotRegisteredException,
                   SystemException
NOT YET IMPLEMENTED

Specified by:
forget in interface UserActivity
Throws:
ServiceNotRegisteredException
SystemException

suspend

public ActivityToken suspend()
                      throws ServiceNotRegisteredException,
                             SystemException
Suspends the association of the current Activity from the calling thread of execution along with any child Activities of the same ContextGroup nested within that Activity. If the suspended Activity is nested within a parent then the parent Activity becomes associated with the thread on completion of this method.

Specified by:
suspend in interface ActivityManager
Returns:
An ActivityToken representing the suspended Activity. This ActivityToken maintains knowledge of the nested Activities and transactions that were suspended when the target Activity was suspended as well as any parent Activity that was established as a result of the suspend operation. The ActivityToken may be used on a subsequent call to resume but not to resumeAll or resumeGroup. If the calling thread is not associated with any Activity then null is returned.
Throws:
ServiceNotRegisteredException
SystemException

resume

public void resume(ActivityToken activityToken)
            throws InvalidActivityException,
                   InvalidParentContextException,
                   ServiceNotRegisteredException,
                   SystemException
Resumes the association of the Activity, and any nested Activities and transactions, represented by the ActivityToken with the calling thread of execution. The ActivityToken represents a hierarchy of one of more Activities and transactions and must have been obtained by a prior call to suspend. If there is an Activity associated with the thread prior to the method invocation then the re-associated Activity is resumed as a child of the Activity that is already on the thread. Any such parent Activity must be the same parent Activity within which the child Activity was originally begun. If the specified ActivityToken is null, then no new associated is made.

Specified by:
resume in interface ActivityManager
Parameters:
activityToken - - the ActivityToken to resume. The ActivityToken represents a hierarchy of one of more Activities and transactions and must have been obtained by a prior call to suspend.
Throws:
InvalidActivityException
InvalidParentContextException
ServiceNotRegisteredException
SystemException

suspendGroup

public ActivityToken suspendGroup()
                           throws ServiceNotRegisteredException,
                                  SystemException
Not yet implemented.

Specified by:
suspendGroup in interface ActivityManager
Throws:
ServiceNotRegisteredException
SystemException

resumeGroup

public void resumeGroup(ActivityToken activityToken)
                 throws InvalidActivityException,
                        InvalidParentContextException,
                        ServiceNotRegisteredException,
                        SystemException
Not yet implemented.

Specified by:
resumeGroup in interface ActivityManager
Throws:
InvalidActivityException
InvalidParentContextException
ServiceNotRegisteredException
SystemException

suspendAll

public ActivityToken suspendAll()
                         throws ServiceNotRegisteredException,
                                SystemException
Not yet implemented.

Specified by:
suspendAll in interface ActivityManager
Throws:
ServiceNotRegisteredException
SystemException

resumeAll

public void resumeAll(ActivityToken activityToken)
               throws InvalidActivityException,
                      InvalidParentContextException,
                      ServiceNotRegisteredException,
                      SystemException
Not yet implemented.

Specified by:
resumeAll in interface ActivityManager
Throws:
InvalidActivityException
InvalidParentContextException
ServiceNotRegisteredException
SystemException

hibernate

public GlobalId hibernate()
                   throws ServiceNotRegisteredException,
                          InvalidActivityException,
                          SystemException
Not yet implemented.

Specified by:
hibernate in interface ActivityManager
Throws:
ServiceNotRegisteredException
InvalidActivityException
SystemException

reactivate

public void reactivate(GlobalId globalId)
                throws ActivityCompletedException,
                       InvalidParentContextException,
                       ServiceNotRegisteredException,
                       SystemException
Not yet implemented.

Specified by:
reactivate in interface ActivityManager
Throws:
ActivityCompletedException
InvalidParentContextException
ServiceNotRegisteredException
SystemException

setActivityIdGenerator

public static void setActivityIdGenerator(ActivityIdGenerator generator)
Sets the Activity Id Generator for all Activity Service instances.

Parameters:
generator - - A reference to the unique ActivityIdGenerator

getNumberOfActivities

public int getNumberOfActivities()
Return the number of activities in the activities HashMap.

Returns:
Number of activities currently in the HashMap.

associateActivityToCurrentThread

public void associateActivityToCurrentThread(ActivityCoordinator activity)
Specified by:
associateActivityToCurrentThread in interface ActivityManager

disassociateActivityFromCurrentThread

public ActivityCoordinator disassociateActivityFromCurrentThread()
Specified by:
disassociateActivityFromCurrentThread in interface ActivityManager

linkActivityToId

public void linkActivityToId(java.lang.String actId,
                             ActivityCoordinator activity)
Specified by:
linkActivityToId in interface ActivityManager

getInstances

public static int getInstances()