BEA Home | Events | Solutions | Partners | Products | Services | Download | Developer Center | WebSUPPORT
JAM Documentation | JAM Scenarios Guide | Previous Topic | Next Topic | Contents | Index

Using JAM in a Clustered Environment

This scenario extends the EJB client model described in the BEA WebLogic Java Adapter for Mainframe Programming Guide to demonstrate a client requesting multiple employee actions against an EJB that is deployed in a cluster. The client holds a remote interface for each EJB on each WebLogic Server in the cluster on which it is deployed. A JAM gateway must be running on each WebLogic Server in the cluster. Each gateway is connected to a CRM running on the same machine or distributed to a different machine. The client is used to make multiple requests to the clustered EJB. The EJB writes a message to the WebLogic Server console, showing the distribution of the client requests.

Action List

To use JAM in a clustered environment, complete the following tasks.

| Your action... | Refer to...
--- | --- | ---
1 | Verify that prerequisite tasks have been completed. | Prerequisites
2 | Prepare your system. | Preparing Your System
3 | Run the sample. | Running the Sample

Prerequisites

Verify that the following prerequisite tasks have been completed.

| Your action... | Refer to...
--- | --- | ---
1 | Verify that the required software has been properly installed: WebLogic Server, WebLogic Java Adapter for Mainframe. | BEA WebLogic Server Getting Started Guide, BEA WebLogic Java Adapter for Mainframe Installation Guide
2 | Verify that the environment and the software components have been properly configured. | BEA WebLogic Server Administration Guide, BEA WebLogic Java Adapter for Mainframe Configuration and Adminstration Guide
3 | Verify the appropriate mainframe application is available. | Your mainframe system administrator

Preparing Your System

Complete the following steps to run the clustering scenario:

1. Add the WebLogic cluster information to the WebLogic Server domain where you will run your cluster samples.

2. Generate the EJB Client sample by following the steps described in the BEA WebLogic Java Adapter for Mainframe Programming Guide.

3. Add the services generated from the client sample to the JAM configuration file for each WebLogic Server in your clustered configuration.

4. Start the JAM gateway under each WebLogic Server. If the WebLogic Server is already started, or the JAM gateway is already running, use the admin servlet to perform the necessary steps. See the "Using JAM Administration Utilities" section of the BEA WebLogic Java Adapter for Mainframe Programming Guide.

Running the Sample

To run the clustering sample provided with the JAM product, complete the following steps.

1. Extend the base example by adding the clusterSampleClientBean to the sample container. The clusterSampleClientBean extends the functions of the SampleClientBean methods readEmployee and newEmployee. These methods will write a line to the WebLogic Server console.

2. The clusterSampleClientBean should be generated and packaged into the sample EJB.

Listing 5-1 clusterSampleClientBean.java

>     // ===========================================================

>     // clusterSampleClientBean.java
>     // Example class that extends a generated JAM client EJB application.
>     //------------------------------------------------------------
>       package sample;
>     // Imports
>       import java.math.BigDecimal;
>       import java.io.IOException;
>       import com.bea.sna.jcrmgw.snaException;
>     // Local imports
>       import sample.EmployeeRecord;
>       import sample.EmployeeRecord.EmpRecord1V;
>       import sample.SampleClientBean;
>     //************************************************************

>     Extends the SampleClientBean EJB class, adding additional business logic.
>     */
>       public class clusterSampleClientBean
>         extends SampleClientBean
>     {
>     // Public functions
>     *****************************************************************
>         * Read an employee record.
>         */
>          public EmployeeRecord readEmployee(EmployeeRecord commarea)
>              throws IOException, snaException
>          {
>              EmployeeRecord  erec = (EmployeeRecord) commarea;
>              try {
>              // Make the remote call.
>                 erec = super.readEmployee(commarea);
>              // Log the results
>                 printEmployee("readEmployee : ", erec);
>              } catch (Exception e) {
>                 log("Read Exception "  + e.toString() + " for "
>                    + erec.getEmpRecord().getEmpName().getEmpNameLast());
>                 throw new IOException();
>              }
>              //  Return the Employee Record
>              return erec;
>          }
>     /**********************************************************

>          * Create a new employee record.
>          */
>          public EmployeeRecord newEmployee(EmployeeRecord commarea)
>              throws IOException, snaException
>          {
>              EmployeeRecord  erec = (EmployeeRecord) commarea;
>              try {
>              // Make the remote call.
>                 erec = super.newEmployee(commarea);
>              // Log the results
>                 printEmployee("newEmployee  : ", erec);
>              } catch (Exception e) {
>                 log("Create Exception " + e.toString() + " for "
>                    + erec.getEmpRecord().getEmpName().getEmpNameLast());
>                 throw new IOException();
>              }
>              //  Return the Employee Record
>              return erec;
>          }
>     // Private Functions
>     /************************************************************
>              * Print the Employee Record
>              */
>              private void printEmployee(String title, EmployeeRecord emp)
>              {
>                  EmpRecord1V empinfo = emp.getEmpRecord();
>                  log(title +
>                     empinfo.getEmpName().getEmpNameFirst() + " " +
>                     empinfo.getEmpName().getEmpNameMi() + " " +
>                     empinfo.getEmpName().getEmpNameLast() + ", " +
>                     empinfo.getEmpAddr().getEmpAddrStreet() + ", " +
>                     empinfo.getEmpAddr().getEmpAddrSt() + " " +
>                     empinfo.getEmpAddr().getEmpAddrZip());
>              }
>             private void log(String s) {
>                     System.out.println(s);
>             }
>          }

3. Change the ejb-jar.xml file to use the extension classes. Change the <ejb-class> to reference clusterSampleClientBean as illustrated in the following example.

>     <enterprise-beans>

>           <session>

>             <ejb-name>SampleClient</ejb-name>

>             <home>sample.SampleClientHome</home>

>             <remote>sample.SampleClient</remote>

>             <ejb-class>sample.clusterSampleClientBean</ejb-class>

>             <session-type>Stateless</session-type>

>             <transaction-type>Container</transaction-type>

>           </session>

4. Deploy the sample to each of the machines in the cluster node by referencing each of the target machines on the EJB deployment list in the WebLogic Server config.xml as illustrated in the following example.

>     <Application Deployed="true" Name="SampleClient" Path=.\config\mydomain\applications">

>     <EJBComponent Name="SampleClient" Targets="mach1,mach2,mach3" URL="SampleClient.jar""/>

>     </Application>

5. Perform a client request against the EJB that is deployed on the cluster. The client will look up the home interface for the clustered EJB and get the remote interface stub for each of the EJBs in the cluster. If you make multiple requests to the EJB, you should see the requests being clustered based on the cluster algorithm you selected under WebLogic Server.

In the example in Listing 5-2, the ClientTest sample is used to make the cluster requests.

Listing 5-2 ClientTest Sample

>     java sample.ClientTest -u "t3://cluster:7001" -c 10 -i 100

The options are in this example are defined in the following way:

  -u option

  specifies the cluster alias and the port number the WebLogic cluster servers are listening on

  -c option

  specifies 10 concurrent requests to be made, each one on its own thread

  -i option

  specifies that 100 requests will be made on each of the concurrent requests

Copyright © 2001 BEA Systems, Inc. All rights reserved. Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.