public interface Scheduler
Instances of a Scheduler are defined using the administrative console, and located by performing a lookup in the WebSphere JNDI name space. For example:
InitialContext ic = new InitialContext(); Scheduler scheduler = (Scheduler)ic.lookup("java:comp/env/Scheduler");(A resource reference to a scheduler is assumed to be bound to the name 'java:comp/env/Scheduler' here)
Each Scheduler has an associated daemon thread that is responsible for executing
tasks created within it's scope using the Scheduler.create
method.
Once tasks are created, the same application can then use the
task's ID (retrieved from the create method's resulting TaskStatus
)
to cancel, suspend, resume or purge the task.
Since all tasks are persistent, if the application server is restarted, the
daemon for the Scheduler will automatically start and begin executing
the tasks. Likewise, you can continue to lookup tasks previously created and
view their status or alter their state.
Modifier and Type | Method and Description |
---|---|
TaskStatus |
cancel(java.lang.String taskId,
boolean purgeAlso)
Cancels a task.
|
TaskStatus |
create(TaskInfo taskInfo)
Creates a task in the persistent store based upon the data found
in the TaskInfo.
|
BeanTaskInfo |
createBeanTaskInfo()
Deprecated.
Use the
createTaskInfo method. |
MessageTaskInfo |
createMessageTaskInfo()
Deprecated.
Use the
createTaskInfo method. |
java.lang.Object |
createTaskInfo(java.lang.Class taskInfoInterface)
Creates an instance of the specified TaskInfo interface class.
|
java.util.Iterator |
findTasksByName(java.lang.String name)
Finds all TaskInfo records with a specified name that were created
by the caller's application.
|
TaskInfo[] |
findTasksByName(java.lang.String name,
int beginIndex,
int endIndex)
Returns the subset
of TaskInfo records between beginIndex and endIndex
(0-based) that match the specified name and were
created by the caller's application.
|
java.util.Iterator |
findTaskStatusByName(java.lang.String name)
Finds all TaskStatus records which have the specified name and were created
by the caller's application.
|
TaskStatus[] |
findTaskStatusByName(java.lang.String name,
int beginIndex,
int endIndex)
Returns the subset of TaskStatus records between beginIndex and endIndex
that match the specified name and were created by the caller's application.
|
TaskStatus |
getStatus(java.lang.String taskId)
Retrieves the current status of a task.
|
TaskInfo |
getTask(java.lang.String taskId)
Retrieves the current task.
|
TaskStatus |
purge(java.lang.String taskId)
Deletes a completed or cancelled task from the persistent store.
|
TaskStatus |
resume(java.lang.String taskId)
Resumes a suspended task.
|
TaskStatus |
suspend(java.lang.String taskId)
Suspends a task.
|
TaskStatus create(TaskInfo taskInfo) throws TaskInvalid, UserCalendarSpecifierInvalid, UserCalendarInvalid, SchedulerNotAvailableException, UserCalendarPeriodInvalid, NotificationSinkInvalid, NotificationException
TaskStatus.getTaskId
method to retrieve the task id for using with the other methods on the Scheduler
.taskInfo
- information describing the task.TaskStatus
status of the task when created.SchedulerNotAvailableException
- Transaction is rolled-back or marked to roll-back.
Thrown when there was a problem accessing the persistent store.TaskInvalid
- No transaction rollback occurs.
Thrown when the task has invalid parameters.UserCalendarInvalid
- No transaction rollback occurs.
Thrown when the UserCalendar specified is not a valid UserCalendar bean.UserCalendarSpecifierInvalid
- No transaction rollback occurs.
Thrown when the UserCalendar specifier is not valid for the set UserCalendar.UserCalendarPeriodInvalid
- No transaction rollback occurs.
Thrown when the UserCalendar period is not valid for the set UserCalendar.NotificationSinkInvalid
- No transaction rollback occurs.
Thrown when the NotificationSink specified is not a valid NotificationSink bean.NotificationException
- No transaction rollback occurs.
Thrown when the NotificationSink fails to fire due to an exception.BeanTaskInfo
,
MessageTaskInfo
,
TaskStatus.getTaskId()
BeanTaskInfo createBeanTaskInfo()
createTaskInfo
method.createTaskInfo(java.lang.Class)
,
BeanTaskInfo
MessageTaskInfo createMessageTaskInfo()
createTaskInfo
method.createTaskInfo(java.lang.Class)
,
MessageTaskInfo
java.lang.Object createTaskInfo(java.lang.Class taskInfoInterface) throws TaskInfoInvalid
For example:
BeanTaskInfo myTask = (BeanTaskInfo)scheduler.createTaskInfo(BeanTaskInfo.class);
myTask.setTaskHandler(myHandlerHome);
scheduler.create(myTask);
taskInfoInterface
- the interface of the TaskInfo implementation you would like to create.TaskInfoInvalid
- the specified TaskInfo interface class is not available or registered.TaskStatus cancel(java.lang.String taskId, boolean purgeAlso) throws SchedulerNotAvailableException, TaskInvalid, TaskPending, NotificationException
taskId
- The Task ID of the task which is to be canceled.purgeAlso
- Specifies that the task should be purged immediately.TaskStatus
of the task.SchedulerNotAvailableException
- Transaction is rolled-back or marked to roll-back.
Thrown when there was a problem accessing the persistent store.TaskInvalid
- No transaction rollback occurs.
The task id is invalid or has been purged.TaskPending
- No transaction rollback occurs.
Thrown when another thread is currently modifying this row.NotificationException
- No transaction rollback occurs.
Thrown when the NotificationSink fails to fire due to an exception.TaskStatus.getTaskId()
TaskStatus suspend(java.lang.String taskId) throws SchedulerNotAvailableException, TaskInvalid, TaskPending, IllegalTaskState, NotificationException
taskId
- The Task ID of the task to be suspended.TaskStatus
of the task.SchedulerNotAvailableException
- Transaction is rolled-back or marked to roll-back.
Thrown when there was a problem accessing the persistent store.TaskInvalid
- No transaction rollback occurs.
The task id is invalid or has been purged.TaskPending
- No transaction rollback occurs.
Thrown when another thread is currently modifying this row.IllegalTaskState
- No transaction rollback occurs.
The task has been cancelled or completed. Cancelled and completed tasks cannot be suspended.NotificationException
- No transaction rollback occurs.
Thrown when the NotificationSink fails to fire due to an exception.TaskStatus.getTaskId()
TaskStatus resume(java.lang.String taskId) throws SchedulerNotAvailableException, TaskInvalid, TaskPending, IllegalTaskState, NotificationException
When a non-repeating task is resumed and the task fire time has elapsed, it will run immediately. If the fire time did not elapse, it will run at the scheduled time.
When a repeating task is resumed, it will not fire immediately, but at the next scheduled fire time based on the previous scheduled fire time. If a custom UserCalendar is used, the UserCalendar will be called continually until a date greater or equal to the current time is generated.
For example: A task is to run every hour using the SIMPLE calendar. The task's next fire time is 2:05, but was suspended at 1:30. If the task was resumed a week later at 5:30, the task would run at 6:05.
taskId
- The Task ID of the task to be suspended.TaskStatus
of the task.SchedulerNotAvailableException
- Transaction is rolled-back or marked to roll-back.
Thrown when there was a problem accessing the persistent store.TaskInvalid
- No transaction rollback occurs.
The task id is invalid or has been purged.TaskPending
- No transaction rollback occurs.
Thrown when another thread is currently modifying this row.IllegalTaskState
- No transaction rollback occurs.
The task has been cancelled or completed. Only suspended tasks can be resumed.NotificationException
- No transaction rollback occurs.
Thrown when the NotificationSink fails to fire due to an exception.TaskStatus.getTaskId()
TaskStatus purge(java.lang.String taskId) throws SchedulerNotAvailableException, TaskInvalid, TaskPending, IllegalTaskState, NotificationException
taskId
- The ID of the task to be deleted.TaskStatus
of the task.SchedulerNotAvailableException
- Transaction is rolled-back or marked to roll-back.
Thrown when there was a problem accessing the persistent store.TaskInvalid
- No transaction rollback occurs.
The task id is invalid or has been purged.TaskPending
- No transaction rollback occurs.
Thrown when another thread is currently modifying this row.IllegalTaskState
- No transaction rollback occurs.
The task has not been cancelled or completed. Only cancelled or completed tasks can be purged.NotificationException
- No transaction rollback occurs.
Thrown when the NotificationSink fails to fire due to an exception.TaskStatus.getTaskId()
TaskStatus getStatus(java.lang.String taskId) throws SchedulerNotAvailableException, TaskInvalid
taskId
- the Task ID of the task that was assigned when created.TaskStatus
of the task.SchedulerNotAvailableException
- No transaction rollback occurs.
Thrown when there was a problem accessing the persistent store.TaskInvalid
- No transaction rollback occurs.
The task id is invalid or has been purged.TaskStatus.getTaskId()
TaskInfo getTask(java.lang.String taskId) throws SchedulerNotAvailableException, TaskInvalid
taskId
- the Task ID of the task that was assigned when created.TaskInfo
of the task.SchedulerNotAvailableException
- No transaction rollback occurs.
Thrown when there was a problem accessing the persistent store.TaskInvalid
- No transaction rollback occurs.
The task id is invalid or has been purged.TaskStatus.getTaskId()
java.util.Iterator findTasksByName(java.lang.String name) throws SchedulerNotAvailableException
The name can include SQL wildcards (depending on the database platform). Common wildcards include:
A name such as "AR_%" would return all names that begin with "AR_".
name
- the name of the task to be found.SchedulerNotAvailableException
- No transaction rollback occurs.
Thrown when there was a problem accessing the persistent store.java.util.Iterator findTaskStatusByName(java.lang.String name) throws SchedulerNotAvailableException
See the findTasksByName(java.lang.String name)
method for
a more detailed description of the name
parameter.
name
- the name of the task to be found.Scheduler.getStatus
method.SchedulerNotAvailableException
- No transaction rollback occurs.
Thrown when there was a problem accessing the persistent store.TaskInfo[] findTasksByName(java.lang.String name, int beginIndex, int endIndex) throws SchedulerNotAvailableException
Returns the subset of TaskInfo records between beginIndex and endIndex (0-based) that match the specified name and were created by the caller's application.
The name can include SQL wildcards (depending on the database platform). Common wildcards include:A name such as "AR_%" would return all names that begin with "AR_".
name
- the name of the task to be found.beginIndex
- the beginning index of the tasks to
retrieve (0 is the first element)endIndex
- the end index of the tasks to retrieve.
If endIndex is greater than the total number of
tasks, then the endIndex is ignored.SchedulerNotAvailableException
- No transaction rollback occurs.
Thrown when there was a problem accessing
the persistent store.java.lang.IndexOutOfBoundsException
- Thrown when the
beginIndex or endIndex is negative or when
the beginIndex is larger than the endIndex.TaskStatus[] findTaskStatusByName(java.lang.String name, int beginIndex, int endIndex) throws SchedulerNotAvailableException
Returns the subset of TaskStatus records between beginIndex and endIndex that match the specified name and were created by the caller's application.
See thefindTasksByName(java.lang.String name)
method for a more detailed description of the name
parameter.name
- the name of the task to be found.beginIndex
- the beginning index of the tasks
to retrieve (0 is the first element)endIndex
- the end index of the tasks to retrieve.
If endIndex is greater than the total number of
tasks, then the endIndex is ignored.Scheduler.getStatus
method.SchedulerNotAvailableException
- No transaction rollback occurs.
Thrown when there was a problem accessing the
persistent store.