com.waveset.task
Class TaskManager

java.lang.Object
  extended bycom.waveset.task.TaskManager

public class TaskManager
extends java.lang.Object

The Waveset Task Manager.

There is ordinarilly one task manager object created by the Server as part of server initialization. The task manager provides the internal API for task operations, some of which is exposed through the Session interface.

The task manager will launch a singleton Scheduler thread object. You could in theory have more than one TaskManager, though there will be only one Scheduler.


Field Summary
static java.lang.String code_id
           
 
Constructor Summary
TaskManager(LighthouseContext lh)
          Build a new TaskManager supplying handles to system resources we need.
 
Method Summary
static Event buildEvent(java.lang.String taskId, TaskState state, java.lang.String user)
          Static utility method to build a suitable event object.
static Event buildEvent(java.lang.String taskId, TaskState state, java.lang.String user, GenericObject attributes)
           
 void deleteTask(java.lang.String taskId, java.lang.String user)
          Deletes a task.
 void deleteTaskInstance(TaskInstance ti, java.lang.String repoUser)
           
 TaskInstance executeTask(java.lang.String id)
          Execute a suspended (or ready) task now synchronously.
 RepositoryResult getExtendedResult(java.lang.String taskId, java.util.Map options)
          Retrieves all extended results for a task.
 void getStatus(java.lang.StringBuffer b)
          Return interesting status.
 java.util.List getTaskDefinitions()
          Get a list of all known task definitions.
 TaskInstance getTaskInstance(java.lang.String defName, java.lang.String nameOrId)
          Return the task instance associated with this name.
 QueryResult getTaskInstances(TaskState state, java.lang.String owner, java.lang.String defName)
          Get the set of task instances.
 TaskInstance launchTask(TaskTemplate tmp)
          Launch a task.
 void postEvent(java.lang.String taskId, TaskState state, java.lang.String user)
          Post a task evnt.
 void postEvent(java.lang.String taskId, TaskState state, java.lang.String user, GenericObject attrs)
           
 void restoreSchedulerCycleTimes()
          Restores the scheduler cycle times to their defaults.
 void resumeTask(java.lang.String taskId, java.lang.String user)
          Resume a task.
 void runScheduler()
          Request that the scheduler go through a cycle immediately.
 void runScheduler(long waitMillis)
          Request that the scheduler go through a cycle immediately and wait for the scheduler to finish processing tasks.
 void setSchedulerCycleTime(TaskState state, int seconds)
          Set the scheduler cycle time for a particular task state.
 void setTrace(boolean trace)
          Turn on the debug trace flag.
static void shutdown()
          Shut down the task manager, freeing any resources we have accumualted.
 void startScheduler()
          Resume the scheduler if it is not already running.
 void stopScheduler()
          Stop the scheduler thread if it is running.
 void suspendTask(java.lang.String taskId, java.lang.String user)
          Suspend a task.
 void terminateTask(java.lang.String taskId, java.lang.String user)
          Terminates a 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
Constructor Detail

TaskManager

public TaskManager(LighthouseContext lh)
            throws WavesetException
Build a new TaskManager supplying handles to system resources we need. These objects usually come from the singleton Server object, but we don't want to introduce a dependency on that object here.

Method Detail

shutdown

public static void shutdown()
Shut down the task manager, freeing any resources we have accumualted. Typically called by the Server object when we're in the process of shutting down the entire server. This needs to block until the scheduler thread is shutdown because the next thing that happens is the repository is shut down and that should not happen under the scheduler...


startScheduler

public void startScheduler()
                    throws WavesetException
Resume the scheduler if it is not already running.

Throws:
WavesetException

stopScheduler

public void stopScheduler()
                   throws WavesetException
Stop the scheduler thread if it is running. We'll just put it in suspend mode the thread will still be active.

Throws:
WavesetException

runScheduler

public void runScheduler()
                  throws WavesetException
Request that the scheduler go through a cycle immediately.

Throws:
WavesetException

runScheduler

public void runScheduler(long waitMillis)
                  throws WavesetException
Request that the scheduler go through a cycle immediately and wait for the scheduler to finish processing tasks.

Parameters:
waitMillis - - wait this long. (If -1, wait indefinitely.)
Throws:
WavesetException

setSchedulerCycleTime

public void setSchedulerCycleTime(TaskState state,
                                  int seconds)
Set the scheduler cycle time for a particular task state. This might be used in test situations to crank it down for faster response.


restoreSchedulerCycleTimes

public void restoreSchedulerCycleTimes()
Restores the scheduler cycle times to their defaults. Usually called after tests that turn down cycle times in order to run faster.


getTaskDefinitions

public java.util.List getTaskDefinitions()
                                  throws WavesetException
Get a list of all known task definitions. The list will not be filtered for authorization. This will be exposed through the Session interface which will perform authorization.

At the moment, this is just a simple repository access, but we encapsulated it here in case we wanted to support definitions that were stored under more than one Type. I hope we don't evolve that way, if so, we could eliminate this and just use the generic object interface.

We'll use the cache so we have to return a List rather than a RepositoryResult.

Throws:
WavesetException

getTaskInstances

public QueryResult getTaskInstances(TaskState state,
                                    java.lang.String owner,
                                    java.lang.String defName)
                             throws WavesetException
Get the set of task instances. We won't use the cache for these, since they're more dynamic and possibly numerous.

Like TaskDefinition, we have our own accessor so we can encapsulate the repository types that are used to assemble the list. This wouldn't be necessary if we cound ensure that all TaskInstance subclasses forced themeslves into the Type.TASK_INSTANCE table. Think..

Since we're using the repository not the cache, its more convenient to return QueryResult, thought that's now inconsistent with getTaskDefinitions.

Throws:
WavesetException

getTaskInstance

public TaskInstance getTaskInstance(java.lang.String defName,
                                    java.lang.String nameOrId)
                             throws WavesetException
Return the task instance associated with this name.

Parameters:
defName - - the definition in case we implement namespaces
nameOrId - - the name of the task
Returns:
the task instance found, or null if none found
Throws:
WavesetException

launchTask

public TaskInstance launchTask(TaskTemplate tmp)
                        throws WavesetException
Launch a task. We just forward it to the Scheduler, but I'm trying to keep that hidden from the outside world. We assume ownership of the TaskTemplate and can trash it as we like.

Throws:
WavesetException

executeTask

public TaskInstance executeTask(java.lang.String id)
                         throws WavesetException
Execute a suspended (or ready) task now synchronously.

Throws:
WavesetException

postEvent

public void postEvent(java.lang.String taskId,
                      TaskState state,
                      java.lang.String user)
               throws WavesetException
Post a task evnt.

Throws:
WavesetException

postEvent

public void postEvent(java.lang.String taskId,
                      TaskState state,
                      java.lang.String user,
                      GenericObject attrs)
               throws WavesetException
Throws:
WavesetException

buildEvent

public static Event buildEvent(java.lang.String taskId,
                               TaskState state,
                               java.lang.String user)
                        throws WavesetException
Static utility method to build a suitable event object.

Throws:
WavesetException

buildEvent

public static Event buildEvent(java.lang.String taskId,
                               TaskState state,
                               java.lang.String user,
                               GenericObject attributes)
                        throws WavesetException
Throws:
WavesetException

suspendTask

public void suspendTask(java.lang.String taskId,
                        java.lang.String user)
                 throws WavesetException
Suspend a task. This may not always be supported.

Throws:
WavesetException

resumeTask

public void resumeTask(java.lang.String taskId,
                       java.lang.String user)
                throws WavesetException
Resume a task.

Throws:
WavesetException

terminateTask

public void terminateTask(java.lang.String taskId,
                          java.lang.String user)
                   throws WavesetException
Terminates a task.

Throws:
WavesetException

deleteTask

public void deleteTask(java.lang.String taskId,
                       java.lang.String user)
                throws WavesetException
Deletes a task.

If it is running we first must terminate it? Hmm, could dance around with locks here, it seems sufficient to just delete it out from under the scheduler (after attempting to notify it) and having the scheduler handle that.

Throws:
WavesetException

deleteTaskInstance

public void deleteTaskInstance(TaskInstance ti,
                               java.lang.String repoUser)
                        throws WavesetException
Throws:
WavesetException

getExtendedResult

public RepositoryResult getExtendedResult(java.lang.String taskId,
                                          java.util.Map options)
                                   throws WavesetException
Retrieves all extended results for a task. The task is identified by id, internally we manufacture an Executor for that task, and ask it to obtain the result.

Throws:
WavesetException

setTrace

public void setTrace(boolean trace)
              throws WavesetException
Turn on the debug trace flag. We just forward it along to the scheduler.

Throws:
WavesetException

getStatus

public void getStatus(java.lang.StringBuffer b)
Return interesting status. This is expected to be called by someone assembling a Report document, we contribute one or more
elements.