org.objectweb.jass.as
Class ActivityImpl

java.lang.Object
  extended byorg.objectweb.jass.as.ActivityImpl
All Implemented Interfaces:
ActivityCoordinator, java.io.Serializable, TimeoutTarget

public class ActivityImpl
extends java.lang.Object
implements ActivityCoordinator, TimeoutTarget, java.io.Serializable

Each object of this class represents an activity and its coordinator. Implements the AS ActivityCoordinator interface in order to be able to broadcast signals to registered actions. TimeoutTarget is implemented in order to be warned of timeout.

Author:
fran Date: Feb 16, 2004 org.objectweb.jass.asActivityImpl.java
See Also:
Serialized Form

Constructor Summary
ActivityImpl(ActivityService activityService, ActivityIdImpl activityId, ActivityImpl superior, int timeout)
           
 
Method Summary
 void addAction(Action action, java.lang.String signalSetName, int priority)
          Establishes an interest relationship between the specified Action and SignalSet for the Activity represented by the target ActivityCoordinator.
 void addGlobalAction(Action action, int priority)
          Establishes an interest relationship between the specified Action and all SignalSets used by the Activity represented by the target ActivityCoordinator.
 void associateActivityManager(ActivityManager am)
          Reasociates the local ActivityService with the recreated activity
 void associateCurrentThread()
          Associates the calling thread with this activity.
 Outcome completeActivity(int completionStatus)
          Causes the Activity associated with the target ActivityCoordinator to complete with the specified CompletionStatus.
 void disassociateCurrentThread()
          Disassociates the calling thread from this activity.
 Action[] getActions(java.lang.String signalSetName)
          Returns all the Actions that have been registered with an interest in the specified signalSetName.
 java.lang.String getCompletionSignalSetName()
          Returns the name of the SignalSet, if any, that will be used for the distribution of completion signals when the current Activity completes.
 GlobalId getGlobalId()
          Returns the GlobalId of the Activity represented by the target ActivityCoordinator.
 java.lang.String getName()
          Returns a printable string describing the Activity represented by the target ActivityCoordinator.
 int getNumberRegisteredActions(java.lang.String signalSetName)
          Returns the number of Actions, including global Actions, registered with the target ActivityCoordinator with an interest in the specified SignalSet.
 ActivityCoordinator getParent()
          Returns the parent ActivityCoordinator or null if the target ActivityCoordinator represents a top-level Activity.
 int getParentStatus()
          Returns the Status of the Activity represented by the target ActivityCoordinator's parent.
 int getStatus()
          Returns the Status of the Activity represented by the target ActivityCoordinator.
 java.lang.String getStringCompletionStatus(int completionStatus)
          Return the string representation of the activity completion status.
 java.lang.String getStringStatus(int status)
          Return the string representation of the activity status.
 Outcome heuristicComplete(int completionStatus)
          TODO NOT YET IMPLEMENTED
 boolean isSameActivity(ActivityCoordinator coord)
          Returns true if the specified coord represents the same Activity as the target ActivityCoordinator.
 Outcome processSignalSet(java.lang.String signalSetName, int completionStatus)
          Causes the SignalSet specified by signalSetName to start producing signals for all registered Actions at times other than during completion.
 void removeAction(Action action, java.lang.String signalSetName)
          Removes the interest relationship between the specified Action and SignalSet for the Activity represented by the target ActivityCoordinator.
 void removeGlobalAction(Action action)
          Removes the interest relationship between the specified Action and all SignalSets for the Activity represented by the target ActivityCoordinator.
 void setCompletionSignalSetName(java.lang.String signalSetName)
          Sets the name of the SignalSet that should be used for the distribution of completion signals when the current Activity completes.
 void timedOut(Timeout timeout)
          Called when our timeout expires.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActivityImpl

public ActivityImpl(ActivityService activityService,
                    ActivityIdImpl activityId,
                    ActivityImpl superior,
                    int timeout)
Method Detail

addAction

public void addAction(Action action,
                      java.lang.String signalSetName,
                      int priority)
               throws SignalSetUnknownException,
                      SystemException,
                      java.lang.IllegalStateException
Establishes an interest relationship between the specified Action and SignalSet for the Activity represented by the target ActivityCoordinator. When a Signal which is a member of the SignalSet is sent, the processSignal method of the Action will be invoked with that Signal. If multiple Actions are registered, then priority may be used to place an order on how they will be invoked when Signals are sent: higher priority Actions will occur first in the Action list, and hence be invoked before other, lower priority, Actions. The priority value must be a positive value; a value of zero means that the Activity Service implementation is free to place the Action at any point in the Action list. If the specified Action is registered multiple times for the same SignalSet then it will be invoked multiple times with the Signals from that SignalSet.

Specified by:
addAction in interface ActivityCoordinator
Throws:
SignalSetUnknownException
SystemException
java.lang.IllegalStateException

addGlobalAction

public void addGlobalAction(Action action,
                            int priority)
                     throws SystemException,
                            java.lang.IllegalStateException
Establishes an interest relationship between the specified Action and all SignalSets used by the Activity represented by the target ActivityCoordinator. When a Signal which is a member of any of the SignalSets is sent, the processSignal method of the Action will be invoked with that Signal. If multiple Actions are registered, then priority may be used to place an order on how they will be invoked when Signals are sent: higher priority Actions will occur first in the Action list, and hence be invoked before other, lower priority, Actions. The priority value must be a positive value; a value of zero means that the Activity Service implementation is free to place the Action at any point in the Action list. If the specified Action is registered multiple times with the target ActivityCoordinator then it will be invoked multiple times with each Signal.

Specified by:
addGlobalAction in interface ActivityCoordinator
Throws:
SystemException
java.lang.IllegalStateException

removeAction

public void removeAction(Action action,
                         java.lang.String signalSetName)
                  throws ActionNotFoundException,
                         SystemException,
                         java.lang.IllegalStateException
Removes the interest relationship between the specified Action and SignalSet for the Activity represented by the target ActivityCoordinator. If signalSetName is an empty String then the interest relationship is removed between the specified Action and all SignalSets in the target Activity. This operation has no effect on any global actions. If the specified Action was registered multiple times with the target ActivityCoordinator then only a single instance of this Action is removed by each call to this method.

Specified by:
removeAction in interface ActivityCoordinator
Throws:
ActionNotFoundException
SystemException
java.lang.IllegalStateException

removeGlobalAction

public void removeGlobalAction(Action action)
                        throws ActionNotFoundException,
                               SystemException,
                               java.lang.IllegalStateException
Removes the interest relationship between the specified Action and all SignalSets for the Activity represented by the target ActivityCoordinator. This operation has no effect on any non-global actions. If the specified Action was registered multiple times with the target ActivityCoordinator then only a single instance of this Action is removed by each call to this method.

Specified by:
removeGlobalAction in interface ActivityCoordinator
Throws:
ActionNotFoundException
SystemException
java.lang.IllegalStateException

getActions

public Action[] getActions(java.lang.String signalSetName)
                    throws SignalSetUnknownException,
                           SystemException
Returns all the Actions that have been registered with an interest in the specified signalSetName. This method may be used by a HLS that has determined that an Activity needs to be persisted and needs to log the Actions registered in the Activity.

Specified by:
getActions in interface ActivityCoordinator
Throws:
SignalSetUnknownException
SystemException

getNumberRegisteredActions

public int getNumberRegisteredActions(java.lang.String signalSetName)
                               throws SignalSetUnknownException,
                                      SystemException
Returns the number of Actions, including global Actions, registered with the target ActivityCoordinator with an interest in the specified SignalSet.

Specified by:
getNumberRegisteredActions in interface ActivityCoordinator
Throws:
SignalSetUnknownException
SystemException

setCompletionSignalSetName

public void setCompletionSignalSetName(java.lang.String signalSetName)
                                throws SignalSetUnknownException,
                                       SystemException,
                                       java.lang.IllegalStateException
Sets the name of the SignalSet that should be used for the distribution of completion signals when the current Activity completes. This method can be called multiple times during the lifetime of an Activity, before the Activity starts completion processing. The last value specified before completion processing starts is used during completion processing.

Specified by:
setCompletionSignalSetName in interface ActivityCoordinator
Throws:
SignalSetUnknownException
SystemException
java.lang.IllegalStateException

getCompletionSignalSetName

public java.lang.String getCompletionSignalSetName()
                                            throws SystemException
Returns the name of the SignalSet, if any, that will be used for the distribution of completion signals when the current Activity completes.

Specified by:
getCompletionSignalSetName in interface ActivityCoordinator
Throws:
SystemException

getParent

public ActivityCoordinator getParent()
                              throws SystemException
Returns the parent ActivityCoordinator or null if the target ActivityCoordinator represents a top-level Activity.

Specified by:
getParent in interface ActivityCoordinator
Throws:
SystemException

getGlobalId

public GlobalId getGlobalId()
                     throws SystemException
Returns the GlobalId of the Activity represented by the target ActivityCoordinator.

Specified by:
getGlobalId in interface ActivityCoordinator
Throws:
SystemException

getStatus

public int getStatus()
              throws SystemException
Returns the Status of the Activity represented by the target ActivityCoordinator.

Specified by:
getStatus in interface ActivityCoordinator
Throws:
SystemException

getParentStatus

public int getParentStatus()
                    throws SystemException
Returns the Status of the Activity represented by the target ActivityCoordinator's parent. If the target ActivityCoordinator represents a top-level Activity, then the Status of this top-level Activity is returned.

Specified by:
getParentStatus in interface ActivityCoordinator
Throws:
SystemException

getName

public java.lang.String getName()
                         throws SystemException
Returns a printable string describing the Activity represented by the target ActivityCoordinator.

Specified by:
getName in interface ActivityCoordinator
Throws:
SystemException

isSameActivity

public boolean isSameActivity(ActivityCoordinator coord)
                       throws SystemException
Returns true if the specified coord represents the same Activity as the target ActivityCoordinator.

Specified by:
isSameActivity in interface ActivityCoordinator
Throws:
SystemException

completeActivity

public Outcome completeActivity(int completionStatus)
                         throws ActivityPendingException,
                                ContextPendingException,
                                NotOriginatorException,
                                InvalidStateException,
                                ActivityNotProcessedException,
                                SystemException
Causes the Activity associated with the target ActivityCoordinator to complete with the specified CompletionStatus. The Activity service sets the Status to StatusCompleting before asking any completion SignalSet to start producing Signals. 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. The UserActivity interface should be used in preference to the ActivityCoordinator for completing Activities in most circumstances. This method is provided primarily for use after recovery when the Activity to be completed is not associated with the calling thread.

Specified by:
completeActivity in interface ActivityCoordinator
Throws:
ActivityPendingException
ContextPendingException
NotOriginatorException
InvalidStateException
ActivityNotProcessedException
SystemException

heuristicComplete

public Outcome heuristicComplete(int completionStatus)
                          throws ActivityPendingException,
                                 ContextPendingException,
                                 InvalidStateException,
                                 ActivityNotProcessedException,
                                 SystemException
TODO NOT YET IMPLEMENTED

Specified by:
heuristicComplete in interface ActivityCoordinator
Throws:
ActivityPendingException
ContextPendingException
InvalidStateException
ActivityNotProcessedException
SystemException

processSignalSet

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

Specified by:
processSignalSet in interface ActivityCoordinator
Throws:
SignalSetUnknownException
ActivityNotProcessedException
InvalidActivityException
SystemException

timedOut

public void timedOut(Timeout timeout)
Called when our timeout expires.

Specified by:
timedOut in interface TimeoutTarget

associateCurrentThread

public void associateCurrentThread()
Associates the calling thread with this activity.

Specified by:
associateCurrentThread in interface ActivityCoordinator

disassociateCurrentThread

public void disassociateCurrentThread()
Disassociates the calling thread from this activity.

Specified by:
disassociateCurrentThread in interface ActivityCoordinator

associateActivityManager

public void associateActivityManager(ActivityManager am)
Reasociates the local ActivityService with the recreated activity

Specified by:
associateActivityManager in interface ActivityCoordinator
Parameters:
am - the activity manager interface representing the Activity Service implementation.

getStringStatus

public java.lang.String getStringStatus(int status)
Return the string representation of the activity status.

Parameters:
status - the integer status to convert.
Returns:
the string representation of the status.

getStringCompletionStatus

public java.lang.String getStringCompletionStatus(int completionStatus)
Return the string representation of the activity completion status.

Parameters:
completionStatus - the integer completion status to convert.
Returns:
the string representation of the completion status.