Use this procedure to develop the JobBean class of the HelloJob.
...
1. From the HelloJobProject, open the HelloJobBean.java file.
2. Update the source code as shown in the sample below.
The code excerpt below shows the implementation of a job definition which logs a Hello message.
The MessageDriven annotation declares the bean as a message-driven bean. By using the ActivationConfig element of the of the MessageDrivenannotation, you have to further specify JobDefinition = 'HelloJob' as the message selector and javax.jms.Queue as the destination type.
The message selector has to be in the following format: JobDefinition = ‘<Job name>’
<Job name> has to be identical with the name of the job definition which you specify in the job-definition.xml. It can contain any valid message selector string literal composed of letters, digits, hyphens (-), and underscores ( _ ).
The <Job name>variable does not depend on the name of the JobBean class. By using this mechanism, you can define two different jobs which use the same implementation.
JobBeans have a single business method which is the onJob() method. In JobBeans, the onJob() method replaces the onMessage() method, which is the standard business method of message-driven beans. Jobs inherit from an MDBJobImplementation base class. It provides an implementation of the onMessage() method which is declared as final in the base class.
You must not provide an implementation of the onMessage() method in a JobBean. If you provide an implementation of the onMessage() method, the job definition will not be operational.
package com.sap.scheduler.examples.hellojob;
import java.util.logging.Logger; import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import com.sap.scheduler.runtime.JobContext; import com.sap.scheduler.runtime.mdb.MDBJobImplementation;
@MessageDriven(activationConfig={ @ActivationConfigProperty( propertyName="messageSelector", propertyValue="JobDefinition='HelloJob'"), @ActivationConfigProperty( propertyName="destinationType", propertyValue="javax.jms.Queue")}) public class HelloJobBean extends MDBJobImplementation {
public void onJob(JobContext ctx) {
Logger log = ctx.getLogger(); log.info("Hello "); } } |
The onJob() method takes a JobContext object as its argument which is an instance of the JobContext interface. As a runtime object, a running job obtains a reference to its JobContext and executes with it. Through the JobContext interface a job uses the services of the Scheduler Runtime Service. For more information, see Job Definition.
The HelloJob has to access the Runtime via the JobContext interface to get a logger and write logs.
3. Save the file.
For the reference documentation of the JobContext interface, see the JavaDoc at http://help.sap.com/javadocs/nwce/current/sc/index.html and refer to the com.sap.scheduler.runtime package.
Extending the JobBean Class with Job Parameters