Package com.onenetwork.platform.grid
Interface TaskPerformer
- All Known Implementing Classes:
AbstractTaskPerformer
public interface TaskPerformer
Classes implementing the TaskPerformer interface are created and called by the Grid Dispatcher
to perform a task of the type returned by
getTaskType()
.
A single TaskPerformer object is associated with a single thread. TaskPerformer
implementations do not have to worry about more than one thread accessing a single TaskPerformer
object at a time. A single TaskPerformer object will be used over and over again to process tasks
of the specified task type. If the TaskPerformer keeps any state, it should make sure that the
state is cleared each time performTask is called.
Clients are encouraged to use AbstractTaskPerformer
as the base class for their
TaskPerformer implementations.-
Method Summary
Modifier and Type Method Description void
addToFailTransaction(java.lang.String taskParams, java.lang.String taskInput, java.lang.String reason)
After a result of FAIL, this gives the TaskPerformer the opportunity to perform an action which may update the database.void
addToRetryTransaction(java.lang.String taskParams, java.lang.String taskInput, java.lang.String reason)
After a result of RETRY, this gives the TaskPerformer the opportunity to perform an action which may update the database.TaskPerformerConfig
getTaskPerformerConfig()
Returns the TaskPerformerConfig for this task performer.java.lang.String
getTaskType()
Returns the task type that this TaskPerformer can handleTaskResult
performTask(java.lang.String taskParams, java.lang.String taskInput)
Execute the given task - this represents the "meat" of most TaskPerformer implementations.void
setTaskPerformerConfig(TaskPerformerConfig taskPerformerConfig)
Sets the TaskPerformerConfig on this task performer.
-
Method Details
-
setTaskPerformerConfig
Sets the TaskPerformerConfig on this task performer. This includes any parameterization of the behavior of this performer specified in that configuration- Parameters:
taskPerformerConfig
- configuration for this task performer
-
performTask
Execute the given task - this represents the "meat" of most TaskPerformer implementations. The TaskPerformer should perform its work and return aTaskResult
to indicate the outcome. If this method throws an Exception, a RETRY will automatically be used which wraps the thrown exception.- Parameters:
taskParams
- parameters supplied when task was createdtaskInput
- the output of the task this task depends on- Returns:
- the execution status
-
addToFailTransaction
void addToFailTransaction(java.lang.String taskParams, java.lang.String taskInput, java.lang.String reason)After a result of FAIL, this gives the TaskPerformer the opportunity to perform an action which may update the database. (In a typical failure scenario the transaction is rolled back, thus the need for a separate handler.) Note: This method is also called when a task moves fromFAIL_PENDING
toFAILED
. Currently, implementations can restrict or modify execution by checking the task state in the method usingGridTask.getState()
fromGridTaskContext.getGridTask()
. A state ofTaskState.RUNNING
implies that the method was called through normal execution of the task;TaskState.FAIL_PENDING
implies that it is being run administratively.- Parameters:
taskParams
- parameters supplied when task was createdtaskInput
- the output of the task this task depends onreason
- a description of what caused the task to fail
-
addToRetryTransaction
void addToRetryTransaction(java.lang.String taskParams, java.lang.String taskInput, java.lang.String reason)After a result of RETRY, this gives the TaskPerformer the opportunity to perform an action which may update the database. (In a typical retry scenario the transaction is rolled back, thus the need for a separate handler.)- Parameters:
taskParams
- parameters supplied when task was createdtaskInput
- the output of the task this task depends onreason
- a description of what caused the task to retry
-
getTaskType
java.lang.String getTaskType()Returns the task type that this TaskPerformer can handle- Returns:
- the task type that this TaskPerformer can handle
-
getTaskPerformerConfig
TaskPerformerConfig getTaskPerformerConfig()Returns the TaskPerformerConfig for this task performer. This includes any parameterization of the behavior of this performer specified in that configuration.- Returns:
- TaskPerformerConfig for this task performer
-