net.kwfgrid.gwes
Class GenericWorkflowHandler

java.lang.Object
  extended by java.lang.Thread
      extended by net.kwfgrid.gwes.GenericWorkflowHandler
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
GWorkflowDLHandler

public abstract class GenericWorkflowHandler
extends Thread

A GenericWorkflowHandler controls one workflow. This generic workflow handler is abstract and should be extended in order to implement a concrete one, which is specific to a certain Workflow Description Language. In order to implement your own GenericWorkflowHandler, you should override the methods

 initiateWorkflow()
 startWorkflow()
 suspendWorkflow()
 resumeWorkflow()
 abortWorkflow()
 
One concrete implemenation of the GenericWorkflowHandler is the KWfGenericWorkflowHandler.

Version:
$Id: GenericWorkflowHandler.java 1531 2011-06-22 18:43:10Z hoheisel $
Author:
Andreas Hoheisel (www.andreas-hoheisel.de), Andreas Hoheisel (www.andreas-hoheisel.de)
See Also:
GWorkflowDLHandler, initiateWorkflow(), startWorkflow(), suspendWorkflow(), resumeWorkflow(), abortWorkflow()

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected GenericWorkflowHandler(GWESEngine engine, String originalWorkflowDescriptionType, String workflowDescription, String userID)
          Constructor for GenericWorkflowHandler.
 
Method Summary
abstract  void abortWorkflow()
          Abort this workflow.
abstract  void abortWorkflowAsync()
          Abort this workflow asynchonously.
 String createNewErrorID()
          Get a new unique error ID for this workflow.
 ActivityTable getActivityTable()
          Get the activity table with all activities triggered by this workflow instance.
 long getBirthday()
          Get the birthday of this workflow.
 int getCompletedActivities()
           
abstract  String[] getData(String placeID)
          Get specific data that is hold inside the workflow and that is referenced by a data place identifier.
abstract  String getDescription()
          Get the human-readable description of the workflow.
 long getDurationActive()
          Get the duration of how long this workflow was "ACTIVE".
 long getDurationInitiated()
          Get the duration of how long this workflow was "INITIATED" (before running).
 long getDurationRunning()
          Get the duration of how long this workflow was "RUNNING" not including the time it was "ACTIVE".
 long getDurationSuspended()
          Get the duration of how long this workflow was "SUSPENDED".
 long getDurationTotal()
          Get the total workflow duration.
 long getDurationUndefined()
          Get the duration of how long this workflow was "UNDEFINED" (before initiated).
 long getEndTime()
          Get the completion or termination time of this workflow.
 GWESEngine getEngine()
          Get the parent GWESEngine that owns this workflow handler.
 GWESLogger getGlog()
           
 String getID()
          Get the identifier of this workflow instance.
protected  String getNewActivityID()
          Generate a new activity identifier.
 String getOriginalWorkflowDescriptionType()
          Get the original workflow description type before conversion to default description type.
 int getStatus()
          Get the current status code of this workflow as int.
 String getStatusAsString()
          Get the current status of this workflow instance as string.
 int getTerminatedActivities()
           
 String getUserID()
          Get the user identifier of the owner of this workflow instance.
 Object getWorkflow()
           
 String getWorkflowDescription()
          Get the current workflow description of this workflow.
 String[] getWorkflowStatus()
          Get the workflow status as an array of strings.
 void incrementCompletedActivities(int completedActivities)
           
 void incrementTerminatedActivities(int terminatedActivities)
           
abstract  void initiateWorkflow()
          Initiate this workflow.
protected  void logStatistics()
           
protected  String newID()
          Creates a new Universal Unique ID for a workflow instance.
abstract  void resumeWorkflow()
          Resume this workflow.
abstract  void run()
          Implement this method for each Class that exends GridJob.
abstract  void setDescription(String description)
          Set the human-readable description of the workflow.
protected  void setStatus(int status)
          Set status of the workflow and notify threads that wait for a status change.
 void setWorkflowDescription(String workflowDescription)
          Set the current workflow description of this workflow.
abstract  void startWorkflow()
          Start this workflow.
abstract  String storeWorkflow()
          Stores this workflow.
abstract  void suspendWorkflow()
          Suspend this workflow.
abstract  void suspendWorkflowAsync()
          Suspend this workflow asynchonously.
 int waitForStatusChangeFrom(int oldStatus)
          Wait for workflow to change its status.
 void waitForStatusChangeTo(int newStatus)
          Wait for workflow to change its status to a specified status.
 int waitForStatusChangeToCompletedOrTerminated()
          Wait for workflow to change its status to final states COMPLETED or TERMINATED.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GenericWorkflowHandler

protected GenericWorkflowHandler(GWESEngine engine,
                                 String originalWorkflowDescriptionType,
                                 String workflowDescription,
                                 String userID)
                          throws WorkflowSecurityException,
                                 LoggingException
Constructor for GenericWorkflowHandler.

Parameters:
engine - The parent workflow handler
originalWorkflowDescriptionType - The original type of workflow description, e.g. "GWorkflowDL 2.0" before conversion to default type.
Throws:
WorkflowSecurityException
LoggingException
Method Detail

getID

public String getID()
Get the identifier of this workflow instance. String representation of a Universal Unique ID.

Returns:
The identifier of this workflow

getUserID

public String getUserID()
Get the user identifier of the owner of this workflow instance.

Returns:
The userID

getGlog

public GWESLogger getGlog()

getOriginalWorkflowDescriptionType

public String getOriginalWorkflowDescriptionType()
Get the original workflow description type before conversion to default description type.

Returns:
String with the original workflow description type, e.g., "GWorkflowDL 2.0".

getWorkflowDescription

public String getWorkflowDescription()
Get the current workflow description of this workflow. If the workflow description changes during runtime, you should override this method by the concrete implmenetation.

Returns:
The workflow descpription

getWorkflow

public Object getWorkflow()

setWorkflowDescription

public void setWorkflowDescription(String workflowDescription)
                            throws net.kwfgrid.gworkflowdl.structure.WorkflowFormatException,
                                   StateTransitionException
Set the current workflow description of this workflow.

Parameters:
workflowDescription - The workflow description
Throws:
net.kwfgrid.gworkflowdl.structure.WorkflowFormatException
StateTransitionException

setStatus

protected void setStatus(int status)
Set status of the workflow and notify threads that wait for a status change.

See Also:
WorkflowStatus.STATUS_UNDEFINED, WorkflowStatus.STATUS_INITIATED, WorkflowStatus.STATUS_RUNNING, WorkflowStatus.STATUS_SUSPENDED, WorkflowStatus.STATUS_ACTIVE, WorkflowStatus.STATUS_TERMINATED, WorkflowStatus.STATUS_COMPLETED, waitForStatusChangeTo(int), waitForStatusChangeFrom(int)

getStatus

public int getStatus()
Get the current status code of this workflow as int.

Returns:
The current status code of this workflow.
See Also:
getStatusAsString(), WorkflowStatus.STATUS_UNDEFINED, WorkflowStatus.STATUS_INITIATED, WorkflowStatus.STATUS_RUNNING, WorkflowStatus.STATUS_SUSPENDED, WorkflowStatus.STATUS_ACTIVE, WorkflowStatus.STATUS_TERMINATED, WorkflowStatus.STATUS_COMPLETED

waitForStatusChangeFrom

public int waitForStatusChangeFrom(int oldStatus)
                            throws InterruptedException
Wait for workflow 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(int newStatus)
                           throws InterruptedException
Wait for workflow 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

waitForStatusChangeToCompletedOrTerminated

public int waitForStatusChangeToCompletedOrTerminated()
                                               throws InterruptedException
Wait for workflow to change its status to final states COMPLETED or TERMINATED.

Returns:
The final status
Throws:
InterruptedException - If the thread has been interrupted

getStatusAsString

public String getStatusAsString()
Get the current status of this workflow instance as string.

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

getWorkflowStatus

public String[] getWorkflowStatus()
Get the workflow status as an array of strings. Example:
 "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"
 "userID=test user"
 

Returns:
The current workflow status as string array

getEngine

public GWESEngine getEngine()
Get the parent GWESEngine that owns this workflow handler.

Returns:
The parent GWES engine

getActivityTable

public ActivityTable getActivityTable()
Get the activity table with all activities triggered by this workflow instance.

Returns:
The activity table

newID

protected String newID()
Creates a new Universal Unique ID for a workflow instance. The UUID now consists of two parts: The two parts are connected by a underline (_).


getNewActivityID

protected String getNewActivityID()
Generate a new activity identifier. This identifier consists of the UUID of the workflow a underscore (_) and a serial number with leading zeros (activity counter).

Returns:
The new activity identifier.

getDurationUndefined

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

Returns:
The duration in milliseconds

getDurationInitiated

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

Returns:
The duration in milliseconds

getDurationRunning

public long getDurationRunning()
Get the duration of how long this workflow 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 workflow was "ACTIVE".

Returns:
The duration in milliseconds

getDurationSuspended

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

Returns:
The duration in milliseconds

getDurationTotal

public long getDurationTotal()
Get the total workflow duration.

Returns:
The duration in milliseconds

getBirthday

public long getBirthday()
Get the birthday of this workflow. This is the time of the first occurence of STATUS_UNDEFINED of this workflow.

Returns:
The begin time in milliseconds since 1970

getEndTime

public long getEndTime()
Get the completion or termination time of this workflow.

Returns:
The end time in milliseconds since 1970 or "0" if this workflow has not been finished yet.

createNewErrorID

public String createNewErrorID()
Get a new unique error ID for this workflow.

Returns:
a String with a unique error ID.

logStatistics

protected void logStatistics()

getTerminatedActivities

public int getTerminatedActivities()

incrementTerminatedActivities

public void incrementTerminatedActivities(int terminatedActivities)

getCompletedActivities

public int getCompletedActivities()

incrementCompletedActivities

public void incrementCompletedActivities(int completedActivities)

initiateWorkflow

public abstract void initiateWorkflow()
                               throws net.kwfgrid.gworkflowdl.structure.WorkflowFormatException,
                                      StateTransitionException
Initiate this workflow. Status should switch to INITIATED. Method should only work if the status was UNDEFINED before. Implement this method in all derived classes!

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

startWorkflow

public abstract void startWorkflow()
                            throws StateTransitionException
Start this workflow. Status should switch to RUNNING. Implement this method in all derived classes!

Throws:
StateTransitionException

suspendWorkflow

public abstract void suspendWorkflow()
                              throws StateTransitionException
Suspend this workflow. Waits until status switches to SUSPENDED. Implement this method in all derived classes!

Throws:
StateTransitionException

suspendWorkflowAsync

public abstract void suspendWorkflowAsync()
                                   throws StateTransitionException
Suspend this workflow asynchonously. This method does not wait until workflow switches to SUSPENDED. Implement this method in all derived classes!

Throws:
StateTransitionException

resumeWorkflow

public abstract void resumeWorkflow()
                             throws StateTransitionException
Resume this workflow. Status should switch to RUNNING. Implement this method in all derived classes!

Throws:
StateTransitionException

abortWorkflow

public abstract void abortWorkflow()
                            throws StateTransitionException
Abort this workflow. Waits until status switches to TERMINATED. Implement this method in all derived classes!

Throws:
StateTransitionException

abortWorkflowAsync

public abstract void abortWorkflowAsync()
                                 throws StateTransitionException
Abort this workflow asynchonously. This method does not wait until status switches to TERMINATED. Implement this method in all derived classes!

Throws:
StateTransitionException

storeWorkflow

public abstract String storeWorkflow()
                              throws DatabaseException
Stores this workflow. Implement this method in all derived classes!

Returns:
The location identifier of the storage location.
Throws:
DatabaseException

getData

public abstract String[] getData(String placeID)
Get specific data that is hold inside the workflow and that is referenced by a data place identifier.

Parameters:
placeID - The place identifier that refers to the data
Returns:
The data as an array of Strings.

getDescription

public abstract String getDescription()
Get the human-readable description of the workflow.

Returns:
A String containing the description.

setDescription

public abstract void setDescription(String description)
Set the human-readable description of the workflow.

Parameters:
description - The description.

run

public abstract void run()
Implement this method for each Class that exends GridJob.

Specified by:
run in interface Runnable
Overrides:
run in class Thread


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