com.waveset.task
Class Executor

java.lang.Object
  extended bycom.waveset.task.Executor
Direct Known Subclasses:
ADSyncFailoverTask, ADSyncRecoveryCollectorTask, BaseReportTask, DeferredScanner, DictionaryLoader, ManageServerEncryption, PasswordExpiration, SARunner, SimulateTask, SourceAdapterTask, TestTask, WorkflowExecutor

public abstract class Executor
extends java.lang.Object

The interface which must be implemented by any class that wants to implement a background task and be managed by the TaskManager.

I decided to make this an abstract class rather than an interface so we can maintain a pool chain, and leave it open for other things common to all executors. It also allows us to provide default implementations for suspend and terminate in case a task doesn't support them.


Field Summary
protected  Monitor _monitor
          Monitors task results.
protected  boolean _suspendRequested
          Flag indicating that task suspension has been requested.
protected  boolean _terminateRequested
          Flag indicating that task termination has been requested.
static java.lang.String code_id
           
protected static Trace trace
           
protected static java.lang.String XML_HEADER
           
 
Constructor Summary
Executor()
           
 
Method Summary
protected  void addExtendedResult(TaskContext context, TaskInstance task, int sequence, TaskResult taskResult, java.util.Map options)
          Record an extended result for a task instance.
protected  void delete(TaskContext ctx, TaskInstance task)
          This method is invoked when a TaskInstance object that corresponds to this Executor is deleted.
protected  void doRealWork(TaskContext ctx, TaskInstance task)
           
 void execute(TaskContext ctx, TaskInstance task)
          Execute the task.
 RepositoryResult getExtendedResult(TaskContext context, TaskInstance task, java.util.Map options)
           
 Executor getPool()
          Get the pool pointer.
 boolean isSuspendRequested()
          Test the suspend request flag.
 boolean isTerminateRequested()
          Test the terminate request flag.
protected static void println(java.lang.Object o)
          The usual trace hack.
 void processEvent(TaskEvent ev)
          Handle an extended event - not suspend or terminate
 void setPool(Executor p)
          Set the pool pointer.
 void setSuspendRequested(boolean b)
          Request suspension of the task.
 void setTerminateRequested(boolean b)
          Request termination of the task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

trace

protected static Trace trace

XML_HEADER

protected static final java.lang.String XML_HEADER
See Also:
Constant Field Values

_monitor

protected Monitor _monitor
Monitors task results. GPC: This doesn't really do much yet, but I ask you to please consider it a harmless placeholder for something that may soon be more generally useful.


_suspendRequested

protected boolean _suspendRequested
Flag indicating that task suspension has been requested. This may be set by the Scheduler if it finds an Event object requesting suspension of the task. The Executor is expected to check this periodically with isSuspendRequested() and suspend itself if supports suspension. Since suspension normally requires that we save state in the repository, many Executors will not support suspension. The GUI should use TaskDefinition.isSuspendable() to determine if it should even try to do this.


_terminateRequested

protected boolean _terminateRequested
Flag indicating that task termination has been requested. This may be set by the Scheduler if it finds an Event object requesting termination of the task. The Executor is expected to check this periodically with is TerminateRequested() and terminate itself cleanly. While suspend requests don't have to be obeyed, every Executor should try to support terminate requests.

Constructor Detail

Executor

public Executor()
Method Detail

execute

public void execute(TaskContext ctx,
                    TaskInstance task)
Execute the task. System resources are supplied through the context object. Task options and persistent task state is supplied through the task object. This method provides shell execution logic as a default. A subclass must feel perfectly free to override this logic if any part of the structure seems inappropriate. However, if satisfied with this structure, a subclass need only implement the abstract method doRealWork().

See Also:
doRealWork(TaskContext, TaskInstance)

doRealWork

protected void doRealWork(TaskContext ctx,
                          TaskInstance task)
                   throws java.lang.Exception
Throws:
java.lang.Exception

delete

protected void delete(TaskContext ctx,
                      TaskInstance task)
               throws java.lang.Exception
This method is invoked when a TaskInstance object that corresponds to this Executor is deleted. It can be used to implement task-specific cleanup. The default implementation of this method does nothing.

Throws:
java.lang.Exception

addExtendedResult

protected final void addExtendedResult(TaskContext context,
                                       TaskInstance task,
                                       int sequence,
                                       TaskResult taskResult,
                                       java.util.Map options)
                                throws WavesetException
Record an extended result for a task instance. An extended result is a WavesetResult associated with the task, but stored outside the task instance.

If you need to pass in arguments that specify what the result should be, use name/value pairs in the options map.

Throws:
WavesetException

getExtendedResult

public final RepositoryResult getExtendedResult(TaskContext context,
                                                TaskInstance task,
                                                java.util.Map options)
                                         throws WavesetException
Returns:
task results for the specified task.

The caller may have specified a range of sequence numbers in the map of options. This allows callers to "page" through large results so they can be examined and displayed incrementally.

Throws:
WavesetException
See Also:
TaskResult.FROM_SEQUENCE, TaskResult.TO_SEQUENCE, TaskResult.JUST_LIST_THEM

setSuspendRequested

public void setSuspendRequested(boolean b)
Request suspension of the task. This is only a request, you cann't assume that the task has in fact suspended when the call returns. This normally sets a flag that is tested periodically, and eventually causes the execute() method to terminate.

This differs from terminate in that the intent is that the task store enough state in the task object so that it can be resumed later.


setTerminateRequested

public void setTerminateRequested(boolean b)
Request termination of the task. Similar to suspend except that the intent is that the task will not be resumed later.


isSuspendRequested

public boolean isSuspendRequested()
Test the suspend request flag.


isTerminateRequested

public boolean isTerminateRequested()
Test the terminate request flag.


getPool

public Executor getPool()
Get the pool pointer.


setPool

public void setPool(Executor p)
Set the pool pointer.


processEvent

public void processEvent(TaskEvent ev)
Handle an extended event - not suspend or terminate


println

protected static void println(java.lang.Object o)
The usual trace hack.