Technical notes for the BeenThere Sample


Locating source code
Reviewing coding notes


Locating source code

The source code for the BeenThere application is located in the profile_root/samples/src/BeenThere directory, where <profile_root> is the fully qualified path to the deployment manager profile.

z/OS customers: The source code tree for Samples is not provided on the z/OS platform because Sample applications are not built on the z/OS platform.



Reviewing coding notes

Overview

The BeenThere application demonstrates the workload management (WLM) capabilities of IBM WebSphere Application Server Network Deployment Edition. The BeenThere application contains the BeenThere servlet and the BeenThere stateless session enterprise bean. The BeenThere servlet demonstrates the application server in a cluster to which an HTTP request is dispatched. The BeenThere enterprise bean demonstrates the application server in a cluster to which an enterprise bean request was dispatched. The BeenThere enterprise bean is invoked by the BeenThere servlet.

The BeenThere servlet displays the following information:


Additionally, the BeenThere servlet can perform the following actions:


Environment

The Sample environment that is used to demonstrate Web container and EJB container workload management is depicted in the following illustration:



Figure 1   The Sample environment


The machines in this environment include:



The configuration contains two server clusters, MyWebCluster and MyEJBCluster. A server cluster consists of a group of application servers. If one of the member servers fails, requests are routed to other members of the cluster. Each of the Sample clusters are comprised of two cluster members. The cluster MyWebCluster consists of cluster members, WebServer1 and WebServer2, and the cluster MyEJBCluster consists of cluster members, EJBServer1 and EJBServer2.

This configured environment is a Sample that is used just for demonstrating how to run the BeenThere application. In a production environment, careful resource capacity planning must be done to determine how many application server members to create across a particular number of machines, based on the expected client request load.

Workload management

WebSphere Application Server Network Deployment Edition provides workload management (WLM) of HTTP requests and EJB requests.

Web container workload management

Workload management of HTTP requests is handled by the Web server plug-in.

Consider the configuration in Figure 1. The web machine is running an IBM HTTP Server that dispatches HTTP requests to each of the application servers WebServer1 and WebServer2 that comprise the members of the MyWebCluster cluster and are running the BeenThere servlet. These application servers are configured on the app1 and app2 machines, respectively. Furthermore, the IBM HTTP Server plug-in is configured such that WebServer1 has a WLM weight of 2 and WebServer2 has a WLM weight of 3. You can think of the weights as counters that start at their configured value and get decremented by 1 after each request is serviced. Requests get dispatched using a round-robin process to any application server that currently has a weight counter value greater than 0. If the value is 0, the application server is skipped. After all weight counters are decremented to 0, then all application server weight counters are reset to their configured value and the dispatch process starts all over again.

EJB container workload management

Workload management of EJB requests is handled internally by the WLM controller in WebSphere Application Server.

Consider the configuration in Figure 1. A MyEJBCluster cluster is defined that is comprised of the application server members EJBServer1 and EJBServer2 that are responsible for running the BeenThere stateless session enterprise bean. The BeenThere servlet makes a call to the enterprise bean to obtain execution information about the application server in which the enterprise bean is running. Furthermore, these servers are configured with weight values of 1 and 3, respectively.

On the z/OS platform, weight values are used to balance HTTP requests, but are not used to balance Internet Inter-ORB Protocol (IIOP) requests.

WebSphere administrative application programming interfaces

The BeenThere application utilizes the administrative application programming interfaces in WebSphere Application Server. With these interfaces applications can access run-time and environment configuration information:


AdminService

Provides the server-side interfaces to obtain application server attribute information as well as the ability to perform standard JMX MBean management functions.

AdminClient

Provides the client-side interfaces to a remote AdminService object. The AdminClient class provides a proxy to the remote AdminService object through one of the supported Java Management Extensions (JMX) connectors.

ConfigService

Provides interfaces to query or modify configuration data, locally or remotely, and manages the location and the content of application server configuration documents.

To demonstrate the power and flexibility that applications have when using WebSphere Application Server administrative interfaces, the BeenThere application utilizes all of these interfaces in the following ways:


AdminService

The AdminService interface is used by both the BeenThere servlet and the enterprise bean to obtain the node name, application server name, and the process ID for the application server in which they are running. The following code segment demonstrates how to obtain server attribute information:


// Get the WebSphere AdminService.
AdminService adminService = AdminServiceFactory.getAdminService();

// Get the WebSphere Admin Local Server MBean instance.
ObjectName localServer = adminService.getLocalServer();

// Get the Node name.
nodeName = (String) adminService.getAttribute(localServer, "nodeName");

// Get the Application Server name.
serverName = (String) adminService.getAttribute(localServer, "name");

// Get the Application Server Process Id.
serverPid = (String) adminService.getAttribute(localServer, "pid");

AdminClient

The AdminClient interface is used to connect to the deployment manager process to retrieve the cluster member weight values for all the application server members of the cluster running the BeenThere enterprise bean. The following code segment demonstrates how to obtain an instance of the AdminClient interface:


// Get the WebSphere AdminService.
AdminService adminService = AdminServiceFactory.getAdminService();

// Get the AdminClient instance for the Deployment Manager.
adminClient = adminService.getDeploymentManagerAdminClient();

ConfigService

The ConfigService interface is used to read the WebSphere Application Server cell.xml configuration document to determine if the BeenThere application is running in a WebSphere Application Server Base Edition or Network Deployment Edition environment. The following code segment demonstrates how to determine the environment in which an application is running:


// Create a new WebSphere Management Session.
Session session = new Session();

// Get the WebSphere ConfigService instance
// for the application server executing this servlet.
ConfigService configService = ConfigServiceFactory.getConfigService();
if (configService != null)
{
  // Read the cell.xml document.
  ObjectName cellObj = ConfigServiceHelper.createObjectName(null, "Cell");
  ObjectName[] cellObjs = configService.queryConfigObjects(session, null, cellObj, null);

  if (cellObjs.length != 0)
  {
    cellObj = cellObjs[0];
    String cellName = (String) configService.getAttribute(session, cellObj, "name");
    String cellType = (String) configService.getAttribute(session, cellObj, "cellType");
    if (cellType.equals("DISTRIBUTED"))
    {
      websphereND = true;
    }
  }

  // Release the Session.
  configService.discard(session);

If a Network Deployment environment is detected, then the Display bean cluster member weights option is enabled and displayed because this option is only valid in this type of environment. Otherwise, this option is not displayed as a selectable option.