Creating the task API event handler
Follow these steps to create the task API event handler:
- Create a Java project and add the Process Server runtime library to it. The tutorial creates the Java project Task Event Handler.
- Create an optional, but recommended, Java package in the src folder. If the package is not created, the default package is used (as is done in the tutorial).
- Create a Java class that extends the com.ibm.task.spi.APIEventHandler class. You have the option to create a handler that implements the APIEventHandlerPlugin5 interface. However, extending the APIEventHandler class is recommended because if there is any future change in the task API with future product releases, APIEventHandler of the new release will provide a default (do nothing) implementation of the various declared methods in the APIEventHandlerPlugin5 interface or potentially other interfaces.
- Override the appropriate methods of the APIEventHandler class. Which method is overridden depends on the business requirements. The tutorial overrides the preCreateTask and postCreateTask methods.
Listing 1 shows the preCreateTask method of
the TaskEventHandler plug-in.
Listing 1. The preCreateTask method
public void preCreateTask(TaskModel newTaskModel, TaskTemplate template,
Serializable inputMessage, ReplyHandler replyHandler) throws ApplicationVetoException {
ServiceManager serviceManager = new ServiceManager();
Service myService = (Service) serviceManager.locateService("MyServiceIntPartner");
myService.invoke("getIt", "preCreateTask method is executed.");
} |
This is a simple implementation of the preCreateTask method. The task container of Process Server executes this method in the context of the Java EE application that represents the logic implemented in the MyProcess SCA project before the task is created. This implementation shows how to invoke a service that is located in the MyService SCA module, which is a different SCA module from MyProcess. To invoke the service in the MyService module, the preCreateTask method:
- Gets a reference to the singleton service ServiceManager as shown
in the
ServiceManager serviceManager… line. - Looks up the service MyServiceIntPartner as shown in the
Service myService… line. MyServiceIntPartner is the service reference that points to the Java component exposed as an SCA service in the MyService project. - Invokes the method getIt of the MyServiceIntPartner service
reference as shown in the
myService.invoke… line.
The task API event handler TaskEventHandler is configured as a Java EE service provider. To configure it, follow these steps:
- Create the META-INF/services folder in the root of the Task Event Handler project.
- Create a text file called
com.ibm.task.spi.plug-inNameAPIEventHandlerPlugin
in the META-INF/services folder. Replace
plug-inNamewith an arbitrary text that may appropriately be your event handler class name. For the tutorial, the event handler class name isTaskEventHandler. - Type the fully qualified name of the plug-in name
(
package.name) in the first line of the text file. For the tutorial, the default package is used. So, the first line in the text file isTaskEventHandler. - Save the text file com.ibm.task.spi.plug-inNameAPIEventHandlerPlugin.




