|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
com.waveset.task.Scheduler
The background task execution thread.
The scheduler is a singleton thread that periodically checks for task instances in the repository that need attention. This includes ready tasks that can be executed, executing tasks that have run too long, and finished tasks that whose results can be deleted.
Tasks are ordinarily launched in their own thread, but the definition can also request "synchronous" execution, in which case the task will execute in the scheduler's thread. This should be only used for very brief tasks. It is somewhat dangerous and may be removed.
Nested Class Summary | |
static class |
Scheduler.TaskInfo
A helper class we use to maintain information about the tasks currently executing in this JVM. |
static interface |
Scheduler.TaskListener
Classes that want to be notified when tasks complete can implement TaskListener and register with the listener interface. |
Field Summary | |
protected boolean |
_trace
If set, causes debug messages to be displayed on the console. |
static java.lang.String |
CLEANUP_TASK_RESULT_CYCLE
|
static java.lang.String |
CLEANUP_TASK_RESULT_DISABLE
|
static java.lang.String |
CLEANUP_TASK_RESULT_TRACE
|
static java.lang.String |
code_id
|
static int |
DEFAULT_BASE_CYCLE_TIME
Default base cycle time. |
static int |
DEFAULT_FINISHED_CYCLE_TIME
Default finished cycle time. |
static int |
DEFAULT_READY_CYCLE_TIME
Default ready cycle time. |
static int |
DEFAULT_SCHEDULED_CYCLE_TIME
Default scheduled cycle time. |
static int |
DEFAULT_TASK_LIMIT
|
static java.lang.String |
DISABLE_DAEMON
|
static java.lang.String |
DISABLE_FAILOVER
|
static java.lang.String |
DISABLE_SCHEDULED
|
static java.lang.String |
START_DISABLED
|
static java.lang.String |
START_ENABLED
|
static java.lang.String |
START_MANUAL
|
static java.lang.String |
START_SUSPENDED
|
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Fields inherited from interface com.waveset.task.SchedulerMBean |
NAME, OBJECT_NAME, RESUMED, STARTED, STATUS, STOPPED, SUSPENDED |
Method Summary | |
void |
addNotificationListener(javax.management.NotificationListener listener,
javax.management.NotificationFilter filter,
java.lang.Object handback)
|
void |
cleanupOrphanTaskResults()
Find and delete any offspring of deleted TaskInstances. |
static void |
defibrillate()
"Shock" the Scheduler into calling ServerRegistry and picking up a new value for heartbeat interval. |
void |
deleteTaskInstance(java.lang.String taskId,
TaskDefinition taskDef,
TaskInstance ti,
java.lang.String repoUser)
|
void |
deleteTaskInstance(TaskInstance ti,
java.lang.String repoUser)
Public so it can be called by DeleteVisitor. |
void |
deleteTaskInstanceSubObjects(java.lang.String taskId,
TaskDefinition taskDef,
java.lang.String repoUser)
|
void |
deleteTaskInstanceSubObjects(TaskInstance ti,
java.lang.String repoUser)
|
static void |
deRegisterListener(Scheduler.TaskListener tl)
|
TaskInstance |
executeTask(java.lang.String id)
Public method to resume a suspended task and run it now synchronously. |
protected void |
finishExecution(TaskInstance task,
boolean ignoreLockContention)
Cleanup task state after execution has finished. |
int |
getCycles()
The number of second we want to sleep between cycles. |
int |
getErrorCount()
The number of exceptions we've caught during task processing. |
protected Executor |
getExecutor(TaskInstance task)
Find the executor for a task. |
int |
getExpiredCount()
The number of finished tasks we've expired. |
int |
getFinishedCycleCounter()
The number of seconds we've been waiting for a finished cycle. |
int |
getFinishedCycleTime()
The cycle time in seconds for processing FINISHED tasks. |
long |
getLastHeartbeat()
Returns the date of the last heartbeat in ms. |
int |
getLaunchedCount()
The number of scheduled tasks we've launched. |
long |
getMostRecentHeartbeat()
Gets the date of the most recent heartbeat from the scheduler in ms. |
javax.management.MBeanNotificationInfo[] |
getNotificationInfo()
|
int |
getReadyCount()
The number of ready tasks we've executed during the ready cycle. |
int |
getReadyCycleCounter()
The number of seconds we've been waiting for a ready cycle. |
int |
getReadyCycleTime()
The cycle time in seconds for processing READY tasks. |
int |
getScheduledCycleCounter()
The number of seconds we've been waiting for a scheduled cycle. |
int |
getScheduledCycleTime()
The cycle time in seconds for processing SCHEDULED tasks. |
static Scheduler |
getScheduler(LighthouseContext lh)
Get the singleton scheduler. |
int |
getStatus()
Get state as an integer. |
void |
getStatus(java.lang.StringBuffer b)
Return scheduler diagnostic messages. |
java.lang.String |
getStatusDisplay()
Get the state in a displayable string. |
TaskInstance |
launchTask(TaskTemplate tt)
Create a new TaskInstance object and make it ready for execution; This can be called by the TaskManager in response to a call from the Session API. |
protected void |
poolExecutor(Executor e)
Return an executor to the pool. |
static void |
println(java.lang.String msg)
The ususal convenience "macro". |
static void |
registerListener(Scheduler.TaskListener tl)
|
void |
removeNotificationListener(javax.management.NotificationListener listener)
|
void |
removeNotificationListener(javax.management.NotificationListener listener,
javax.management.NotificationFilter filter,
java.lang.Object handback)
|
void |
restoreCycleTimes()
Reset cycle times to their default values. |
void |
resumeScheduler()
Resumes the scheduler after it has been suspended. |
void |
run()
The scheduler main loop. |
void |
runNow()
Can be called by TaskManager in response to a user request to make the scheduler go through a cycle immediately rather than waiting for its next cycle. |
void |
runNow(long waitMillis)
Run the scheduler immediately, and wait for it to finish processing tasks. |
void |
serverConfigurationChanged()
Function called by ServerConfiguration whenever changes are detected. |
void |
setCycleTime(TaskState state,
int seconds)
Sets the cycle time for processing a particular kind of task. |
void |
setTrace(boolean t)
Turn debug tracing on and off. |
static void |
shutdown(boolean wait)
Shuts down the scheduler. |
void |
start()
|
void |
suspendScheduler()
Suspends the scheduler. |
boolean |
tooBusy()
Tests to see if the scheduler on this machine considers itself too busy to handle another task. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String code_id
public static final int DEFAULT_BASE_CYCLE_TIME
public static final int DEFAULT_READY_CYCLE_TIME
public static final int DEFAULT_SCHEDULED_CYCLE_TIME
public static final int DEFAULT_FINISHED_CYCLE_TIME
public static final java.lang.String CLEANUP_TASK_RESULT_CYCLE
public static final java.lang.String CLEANUP_TASK_RESULT_DISABLE
public static final java.lang.String CLEANUP_TASK_RESULT_TRACE
public static final java.lang.String DISABLE_FAILOVER
public static final java.lang.String DISABLE_DAEMON
public static final java.lang.String DISABLE_SCHEDULED
public static final java.lang.String START_ENABLED
public static final java.lang.String START_DISABLED
public static final java.lang.String START_SUSPENDED
public static final java.lang.String START_MANUAL
public static final int DEFAULT_TASK_LIMIT
protected boolean _trace
Method Detail |
public static Scheduler getScheduler(LighthouseContext lh) throws WavesetException
WavesetException
public void serverConfigurationChanged()
serverConfigurationChanged
in interface com.waveset.server.ServerConfiguration.Listener
public static void shutdown(boolean wait)
The thread shutdown methods from 1.x have been deprecated, so we just suggest stopping by setting a flag. This probably isn't necessary if we're a daemon thread.
public void suspendScheduler()
public void resumeScheduler()
public void setTrace(boolean t)
public void setCycleTime(TaskState state, int seconds)
State cycle times should always be greater than the base cycle time, but if it isn't it doesn't hurt, it will behave as if the cycle time is the same as the base cycle.
public void restoreCycleTimes()
public static void println(java.lang.String msg)
public void getStatus(java.lang.StringBuffer b)
public void run()
We wait awhile, and then check for activity.
For test "liveliness", I wanted to use Thread.interrupt here to force the thread out of sleep and make it do a cycle without waiting 5 seconds for the timeout. Unfortunately, I haven't been able to get Thread.interrupt to cause Thread.sleep to throw an InterruptedException. I kludged a workaround that used an primary sleep time of 1 second, and a secondary time that could be greater for processing tasks. This turned out to be useful as we can now have different cycle times for each task type, which will improve performance.
run
in interface java.lang.Runnable
public static void defibrillate() throws WavesetException
WavesetException
ServerRegistry.getHeartBeatIntervalSeconds(com.waveset.object.LighthouseContext)
public long getLastHeartbeat()
public void runNow()
I wanted to just call Thread.interrupt here, but that doesn't seem to break us out of a sleep, explore someday. Added the staggered cycle times instead.
public void runNow(long waitMillis)
waitMillis
- - wait this long. (If -1, wait indefinitely.)public TaskInstance launchTask(TaskTemplate tt) throws TaskExists, PriorTaskResults, WavesetException
Here we just assemble a TaskInstance object, and pass it down to the next launchTask method.
The execution mode may be specified in the template. It is normally ASYNC, but if we're being called directly from a GUI request thread, it may be SYNC or ASYNC_IMMEDIATE.
TaskExists
PriorTaskResults
WavesetException
public boolean tooBusy()
public void deleteTaskInstance(TaskInstance ti, java.lang.String repoUser) throws WavesetException
WavesetException
public void deleteTaskInstance(java.lang.String taskId, TaskDefinition taskDef, TaskInstance ti, java.lang.String repoUser) throws WavesetException
WavesetException
public void deleteTaskInstanceSubObjects(TaskInstance ti, java.lang.String repoUser) throws WavesetException
WavesetException
public void deleteTaskInstanceSubObjects(java.lang.String taskId, TaskDefinition taskDef, java.lang.String repoUser) throws WavesetException
WavesetException
public TaskInstance executeTask(java.lang.String id) throws WavesetException
One common example is when advancing the state of a workflow task immediately after a work item has been saved, which allows us to report the new workflow state immediately, rather than waiting for the scheduler to advance workflow in the background.
We have to obtain locks on the TaskInstance to prevent the scheduler thread from trying to process this object. Note that we have to use a different lock user than the Scheduler thread.
WavesetException
protected Executor getExecutor(TaskInstance task) throws WavesetException
This can throw a host of internal exceptions if we have trouble finding the class. Callers are advised to catch the exceptions, terminate the task, and mark the task definition so that we don't keep trying this over and over again.
Made this public so the TaskManager can obtain one in order to call the new getExtendedResults and getTaskWorkFiles methods.
WavesetException
protected void poolExecutor(Executor e)
protected void finishExecution(TaskInstance task, boolean ignoreLockContention) throws WavesetException
We can get here through various paths. The task will not be in the repository if we performed the execution immediately on the machine that scheduled the task. It will be in the repository if we read it from processTasks, or it was suspended at one time.
In either case, the task will not be locked, so we can lock it now to store results if necessary. If the task is in the repository, and there are no results to retain, we can delete it.
WavesetException
public void cleanupOrphanTaskResults()
It would be better never to produce any orphaned offspring in the first place (they should always be deleted along with the TaskInstance), but this is a reasonable fallback.
public static void registerListener(Scheduler.TaskListener tl)
public static void deRegisterListener(Scheduler.TaskListener tl)
public void start()
public long getMostRecentHeartbeat()
SchedulerMBean
getMostRecentHeartbeat
in interface SchedulerMBean
public int getStatus()
SchedulerMBean
getStatus
in interface SchedulerMBean
public java.lang.String getStatusDisplay()
SchedulerMBean
getStatusDisplay
in interface SchedulerMBean
public int getCycles()
SchedulerMBean
It should be relatively small so we can respond to scheduler control events like changing cycle times, requesting an immediate cycle, shutting down the thread, etc.
getCycles
in interface SchedulerMBean
public int getReadyCount()
SchedulerMBean
getReadyCount
in interface SchedulerMBean
public int getLaunchedCount()
SchedulerMBean
getLaunchedCount
in interface SchedulerMBean
public int getExpiredCount()
SchedulerMBean
getExpiredCount
in interface SchedulerMBean
public int getErrorCount()
SchedulerMBean
getErrorCount
in interface SchedulerMBean
public int getFinishedCycleCounter()
SchedulerMBean
getFinishedCycleCounter
in interface SchedulerMBean
public int getFinishedCycleTime()
SchedulerMBean
getFinishedCycleTime
in interface SchedulerMBean
public int getReadyCycleCounter()
SchedulerMBean
getReadyCycleCounter
in interface SchedulerMBean
public int getReadyCycleTime()
SchedulerMBean
getReadyCycleTime
in interface SchedulerMBean
public int getScheduledCycleCounter()
SchedulerMBean
getScheduledCycleCounter
in interface SchedulerMBean
public int getScheduledCycleTime()
SchedulerMBean
getScheduledCycleTime
in interface SchedulerMBean
public void removeNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback) throws javax.management.ListenerNotFoundException
removeNotificationListener
in interface javax.management.NotificationEmitter
javax.management.ListenerNotFoundException
public void addNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback) throws java.lang.IllegalArgumentException
addNotificationListener
in interface javax.management.NotificationBroadcaster
java.lang.IllegalArgumentException
public javax.management.MBeanNotificationInfo[] getNotificationInfo()
getNotificationInfo
in interface javax.management.NotificationBroadcaster
public void removeNotificationListener(javax.management.NotificationListener listener) throws javax.management.ListenerNotFoundException
removeNotificationListener
in interface javax.management.NotificationBroadcaster
javax.management.ListenerNotFoundException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |