Receiving scheduler notifications
Overview
Various notification events are generated by a scheduler when it performs an operation on a task. These events include:
- Scheduled
- A task has been scheduled.
- Purged
- A task has been permanently deleted from the persistent store.
- Suspended
- A task was suspended.
- Resumed
- A task was resumed.
- Complete
- A task has run completely. If it was a repeating task, all repeats have been performed.
- Cancelled
- A task has been cancelled. It will not run again.
- Firing
- A task is prepared to run.
- Fired
- A task completed successfully.
- Fire failed
- A task could not run successfully.
To receive notification events, call the setNotificationSink() method on the TaskInfo interface before creating the task. The setNotificationSink() method enables you to specify the session bean that is to act as the callback, and a mask that restricts which events are generated.
Procedure
- Create a NotificationSink session bean. Create a stateless session bean that implements the handleEvent() method in the com.ibm.websphere.scheduler.NotificationSink remote interface. The handleEvent() method is called when the notification is fired. The Home and Remote interfaces can be set as follows in the bean's deployment descriptor:
com.ibm.websphere.scheduler.NotificationSinkHome com.ibm.websphere.scheduler.NotificationSinkThe NotificationSink interface defines the following method:
public void handleEvent(TaskNotificationInfo task) throws java.rmi.RemoteException;- Specify the notification sink session bean prior to submitting the task to the Scheduler using the TaskInfo interface API setNotificationSink() method.
If using the WASScheduler MBean API to set the notification sink, then the JNDI name must be the fully-qualified global JNDI name. Using a JavaServer Pages (JSP) file, servlet or EJB component, look up and set the notification sink on a task as shown in the following code example
We can also use the wsadmin tool to set the notification sink callback session bean as shown in the following JACL scripting exampleTaskInfo taskInfo = ... Object o = new InitialContext().lookup("java:comp/env/ejb/NotificationSink"); NotificationSinkHome home = (NotificationSinkHome )javax.rmi.PortableRemoteObject.narrow(o,NotificationSinkHome.class); taskInfo.setNotificationSink(home,TaskNotificationInfo.ALL_EVENTS);# Use the NotificationSinkHome’s Global JNDI name # Assume that a TaskInfo was already created... $taskInfo setNotificationSink “ejb/MyNotificationSink”- Specify the event mask. The event mask is specified as an integer bitmap. We can either use an individual mask such as TaskNotificationInfo.CREATED to receive specific events, TaskNotificationInfo.ALL_EVENTS to receive all events or a combination of specific events. If you use Java, your script might look like the following example
If you use JACL, your script might look like the following exampleint eventMask = TaskNotificationInfo.FIRED | TaskNotificationInfo.COMPLETE; taskInfo.setNotificationSink(home,eventMask);# Set the event mask based on two event constants. set eventmask [expr [java::field com.ibm.websphere.scheduler.TaskNotificationInfo FIRED] + [java::field com.ibm.websphere.scheduler.TaskNotificationInfo COMPLETE]] # Set our Notification Sink based on our global JNDI name AND event mask. #Note: We need to use the full method signature here since the # method resolver can’t always detect the right method. $taskInfo {setNotificationSink String int} "ejb/MyNotificationSink" $eventmask
Result
A notification sink bean is now set on a TaskInfo object and can now be submitted to a scheduler using the create method.
Related Tasks
Developing a task that calls a session bean
Developing a task that sends a Java Message Service message
Manage tasks with a scheduler
Manage schedulers
See Also
Scheduler interface