Create custom JMX MBeans. You have some alternatives
to select from, when creating MBeans to extend the WebSphere administrative
system. You can use any existing JMX MBean from another application. You can
register any MBean that you tested in a JMX MBean server outside of the WebSphere
Application Server environment in a WebSphere Application Server process,
including standard MBeans, dynamic MBeans, open MBeans, and model MBeans.
In
addition to any existing JMX MBeans, and ones that were written and tested
outside of the WebSphere Application Server environment, you can use the special
distributed extensions provided by WebSphere and create a WebSphere ExtensionMBean
provider. This alternative provides better integration with all of the distributed
functions of the WebSphere administrative system. An ExtensionMBean provider
implies that you supply an XML file that contains an MBean Descriptor based
on the DTD shipped with the WebSphere Application Server. This descriptor
tells the WebSphere system all of the attributes, operations, and notifications
that your MBean supports. With this information, the WebSphere system can
route remote requests to your MBean and register remote Listeners to receive
your MBean event notifications.
All of the internal WebSphere MBeans
follow the Model MBean pattern. Pure Java classes supply the real logic for
management functions, and the WebSphere MBeanFactory class reads the description
of these functions from the XML MBean Descriptor and creates an instance of
a ModelMBean that matches the descriptor. This ModelMBean instance is bound
to your Java classes and registered with the MBeanServer running in the same
process as your classes. Your Java code now becomes callable from any WebSphere
Application Server administrative client through the ModelMBean created and
registered to represent it.
User
MBeans that run on both the WebSphere Application Server distributed platforms
and the WebSphere Application Server for z/OS platform may require special
coding to function properly in the z/OS multiprocess model. On WebSphere Application
Server distributed platforms where each application server runs in a single
JavaTM Virtual Machine (JVM), there is only one MBean server. The
MBean server controls all MBeans that are registered within that application
server. On the WebSphere Application Server for z/OS platform, there is a
control process and a federation of servant processes, each with their own
MBean server. The control process has its own MBean proxy server to distribute
requests among the servant processes. See the detailed discussion of the JMX MBean multiprocess model request
flow.
Example: The SampleStateMBean
MBean
Use this example to guide you in developing user MBeans that
work for the WebSphere Application Server on both the distributed platforms
and the z/OS platform. The example uses all the special handlers to show its
dynamic proxy MBean responsibilities and capabilities. The SampleStateMBean
example keeps track of its state and generates state change events when it
invokes setter methods.
MBeanDescriptor
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MBean SYSTEM "MbeanDescriptor.dtd">
<MBean type="SampleStateMBean"
aggregationHandlerClass="com.ibm.ws390.sample.SampleStateAggregationHandler"
eventHandlerClass="com.ibm.ws390.sample.SampleStateEventHandler"
invocationHandlerClass="com.ibm.ws390.sample.SampleStateInvocationHandler"
stateObjectClass="com.ibm.ws390.sample.SampleState"
version="6.0"
platform="dynamicproxy"
description="Sample State MBean for the documentation example.">
<attribute description="The name of the MBean."
getMethod="getMBeanName" name="mbeanName" type="java.lang.String"
proxyInvokeType="unicall"/>
<attribute description="The state of the MBean." name="state"
getMethod="getState" setMethod="setState" type="java.lang.String"
proxyInvokeType="multicall" proxySetterInvokeType="multicall"/>
<operation
description="Initialize the State MBean."
impact="ACTION" name="initializeState" role="operation"
targetObjectType="objectReference" type="void" proxyInvokeType="multicall">
<signature>
<parameter description="The name of the MBean."
name="mbeanName" type="java.lang.String"/>
<parameter description="The initial state of the MBean."
name="mbeanName" type="java.lang.String"/>
</signature>
</operation>
<notification name="j2ee.state.starting" severity="6" log="false"
description="This sample state MBean is in starting state.">
<notificationType>j2ee.state.starting</notificationType>
</notification>
<notification name="j2ee.state.running" severity="6" log="false"
description="This sample state MBean is in running state.">
<notificationType>j2ee.state.running</notificationType>
</notification>
<notification name="j2ee.state.stopping" severity="6" log="false"
description="This sample state MBean is in stopping state.">
<notificationType>j2ee.state.stopping</notificationType>
</notification>
<notification name="j2ee.state.stopped" severity="6" log="false"
description="This sample state MBean is in stopped state.">
<notificationType>j2ee.state.stopped</notificationType>
</notification>
</MBean>
SampleState implementation
package com.ibm.ws390.sample;
import com.ibm.ejs.ras.Tr;
import com.ibm.ejs.ras.TraceComponent;
import java.io.Serializable;
import com.ibm.websphere.management.dynamicproxy.StateObject;
public class SampleState extends StateObject {
private static TraceComponent tc =
Tr.register(SampleState.class,"SampleState",null);
// Package protected STATE constants.
static final String STATE_STARTING = "j2ee.state.starting";
static final String STATE_RUNNING = "j2ee.state.running";
static final String STATE_STOPPING = "j2ee.state.stopping";
static final String STATE_STOPPED = "j2ee.state.stopped";
// Dynamicproxy State is initialized with STOPPED state.
private String state = STATE_STOPPED;
public SampleState() {
if (tc.isEntryEnabled()) Tr.entry(tc,"<init>");
// State is initialized during "state" initialization above,
// but can also be initialized here in the constructor as well.
/*
state = "WebSphere Application Server for z/OS ready for e-business";
*/
if (tc.isEntryEnabled()) Tr.exit(tc,"<init>");
}
public synchronized String getState() {
if (tc.isEntryEnabled()) Tr.entry(tc,"getState");
if (tc.isEntryEnabled()) Tr.exit(tc,"getState",state);
return state;
}
public synchronized void setState(String state) {
if (tc.isEntryEnabled()) Tr.entry(tc,"setState",state);
this.state = state;
if (tc.isEntryEnabled()) Tr.exit(tc,"setState");
}
public synchronized String getStateObjectInfo() {
return state;
}
}