User: andreas
Date: 00/09/09 21:45:57
Modified: . JMX.Connector.Howto.html
Log:
Add example code and fixed typos
Revision Changes Path
1.2 +143 -14 jbossweb/JMX.Connector.Howto.html
Index: JMX.Connector.Howto.html
===================================================================
RCS file: /products/cvs/ejboss/jbossweb/JMX.Connector.Howto.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JMX.Connector.Howto.html 2000/09/10 03:34:21 1.1
+++ JMX.Connector.Howto.html 2000/09/10 04:45:56 1.2
@@ -20,6 +20,15 @@
margin-right:o.5in;
background-color:white;
}
+DIV.code {
+ font:normal 9pt 'courier new', monospaced;
+ margin-left:0.5in;
+ padding-left:0.25in;
+ margin-right:0.5in;
+ border:none 1px;
+ background-color:lightblue;
+ white-space:pre;
+}
DIV.footer {
font:normal 12pt 'times new roman',serif;
margin-left:0.1in;
@@ -48,6 +57,16 @@
font-weight:bold;
background-color:lightcoral;
}
+PRE.code {
+ font:normal 9pt 'courier new', monospaced;
+ margin-left:0.5in;
+ padding-left:0.25in;
+ margin-right:0.5in;
+ margin-top:0in;
+ margin-bottom:0in;
+ border:none 1px;
+ background-color:lightblue;
+}
H1 {
font-size:28pt;
text-align:center;
@@ -90,10 +109,10 @@
</LI>
<LI>
JMX Agent which contains a MBean Server, certain services like dynamic download,
timers,
-releations etc. and at least one Connector or Adaptor.
+relations etc. and at least one Connector or Adaptor.
</LI>
<LI>
-Management Tool usings a Connector or Adaptor to manage the components of the JMX
Agent
+Management Tool using a Connector or Adaptor to manage the components of the JMX
Agent
the tool is connected to.
</LI>
</OL>
@@ -136,7 +155,7 @@
comfortable than the HTML Adaptor.
</DIV>
<DIV class="para" ALIGN="left">
-By the way I will take this opportunity to thanks Rickard Oeberg for his support.
+By the way I will take this opportunity to thanks Rickard Öberg for his
support.
</DIV>
<H3>Goals</H3>
<DIV class="para" ALIGN="left">
@@ -149,7 +168,7 @@
From the user perspective the Connector should appear like a local MBeanServer
</LI>
<LI>
-Unsupported methods throw an execption
+Unsupported methods throw an exception
</LI>
<LI>
Supports remote notification handling
@@ -159,7 +178,7 @@
</LI>
</UL>
According to the spec the JMX Connector should offer the client a Proxy for a
remote MBean but
-then the MBean proxy must be available at compile time and this compite with the
JMX agent
+then the MBean proxy must be available at compile time and this compete with the
JMX agent
requirements that an JMX agent has to support dynamic loading of MBeans therefore
this is
not supported now.
</DIV>
@@ -191,7 +210,7 @@
The Object Handler class is a serializable class allowing the remote client to deal
with
remotely instantiated classes. This eliminates problems with not serializable
classes and
with the unique identification of serialized classes (on a round trip you get a
copy of
-the origanal instance). The Object Handler is also used to avoid troubles with not
serializable
+the original instance). The Object Handler is also used to avoid troubles with not
serializable
classes used as a Handback object in the Notification handling.
<B>This class allows the client to work on the JMX Connector as he would work on a
local
MBeanServer.</B>
@@ -230,7 +249,7 @@
ask the Connector Factory for all available, remote MBeanServers and let the user
select
one, then it asks the Connector Factory for all available Connectors or more
precise all
the supported protocols of the available Connectors. Now the user can select the
protocol
-and the Test Client loads and starts the appropriate Connector (if avaialable) and
register
+and the Test Client loads and starts the appropriate Connector (if available) and
register
it as a new MBean at the local MBeanServer. Afterwards it asks the Connector for all
available MBeans on the remote server, displays it wit all the attributes and
operations
on this remote MBean. At the end it will try to register to all remote MBeans a
notification
@@ -253,7 +272,7 @@
jmxri.jar (from lib directory)
</LI>
<LI>
-jndi.properties (from conf directory) which you propably have to adjust
+jndi.properties (from conf directory) which you probably have to adjust
</LI>
</UL>
</DIV>
@@ -261,7 +280,12 @@
<DIV class="para" ALIGN="left">
<OL>
<LI>
-Instantiate the <B>RMIClientConnectorImp</B>.
+Instantiate the <B>RMIClientConnectorImpl</B>.
+<PRE class="code" ALIGN="left">
+JMXConnector lConnector = new RMIClientConnectorImpl(
+ "<server-name>"
+);
+</PRE>
</LI>
<LI>
Use either instance or its interface <B>JMXConnector</B> or <B>MBeanServer</B>. If
you got
@@ -275,6 +299,9 @@
If you register a Notification Listener then <B>stop this instance</B> before
terminating
the program otherwise the remote MBeanServer will throw an exception when this
Notification
Listener is called.
+<PRE class="code" ALIGN="left">
+lConnector.stop();
+</PRE>
</LI>
</OL>
</DIV>
@@ -282,25 +309,127 @@
<DIV class="para" ALIGN="left">
<OL>
<LI>
+Import the necessary classes
+<PRE class="code" ALIGN="left">
+import com.sun.management.jmx.MBeanServerImpl;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.management.RuntimeErrorException;
+import javax.management.RuntimeMBeanException;
+import javax.management.RuntimeOperationsException;
+import javax.naming.InitialContext;
+
+import org.jboss.jmx.interfaces.JMXConnector;
+import org.jboss.jmx.client.RMIClientConnectorImpl;
+</PRE>
+</LI>
+<LI>
Instantiate a local MBeanServer (MBeanServerImpl)
+<PRE class="code" ALIGN="left">
+final MBeanServer lLocalServer = new MBeanServerImpl();
+</PRE>
+The local variable is made final because it is needed in the shutdown hook.
</LI>
<LI>
-Load and start the ConnectorFactory MBean
+Load the logger MBean (is needed now because the Connector Factory is a standard
+jBoss MBean but maybe I should make it to a normal MBean to make it leaner).
+<PRE class="code" ALIGN="left">
+lLocalServer.createMBean(
+ "org.jboss.logging.Logger",
+ new ObjectName( "DefaultDomain :name=Logger" )
+);
+</PRE>
</LI>
<LI>
-Look for the list of servers and within a server for the list of protocols
+Load and start the ConnectorFactory MBean
+<PRE class="code" ALIGN="left">
+final ObjectInstance lFactoryInstance = lLocalServer.createMBean(
+ "org.jboss.jmx.client.ConnectorFactoryService",
+ new ObjectName( "DefaultDomain:name=ConnectorFactory" )
+);
+</PRE>
+</LI>
+<LI>
+Look for the list of servers
+<PRE class="code" ALIGN="left">
+Collection lServers = (Collection) lLocalServer.invoke(
+lFactoryInstance.getObjectName(),
+ "getServers",
+ null,
+ null
+);
+</PRE>
+and within a server for the list of protocols
+<PRE class="code" ALIGN="left">
+Collection lProtocols = (Collection) lLocalServer.invoke(
+lFactoryInstance.getObjectName(),
+ "getProtocols",
+ new String[] {lServer},
+ new String[] {"java.lang.String"}
+);
+</PRE>
</LI>
<LI>
Create a connection to the selected Connector
+<PRE class="code" ALIGN="left">
+JMXConnector lConnector = (JMXConnector) lLocalServer.invoke(
+lFactoryInstance.getObjectName(),
+ "createConnection",
+ new Object[] {lServer,lProtocol},
+ new String[] {"java.lang.String","java.lang.String"}
+);
+</PRE>
</LI>
<LI>
Use the new Connector MBean on the local MBeanServer to get and set the attributes
and perform
-operation on the choosen MBeans on the remote MBeanServer.
+operation on the chosen MBeans on the remote MBeanServer.
+<PRE class="code" ALIGN="left">
+Iterator i = pConnector.queryMBeans( null, null ).iterator();
+while( i.hasNext() ) {
+ MBeanInfo info = pConnector.getMBeanInfo( ( (ObjectInstance) i.next()
).getObjectName() );
+ MBeanAttributeInfo[] aInfos = info.getAttributes();
+ ...
+ MBeanOperationInfo[] oInfos = info.getOperations();
+ ...
+</PRE>
</LI>
<LI>
Register a Notification Listener on a remote MBean and wait for notification events
sent from
-the remote MBean. But when you terminate the connector you have to <B>stop</B> the
MBean Connector
-on the local MBeanServer to remove all the Notification Listener from the remote
MBeanServer.
+the remote MBean.
+<PRE class="code" ALIGN="left">
+Iterator i = pConnector.queryMBeans( null, null ).iterator();
+int j = 0;
+while( i.hasNext() ) {
+ ObjectInstance lBean = (ObjectInstance) i.next();
+ try {
+ pConnector.addNotificationListener(
+ lBean.getObjectName(),
+ (NotificationListener) new Listener(),
+ (NotificationFilter) null,
+ new NotSerializableHandback(
+ lBean.getObjectName() + "" + j++
+ )
+ );
+ ...
+</PRE>
+But when you terminate the connector you have to <B>remove the connection</B> by
using the
+Connector Factory to remove all the Notification Listener from the remote
MBeanServer.
+<PRE class="code" ALIGN="left">
+lLocalServer.invoke(
+ lFactoryInstance.getObjectName(),
+ "removeConnection",
+ new Object[] {lServer,lProtocol},
+ new String[] {"java.lang.String","java.lang.String"}
+);
+</PRE>
</LI>
</OL>
</DIV>