141 lines
9.0 KiB
HTML
141 lines
9.0 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
|
|
|
|
<title>Customize using JMX</title>
|
|
</head>
|
|
|
|
<BODY>
|
|
<!-- Java sync-link -->
|
|
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
|
|
|
|
<h4><a name="jmxcrt"></a>Customize using JMX</h4>
|
|
|
|
<p>Your application or operating environment may have management features that are not accessible in the provided WebSphere Application Server - Express administration facilities. You can incorporate WebSphere Application Server - Express administration into other Java programs by using the Java administrative APIs. Alternatively, you can use the administrative classes and methods to add newly managed objects to WebSphere Application Server - Express administration.</p>
|
|
|
|
<p>Perform the following steps to develop a Java program using the WebSphere Application Server - Express administrative APIs to access WebSphere Application Server - Express administration:</p>
|
|
<p>
|
|
<ol>
|
|
<li><p><strong>Develop an administrative client program</strong>.</p>
|
|
<p>
|
|
<ol type="a">
|
|
<li><p>Create an AdminClient instance.</p>
|
|
<p>An administrative client program needs to invoke methods on the AdminService object. The AdminClient resides in the application server. The AdminClass class contains interfaces defined in the JMX javax.management.MBeanServer interface. See <a href="apidocs/jmx/javax/management/MBeanServer.html">Interface MBeanServer</a> <img src="api.gif" width="18" height="15" alt="Link to API documentation"> for more information.</p>
|
|
|
|
<p>The following example shows how to create an AdminClient instance that uses the SOAP connector to interface with the AdminService that runs in the application server:</p>
|
|
|
|
<pre>
|
|
Properties connectProps = new Properties();
|
|
connectProps.setProperty
|
|
(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
|
|
|
|
connectProps.setProperty(AdminClient.CONNECTOR_HOST, "localhost");
|
|
connectProps.setProperty(AdminClient.CONNECTOR_PORT, "8880");
|
|
AdminClient adminClient = null;
|
|
try
|
|
{
|
|
adminClient = AdminClientFactory.createAdminClient(connectProps);
|
|
}
|
|
catch (ConnectorException e)
|
|
{
|
|
System.out.println("Exception creating admin client: " + e);
|
|
}
|
|
</pre>
|
|
</li>
|
|
|
|
<li><p>Find an MBean.</p>
|
|
<p>After you obtain an AdminClient instance, you can use it to access managed resources in an application server. Each managed resource registers an MBean with the AdminService through which you can access the resource. The MBean is represented by an ObjectName instance that identifies the MBean. An ObjectName consists of a domain name followed by an unordered set of one or more key properties. For WebSphere Application Server - Express, the domain name is WebSphere and the key properties defined for administration are as follows:</p>
|
|
<ul>
|
|
<li>type: The type of MBean. For example: Server, TraceService, JVM. See <a href="apidocs/mbean/index.html">Public MBean Interfaces</a> <img src="api.gif" width="18" height="15" alt="Link to API documentation"> for a list of available MBeans.</li>
|
|
<li>name: The name identifier for the individual instance of the MBean.</li>
|
|
<li>cell: The name of the cell in which the MBean is running.</li>
|
|
<li>node: The name of the node in which the MBean is running.</li>
|
|
<li>process: The name of the process in which the MBean is running.</li>
|
|
</ul>
|
|
|
|
<p>You can locate MBeans by querying for them with ObjectNames that match desired key properties. The following example shows how to find the MBean for the NodeAgent of node MyNode:</p>
|
|
<pre>
|
|
String nodeName = "MyNode";
|
|
String query = "WebSphere:type=NodeAgent,node=" + nodeName + ",*";
|
|
ObjectName queryName = new ObjectName(query);
|
|
ObjectName nodeAgent = null;
|
|
Set s = adminClient.queryNames(queryName, null);
|
|
if (!s.isEmpty())
|
|
nodeAgent = (ObjectName)s.iterator().next();
|
|
else
|
|
System.out.println("Node agent MBean was not found");
|
|
</pre>
|
|
</li>
|
|
<li><p>Use the MBean.</p>
|
|
<p>What a particular MBean allows you to do depends on that MBean's management interface. It may declare attributes that you can obtain or set. It may declare operations that you can invoke. It may declare notifications for which you can register listeners. For a list of available MBeans, see <a href="apidocs/mbean/index.html">Public MBean Interfaces</a> <img src="api.gif" width="18" height="15" alt="Link to API documentation">.</p>
|
|
<p>The following example invokes one of the operations available on the NodeAgent MBean that was located above. The following example starts the MyServer application server:</p>
|
|
<pre>
|
|
String opName = "launchProcess";
|
|
String signature[] = { "java.lang.String" };
|
|
String params[] = { "MyServer" };
|
|
try
|
|
{
|
|
adminClient.invoke(nodeAgent, opName, params, signature);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
System.out.println("Exception invoking launchProcess: " + e);
|
|
}
|
|
</pre>
|
|
</li>
|
|
<li><p>Register for events.</p>
|
|
<p>In addition to managing resources, the JMX APIs also support application monitoring for specific administrative events. Refer to the <a href="apidocs/jmx/index.html">JMX javadoc</a> <img src="api.gif" width="18" height="15" alt="Link to API documentation"> for more information on the JMX APIsl. For example, certain events produce notifications when a server starts. Administrative applications can register as listeners for these notifications. WebSphere Application Server - Express provides a full implementation of the JMX notification model and provides additional function so you can receive notifications in a distributed environment.</p>
|
|
<p>The following is an example of how an object can register itself for event notifications emitted from an MBean using the node agent ObjectName:</p>
|
|
<pre>
|
|
adminClient.addNotificationListener(nodeAgent, this, null, null);
|
|
</pre>
|
|
<p>In this example, the null value results in receiving all of the node agent MBean event notifications. You can also use the null value with the handback object.</p>
|
|
</li>
|
|
<li><p>Handle the events.</p>
|
|
<p>Objects receive JMX event notifications via the handleNotification method, which is defined by the NotificationListener interface, and any event receiver must implement. For details on the JMX javax.management.NotificationListener interface, see <a href="apidocs/jmx/javax/management/NotificationListener.html">Interface NotificationListener</a> <img src="api.gif" width="18" height="15" alt="Link to API documentation">.</p>
|
|
|
|
<p>The following example is an implementation of handleNotification that reports the notifications that it receives:</p>
|
|
<pre>
|
|
public void handleNotification(Notification n, Object handback)
|
|
{
|
|
System.out.println("***************************************************");
|
|
System.out.println("* Notification received at " + new Date().toString());
|
|
System.out.println("* type = " + ntfyObj.getType());
|
|
System.out.println("* message = " + ntfyObj.getMessage());
|
|
System.out.println("* source = " + ntfyObj.getSource());
|
|
System.out.println("* seqNum =
|
|
" + Long.toString(ntfyObj.getSequenceNumber()));
|
|
System.out.println("* timeStamp = " + new Date(ntfyObj.getTimeStamp()));
|
|
System.out.println("* userData = " + ntfyObj.getUserData());
|
|
System.out.println("***************************************************");
|
|
}
|
|
</pre>
|
|
</li></ol></p></li>
|
|
<li><p><strong>Build the administrative client program</strong> by compiling it with javac and providing the location of the necessary JAR files in the class path argument.</p>
|
|
<p>This is an example of a typical command:</p>
|
|
<pre>
|
|
javac -classpath /QIBM/ProdData/WebASE51/ASE/lib/admin.jar:
|
|
/QIBM/ProdData/WebASE51/ASE/lib/jmxc.jar:
|
|
/QIBM/ProdData/WebASE51/ASE/lib/wsexception.jar
|
|
-J-Djava.version=1.4 -d . AdminClientExample.java
|
|
</pre>
|
|
<p><strong>Note:</strong> This command is wrapped for display purposes. Enter the command on a single line.</p></li>
|
|
<li><p><strong>Run the administrative client program</strong> by setting up the runtime environment so that the program can find all of the necessary requirements.</p>
|
|
|
|
<p>You can use the /QIBM/ProdData/WebASE51/ASE/bin/setupCmdLine script to set up the environment. This example batch file invokes the setupCmdLine script and runs an administrative client program named MyAdminClient:</p>
|
|
|
|
<pre>
|
|
. /qibm/proddata/webase51/ase/bin/setupCmdLine -instance <em>instance-name</em>
|
|
TRACE=com.ibm.*=all=disabled TRACEFILE=/home/wasclient/logs/client.log
|
|
java ${JAVA_PARM} ${CONSOLE_ENCODING} -Dtrace=${TRACE} -DtraceFile=${TRACEFILE}
|
|
-classpath /home/myDir:${WAS_CLASSPATH}:${WAS_INSTALL_ROOT}/lib/admin.jar:
|
|
${WAS_INSTALL_ROOT}/lib/wasjmx.jar AdminClientExample
|
|
</pre>
|
|
<p><strong>Note:</strong> This command is wrapped for display purposes. Enter the command on a single line.</p></li>
|
|
</ol>
|
|
</p>
|
|
|
|
</body>
|
|
</html> |