Developing the JobBean Class of the HelloJob

Use

Use this procedure to develop the JobBean class of the HelloJob.

Procedure

  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 MessageDriven annotation, 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 ( _ )

    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.

    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.