ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzamy_5.4.0.1/50/admin/jmxcrt.htm

144 lines
8.5 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!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, &quot;localhost&quot;);
connectProps.setProperty(AdminClient.CONNECTOR_PORT, &quot;8880&quot;);
AdminClient adminClient = null;
try
{
adminClient = AdminClientFactory.createAdminClient(connectProps);
}
catch (ConnectorException e)
{
System.out.println(&quot;Exception creating admin client: &quot; + 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 = &quot;MyNode&quot;;
String query = &quot;WebSphere:type=NodeAgent,node=&quot; + nodeName + &quot;,*&quot;;
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(&quot;Node agent MBean was not found&quot;);
</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 = &quot;launchProcess&quot;;
String signature[] = { &quot;java.lang.String&quot; };
String params[] = { &quot;MyServer&quot; };
try
{
adminClient.invoke(nodeAgent, opName, params, signature);
}
catch (Exception e)
{
System.out.println(&quot;Exception invoking launchProcess: &quot; + 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(&quot;***************************************************&quot;);
System.out.println(&quot;* Notification received at &quot; + new Date().toString());
System.out.println(&quot;* type = &quot; + ntfyObj.getType());
System.out.println(&quot;* message = &quot; + ntfyObj.getMessage());
System.out.println(&quot;* source = &quot; + ntfyObj.getSource());
System.out.println(&quot;* seqNum =
&quot; + Long.toString(ntfyObj.getSequenceNumber()));
System.out.println(&quot;* timeStamp = &quot; + new Date(ntfyObj.getTimeStamp()));
System.out.println(&quot;* userData = &quot; + ntfyObj.getUserData());
System.out.println(&quot;***************************************************&quot;);
}
</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 -Djava.version=1.3 -classpath
/QIBM/ProdData/WebASE/ASE5/lib/admin.jar;/QIBM/ProdData/WebASE/ASE5/lib/wsexception.jar;
/QIBM/ProdData/WebASE/ASE5/lib/jmxc.jar MyAdminClient.java
</pre>
</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/WebASE/ASE5/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>
. $(/usr/bin/dirname $0)/setupCmdLine
TRACE=com.ibm.*=all=disabled TRACEFILE=/home/wasclient/logs/client.log
java ${JAVA_PARM_USER} \
${CONSOLE_ENCODING} \
-Dtrace=$(TRACE) \
-DtraceFile=$(TRACEFILE) \
com.ibm.ws.bootstrap.WSLauncher \
MyAdminClient &quot;$@&quot;
</pre>
</li>
</ol>
</p>
</body>
</html>