net.kwfgrid.gwes
Class Activity

java.lang.Object
  extended by net.kwfgrid.gwes.Activity

public abstract class Activity
extends Object

This abstract class is to be extended in order to implement a concrete activity, such as a remote procedure call. Activities are single process steps of a workflow. In order to implement your own activity class, you should override the methods

 initiateActivity()
 startActivity()
 simulateActivity()
 suspendActivity()
 resumeActivity()
 abortActivity()
 restartActivity()
 cleanupActivity()
 

Version:
$Id: Activity.java 1534 2011-06-29 14:53:44Z hoheisel $
Author:
Andreas Hoheisel (www.andreas-hoheisel.de)
See Also:
initiateActivity(), startActivity(), simulateActivity(), suspendActivity(), resumeActivity(), abortActivity(), restartActivity(), cleanupActivity()

Nested Class Summary
static class Activity.Status
          Valid status for activities:
Status UNDEFINED.
 
Field Summary
static long DEFAULT_TIMEOUT_ACTIVE
          Default timeoutActive for activities in state "ACTIVE" in milliseconds.
static long DEFAULT_TIMEOUT_RUNNING
          Default timeoutRunning for activities in state "RUNNING" or "ACTIVE" in milliseconds.
 GenericWorkflowHandler handler
          The parent workflow handler that owns this activity
 String ID
          Identifier of this Activity
 Integer lastExitCode
          saves the last exitCode in call stack for SOAPFault
static org.apache.log4j.Logger logger
          log4j logger
protected  net.kwfgrid.gworkflowdl.structure.OperationCandidate op
          The operation candidate contains all information about the operation and its resources.
 long timeoutActive
          Timeout for this activity in state active in milliseconds.
 long timeoutRunning
          Timeout for this activity in state running or active in milliseconds.
protected  TransitionOccurrence to
          The transition occurrence contains all the workflow information needed for this activity.
 
Constructor Summary
Activity(GenericWorkflowHandler handler, TransitionOccurrence to, net.kwfgrid.gworkflowdl.structure.OperationCandidate op)
          Constructor for Activity.
 
Method Summary
abstract  void abortActivity()
          Abort this activity.
 void appendFaultMessage(String faultMessage)
          Append the human-readable fault message.
abstract  void cleanupActivity()
          Cleans up all temporary data produced by this activity.
 void decreaseAttempts()
           
 void enqueueActivity()
          Enqueue this activity in order to be processed by the ActivityStarter.
 int getAttempts()
          Get the number of pending attempts for this activity.
 long getDurationActive()
          Get the duration of how long this activity was "ACTIVE".
 long getDurationInitiated()
          Get the duration of how long this activity was "INITIATED" (before running).
 long getDurationRunning()
          Get the duration of how long this activity was "RUNNING" not including the time it was "ACTIVE".
 long getDurationSuspended()
          Get the duration of how long this activity was "SUSPENDED".
 long getDurationTotal()
          Get the total activity duration.
 long getDurationUndefined()
          Get the duration of how long this activity was "UNDEFINED" (before initiated).
 String getFaultMessage()
          Gest the human-readable fault message.
 GWESLogger getGlog()
          Get the GWESLogger for this activity.
 GenericWorkflowHandler getHandler()
          Get the parent workflow handler that owns this activity.
 String getID()
          Get the identifier of this activity.
 net.kwfgrid.gworkflowdl.structure.OperationCandidate getOperationCandidate()
          Get the operation candidate.
 String getOperationName()
          Get the operation name of this activity.
 String getResourceName()
          Get the resource name of this activity.
 SOAPFault getSoapFault()
          Get fault as SOAPFault.
 long getStartTimeTotal()
          Get the start time of this activity in milliseconds since 1970.
 Activity.Status getStatus()
          Get the current status of this activity as int.
 String[] getStatusArray()
          Get the activity status as an array of strings.
 String getStatusAsString()
          Get the current status of the activity as string.
static String getStatusAsString(Activity.Status status)
          Convert the status of a activity from an integer to a string.
 long getTimeoutActive()
          Get the timeoutActive of this activity.
 long getTimeoutRunning()
          Get the timeoutRunning of this activity.
 TransitionOccurrence getTransitionOccurrence()
          Get transition occurrence object.
abstract  void initiateActivity()
          Initiate this activity.
 boolean isFinalStatus()
           
static boolean isFinalStatus(Activity.Status status)
           
protected  void putFaultTokenOnOutputPlaces()
          Put SOAP Fault on each output token that is connected with a edge expression.
abstract  void restartActivity()
          Restart this activity.
abstract  void resumeActivity()
          Resume this activity.
 void setFaultMessage(String faultMessage)
          Set the human-readable fault message.
 void setSoapFault(SOAPFault soapFault)
          Set SOAP fault.
 void setStatus(Activity.Status status)
          Set status of the activity and notify threads that wait for a status change.
protected  void setTimeoutActive(long timeoutActive)
          Set the timeoutActive of this Activity.
protected  void setTimeoutRunning(long timeoutRunning)
          Set the timeoutRunning of this Activity.
abstract  void simulateActivity()
          Simulate this activity.
abstract  void startActivity()
          Start this activity.
abstract  void suspendActivity()
          Suspend this activity.
 String toString()
          Each activity should be able to give some information about itself using the toString() method.
 void waitForCompleteOrTerminate()
          Wait for activity to change its status to COMPLETED or TERMINATED.
 Activity.Status waitForStatusChangeFrom(Activity.Status oldStatus)
          Wait for activity to change its status.
 void waitForStatusChangeTo(Activity.Status newStatus)
          Wait for activity to change its status to a specified status.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

public static final org.apache.log4j.Logger logger
log4j logger


ID

public final String ID
Identifier of this Activity


handler

public GenericWorkflowHandler handler
The parent workflow handler that owns this activity


to

protected TransitionOccurrence to
The transition occurrence contains all the workflow information needed for this activity.


op

protected net.kwfgrid.gworkflowdl.structure.OperationCandidate op
The operation candidate contains all information about the operation and its resources.


timeoutRunning

public long timeoutRunning
Timeout for this activity in state running or active in milliseconds.


timeoutActive

public long timeoutActive
Timeout for this activity in state active in milliseconds.


DEFAULT_TIMEOUT_RUNNING

public static final long DEFAULT_TIMEOUT_RUNNING
Default timeoutRunning for activities in state "RUNNING" or "ACTIVE" in milliseconds. default = 1000*60*60*24 = 86400000 => 1 Day

See Also:
Constant Field Values

DEFAULT_TIMEOUT_ACTIVE

public static final long DEFAULT_TIMEOUT_ACTIVE
Default timeoutActive for activities in state "ACTIVE" in milliseconds. default = 1000*60*60*2 = 7200000 => 2 Hours

See Also:
Constant Field Values

lastExitCode

public Integer lastExitCode
saves the last exitCode in call stack for SOAPFault

Constructor Detail

Activity

public Activity(GenericWorkflowHandler handler,
                TransitionOccurrence to,
                net.kwfgrid.gworkflowdl.structure.OperationCandidate op)
         throws net.kwfgrid.gworkflowdl.structure.WorkflowFormatException,
                LoggingException
Constructor for Activity. In order to access the input and output objects use the TransitionOccurrence class.

Parameters:
handler - The parent generic workflow handler.
to - The TransitionOccurrence object with workflow data about this activity invocation.
op - The OperationCandidate with information about the operation and its resources.
Throws:
net.kwfgrid.gworkflowdl.structure.WorkflowFormatException
LoggingException
Method Detail

setStatus

public void setStatus(Activity.Status status)
Set status of the activity and notify threads that wait for a status change.


getStatus

public Activity.Status getStatus()
Get the current status of this activity as int.

Returns:
current activity status
See Also:
getStatusAsString()

waitForStatusChangeFrom

public Activity.Status waitForStatusChangeFrom(Activity.Status oldStatus)
                                        throws InterruptedException
Wait for activity to change its status.

Parameters:
oldStatus - The old status
Returns:
The new status
Throws:
InterruptedException - If the thread has been interrupted

waitForStatusChangeTo

public void waitForStatusChangeTo(Activity.Status newStatus)
                           throws InterruptedException
Wait for activity to change its status to a specified status.

Parameters:
newStatus - The new status code to wait for
Throws:
InterruptedException - If the thread has been interrupted

waitForCompleteOrTerminate

public void waitForCompleteOrTerminate()
                                throws InterruptedException
Wait for activity to change its status to COMPLETED or TERMINATED.

Throws:
InterruptedException - If the thread has been interrupted

isFinalStatus

public boolean isFinalStatus()

isFinalStatus

public static boolean isFinalStatus(Activity.Status status)

getStatusAsString

public String getStatusAsString()
Get the current status of the activity as string.

Returns:
string representing the status of the activity. This String is useful for user-readable output.
See Also:
getStatus(), getStatusAsString(Status)

getStatusAsString

public static String getStatusAsString(Activity.Status status)
Convert the status of a activity from an integer to a string.

Parameters:
status - The status code with should be converted into a string.
Returns:
string representing the status that corresponds to the status code.

getID

public String getID()
Get the identifier of this activity. The activity identifier is unique for this GWESEngine.

Returns:
The identifier of this activity

getHandler

public GenericWorkflowHandler getHandler()
Get the parent workflow handler that owns this activity.

Returns:
The workflow handler.

getGlog

public GWESLogger getGlog()
Get the GWESLogger for this activity.

Returns:
The GWESLogger.

getTransitionOccurrence

public TransitionOccurrence getTransitionOccurrence()
Get transition occurrence object.

Returns:

getOperationCandidate

public net.kwfgrid.gworkflowdl.structure.OperationCandidate getOperationCandidate()
Get the operation candidate.

Returns:

getOperationName

public String getOperationName()
Get the operation name of this activity.

Returns:
The operation name.

getResourceName

public String getResourceName()
Get the resource name of this activity.

Returns:
The resource name.

getTimeoutRunning

public long getTimeoutRunning()
Get the timeoutRunning of this activity.

Returns:
The timeoutRunning in milliseconds.

setTimeoutRunning

protected void setTimeoutRunning(long timeoutRunning)
Set the timeoutRunning of this Activity.

Parameters:
timeoutRunning - The timout in milliseconds.

getTimeoutActive

public long getTimeoutActive()
Get the timeoutActive of this activity.

Returns:
The timeoutActive in milliseconds.

setTimeoutActive

protected void setTimeoutActive(long timeoutActive)
Set the timeoutActive of this Activity.

Parameters:
timeoutActive - The timout in milliseconds.

getFaultMessage

public String getFaultMessage()
Gest the human-readable fault message. Returns null if there is no fault message.

Returns:
The fault message as String.

setFaultMessage

public void setFaultMessage(String faultMessage)
Set the human-readable fault message.

Parameters:
faultMessage - The fault message as String.

appendFaultMessage

public void appendFaultMessage(String faultMessage)
Append the human-readable fault message.

Parameters:
faultMessage - The fault message as String to append.

getSoapFault

public SOAPFault getSoapFault()
Get fault as SOAPFault.

Returns:
The SOAP fault of this activity or null if there is no fault.

setSoapFault

public void setSoapFault(SOAPFault soapFault)
Set SOAP fault.

Parameters:
soapFault - The fault.

getStartTimeTotal

public long getStartTimeTotal()
Get the start time of this activity in milliseconds since 1970.

Returns:
The start time

getDurationUndefined

public long getDurationUndefined()
Get the duration of how long this activity was "UNDEFINED" (before initiated).

Returns:
The duration in milliseconds

getDurationInitiated

public long getDurationInitiated()
Get the duration of how long this activity was "INITIATED" (before running).

Returns:
The duration in milliseconds

getDurationRunning

public long getDurationRunning()
Get the duration of how long this activity was "RUNNING" not including the time it was "ACTIVE".

Returns:
The duration in milliseconds

getDurationActive

public long getDurationActive()
Get the duration of how long this activity was "ACTIVE".

Returns:
The duration in milliseconds

getDurationSuspended

public long getDurationSuspended()
Get the duration of how long this activity was "SUSPENDED".

Returns:
The duration in milliseconds

getDurationTotal

public long getDurationTotal()
Get the total activity duration.

Returns:
The duration in milliseconds

getAttempts

public int getAttempts()
Get the number of pending attempts for this activity. "1" means, that this is the last attempt.

Returns:
number of attempts or "-1" if attempts is not set.

decreaseAttempts

public void decreaseAttempts()

enqueueActivity

public void enqueueActivity()
                     throws net.kwfgrid.gworkflowdl.structure.WorkflowFormatException
Enqueue this activity in order to be processed by the ActivityStarter. If the workflow handler is null, then directly start the activity.

Throws:
net.kwfgrid.gworkflowdl.structure.WorkflowFormatException

getStatusArray

public String[] getStatusArray()
Get the activity status as an array of strings. Example:
 ///ToDo update regarding the real output
 "ID=hoheisel_f2968050-1d6a-11db-bacc-ad353bc1f9b1"
 "status=COMPLETED"
 "birthdayMs=1154003111126"
 "durationUndefinedMs=527"
 "durationInitiatedMs=792"
 "durationRunningMs=0"
 "durationActiveMs=0"
 "durationSuspendedMs=0"
 "durationTotalMs=1351"
 "endTimeMs=1154003112477"
 "level=MEMORY"
 "description=test workflow"
 

Returns:
The current activity status as string array

initiateActivity

public abstract void initiateActivity()
                               throws ActivityException
Initiate this activity. Status should switch to INITIATED. Method should only work if the status was UNDEFINED before. Implement this method in all derived classes!

Throws:
ActivityException

startActivity

public abstract void startActivity()
                            throws ActivityException,
                                   net.kwfgrid.gworkflowdl.structure.WorkflowFormatException
Start this activity. Status should switch to RUNNING. Implement this method in all derived classes!

Throws:
ActivityException
net.kwfgrid.gworkflowdl.structure.WorkflowFormatException

simulateActivity

public abstract void simulateActivity()
                               throws ActivityException,
                                      net.kwfgrid.gworkflowdl.structure.WorkflowFormatException
Simulate this activity. Status should switch to RUNNING. This method is equivalent to "startActivity()", however the invocation of the activity is only simulated and takes minimum amount of time. The performance results (duration, memory consumption etc.) of the activity should be returned as properties of the output tokens. Implement this method in all derived classes!

Throws:
ActivityException
net.kwfgrid.gworkflowdl.structure.WorkflowFormatException

suspendActivity

public abstract void suspendActivity()
                              throws ActivityException
Suspend this activity. Status should switch to SUSPENDED. Implement this method in all derived classes!

Throws:
ActivityException

resumeActivity

public abstract void resumeActivity()
                             throws ActivityException
Resume this activity. Status should switch to RUNNING. Implement this method in all derived classes!

Throws:
ActivityException

abortActivity

public abstract void abortActivity()
                            throws ActivityException
Abort this activity. Status should switch to TERMINATED. Implement this method in all derived classes!

Throws:
ActivityException

restartActivity

public abstract void restartActivity()
                              throws ActivityException
Restart this activity. Status should switch to INITIATED. Implement this method in all derived classes!

Throws:
ActivityException

cleanupActivity

public abstract void cleanupActivity()
                              throws ActivityException
Cleans up all temporary data produced by this activity. Implement this method in all derived classes!

Throws:
ActivityException

toString

public String toString()
Each activity should be able to give some information about itself using the toString() method.

Overrides:
toString in class Object
Returns:
String containing human readable information about the activity.

putFaultTokenOnOutputPlaces

protected void putFaultTokenOnOutputPlaces()
                                    throws net.kwfgrid.gworkflowdl.structure.WorkflowFormatException
Put SOAP Fault on each output token that is connected with a edge expression. Does NOT overwrite existing tokens!

Throws:
net.kwfgrid.gworkflowdl.structure.WorkflowFormatException


Copyright © 2005-2011 Fraunhofer FIRST. All Rights Reserved.