WebSphere Extended Deployment Compute Grid, Version 6.1.1
             Operating Systems: AIX, HP-UX, Linux, Solaris, Windows, z/OS


Developing a simple batch application

This topic describes how to write a simple batch application.

Before you begin

Before starting this task, you must set up your environment. You might need to configure the com.ibm.websphere.ejbcontainer.expandCMPCFJNDIName custom property before developing a Compute Grid batch application. SeeJava virtual machine custom properties for configuration information.

About this task

This sample task assumes that the user is using Rational Application Developer. Other development tools can be used as well.

Procedure

  1. Create a new enterprise application project entitled PostingsSample2.
    1. Add a new Enterprise JavaBeans (EJB) project module. This creates a new Enterprise ARchive (EAR) file and Enterprise EJB project.
    2. Add batchruntime.jar to the Java build path for the PostingsSample2EJB project. The batchruntime.jar is located in the <WAS_HOME>/lib folder.
    3. Assume that there is an existing Java class, AccountOp, which is a Java object that has two public interface methods, creditAccount(..) and debitAccount(..). These methods are called from the batch bean as appropriate. Import this class from the workspace, or write a batch calling class.
  2. Create the BatchStep class. The batch bean is an entity bean that is inherited from an abstract batch step class. Complete the following substeps to create the abstract job step PostingSample2Step:
    1. In the PostingsSample2EJB project, create the abstract Java class, PostingSample2Step , that is inherited from the BatchJobStepInterface.
    2. Add the BatchJobStepInterface.
    3. Make the class abstract.
  3. Create the batch bean. The following substeps describe how to create the batch bean manually. The batch bean reuses the BatchJobStepLocalInterface, the BatchJobStepKey and the BatchJobStepLocalHome classes from the provided programming model. These classes are not recreated. Only the batch bean implementation is generated.
    1. In the PostingSample2EJB project, create a new CMP EJB, entitled PostingsSample2Data.
    2. For the local home interface class, select BatchJobStepLocalHomeInterface.
    3. For the local interface class, select BatchJobStepLocalInterface.
    4. Deselect the Use single key attribute type for the key class.
    5. For the key class, select BatchJobStepKey.
    6. Remove the CMP attribute ID.
    7. In the CMP attribute, add the two CMP attributes, jobID and stepID of type string.
    8. Add jobID as the name, and java.lang.String as the type. Select Key.
    9. Similarly, add stepID, type java.lang.String, and insert this type name to Key field.
    10. Select the BeanSuperclass. Create a matching type of PostingStep2. This action creates the new EJB, but only the EJB bean class is displayed in the projects. The local interface, home interface and the key class are picked up from the programming model-provided classes.
    11. Edit the deployment descriptor. Make the following changes in the ejb-jar.xml file for the PostingSample2Data.
      1. In the Bean tab, edit the CMP connection factory JNDI name to jdbc/lree, and the Container Authorization type to Per_Connection_Factory.
      2. In the Assembly tab, for the container transactions, make all methods of the PostingsSample2Data as Required.
      3. Edit the JNDI name from WebSphere bindings to ejb/com/ibm/ws/batch/sample/PostingsSample2Data.
    12. Save and close the deployment descriptor. As before, add the implementation for the EJB later.
  4. Create the batch job session bean. The batch job is a session bean that is declared in the deployment descriptor, but has no classes generated because the classes are all part of the runtime.
    1. From the ejb-jar.xml file, in the Bean tab, click Add to create the new session EJB, PostingsJob2.
    2. Change Transaction type to bean.
    3. In the Bean class, Remote home interface and Remote interface, type the following strings:
      1. Bean class : com.ibm.ws.batch.BatchJobControllerBean
      2. Remote interface: com.ibm.ws.batch.BatchJobController
      3. Remote home interface: com.ibm.ws.batch.BatchJobControllerHome

      Note that no new class is generated because all the classes exist in the runtime environment. You are only declaring the Job Session bean in the deployment descriptor.

    4. Edit the WebSphere bindings Java Naming and Directory Interface (JNDI) name to ejb/com/ibm/ws/batch/PostingsSample2Job.
    5. Add an EJB reference to the PostingsSample2Job.
    6. Select the PostingsSample2Data bean and add the name ejb/PostingsSample2Data.

      Select the local reference type.

    7. Create the work manager reference.
      1. In the references tab, on the PostingSample2Job bean, click Add. Select Resource Reference, click Next, and provide the following information:
      • Name: wm/BatchWorkManager
      • Type: Select commonj.work.WorkManager
      • Authentication: Container
      • Sharing scope: Shareable
    8. Edit the JNDI name of the wm/BatchWorkManger to wm/default.
    9. Save and close the ejb-jar.xml file.
  5. Create the input batch data stream. There can be zero, 1 or n input and or output streams. In this example, there is one input stream reading from a file and no output stream. Output is written to the console. The batch data stream (BDS) classes are Plain Old Java Object (POJO). To create the input stream, complete the following steps:
    1. Create a new class in the com.ibm.ws.batch.sample package, called PostingsSample2InputStream.
    2. Implement the BatchDataStream interface. This action creates the new PostingSample2Input stream class. You can add the implementations later.
  6. Create Posting2Class to represent a record from the input stream. This class is the object representation of a record in the batch input stream. This is constructed while reading a record from the input BDS, and passed on to the batch bean. This class is like a data or cargo bean that contains attributes and corresponding getters and setters, of the fields in the input stream.
    1. Create a new class named Posting2 that implements the serializable interface. Implementations can be added to this later.
  7. Add implementations to the classes.
    1. Now add implementations to the PostingSample2Data bean, PostingSample2Step and PostingSample2InputStream as in the attached class files. This example is kept simple from a processing standpoint to highlight the steps involved in developing a new batch application. After you add the implementation classes, you can deploy the EJB.



Related concepts
Batch job steps
The batch programming model
Batch controller bean
Task topic    

Terms of Use | Feedback

Last updated: Oct 30, 2009 1:38:02 PM EDT
http://publib.boulder.ibm.com/infocenter/wxdinfo/v6r1m1/index.jsp?topic=/com.ibm.websphere.gridmgr.doc/info/scheduler/tbgridtutorial2.html