WAS v8.5 > Administer applications and their environment > Use the administrative clients > Use administrative programs (JMX)

Deploy and managing a custom Java administrative client program with multiple Java Platform, Enterprise Edition application servers

This section describes how to connect to a Java Platform, Enterprise Edition (Java EE) server, and how to manage multiple vendor servers.

WAS v8.5 completely implements the Java EE Management specification, also known as JSR-77 (Java Specification Requests 77). However, some differences in details between the Java EE specification and the WebSphere Application Server implementation are important for you to understand when we develop a Java administrative client program to manage multiple vendor servers. For information, see the Java Platform, Enterprise Edition (Java EE) Management Specification and the MBean Java API documentation. In this information center, click Reference > Mbean interfaces. When your administrative client program accesses WASs exclusively, we can use the Java APIs and WAS-defined MBeans to manage them. If your program needs to access both WASs and other Java EE servers, use the API defined in the Java EE Management specification.

  1. Connect to a Java EE server.

    Connect to a server by looking up the Management enterprise bean from the JNDI. The Management enterprise bean supplies a remote interface to the MBean server that runs in the application server. The Management enterprise bean works almost exactly like the WAS administrative client, except that it does not provide WAS specific functionality. The following example shows how to look up the Management enterprise bean.

    import javax.management.j2ee.ManagementHome;
    import javax.management.j2ee.Management;
    
    Properties props = new Properties();
    
    props.setProperty(Context.PROVIDER_URL, "iiop://myhost:2809");
    Context ic = new InitialContext(props);
    Object obj = ic.lookup("ejb/mgmt/MEJB");
    ManagementHome mejbHome = (ManagementHome)
            PortableRemoteObject.narrow(obj, ManagementHome.class);
    Management mejb = mejbHome.create();
    The example gets an initial context to an application server by passing the host and port of the Remote Method Invocation (RMI) connector. You must explicitly code the RMI port, in this case 2809. The lookup method looks up the ejb/mgmt/MEJB path, which is the location of the Management enterprise bean home. The example then creates the mejb stateless session bean, which we use in the next step.
  2. Manage multiple vendor application servers.

    After creating the mejb stateless session bean, we can use it to manage the application servers. Components from the application servers appear as MBeans, which the specification defines. These MBeans all have the j2eeType property. This property is one of a set of types the specification defines. All of these types have a set of exposed attributes.

    Use the following example to guide you in managing multiple vendor application servers. The example uses the JVM MBean to determine what the current heap size is for the application server.

    ObjectName jvmQuery = new ObjectName("*:j2eeType=JVM,*");
    Set s = mejb.queryNames(jvmQuery, null);
    ObjectName jvmMBean = (ObjectName) s.iterator().next();
    boolean hasStats = ((Boolean) mejb.getAttribute(jvmMBean,
            "statisticsProvider")).booleanValue();
    if (hasStats) {
        JVMStats stats = (JVMStats) mejb.getAttribute(jvmMBean,
                                                      "stats");
        String[] statisticNames = stats.getStatisticNames();
        if (Arrays.asList(statisticNames).contains("heapSize")) {
            System.out.println("Heap size: " + stats.getHeapSize());
        }}

    The queryNames() method first queries the JVM MBean. The getAttribute method gets the statisticsProvider attribute and determine if this MBean provides statistics. If the MBean does, the example accesses the stats attribute, and then invokes the getHeapSize() method to get the heap size.


Results

The strength of this example is the example can run on any vendor application server. It demonstrates that an MBean can optionally implement defined interfaces, in this case the StatisticsProvider interface. If an MBean implements the StatisticsProvider interface, we can see if an application server supports a particular statistic, in this case the heap size. The specification defines the heap size, although this value is optional. If the application server supports the heap size, we can display the heap size for the JVM.


Related concepts:

Administrative programs for multiple Java Platform, Enterprise Edition application servers


+

Search Tips   |   Advanced Search