📄 ch13s39.html
字号:
java.naming.provider.url points to the JNDI server your JMX Connectors
are registered to. At the moment you can only have one JMX Connector
running at the same computer (but serveral can be registered at the same
JNDI server) and you can only have one JNDI server.
</p><div class="orderedlist"><ol type="1"><li><p><a name="d0e9988"></a>
Import the necessary classes
<pre class="programlisting">
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.RemoteMBeanServer;
import org.jboss.jmx.client.RMIClientConnectorImpl;
</pre>
</p></li><li><p><a name="d0e9994"></a>
Instantiate a local MBeanServer (MBeanServerImpl)
<pre class="programlisting">
final MBeanServer lLocalServer = new MBeanServerImpl();
</pre>
The local variable is made final because it is needed in the shutdown hook.
</p></li><li><p><a name="d0e10000"></a>
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="programlisting">
lLocalServer.createMBean(
"org.jboss.logging.Logger",
new ObjectName( "DefaultDomain :name=Logger" )
);
</pre>
</p></li><li><p><a name="d0e10006"></a>
Load and start the ConnectorFactory MBean
<pre class="programlisting">
final ObjectInstance lFactoryInstance = lLocalServer.createMBean(
"org.jboss.jmx.client.ConnectorFactoryService",
new ObjectName( "DefaultDomain:name=ConnectorFactory" )
);
</pre>
</p></li><li><p><a name="d0e10012"></a>
Look for the list of remote Connectors at a given JNDI server (lContext.getEnvironment()
returns the actual properties from a given InitialContext).
<pre class="programlisting">
Hashtable lProperties = lContext.getEnvironment();
ConnectorFactoryImpl.JBossConnectorTester lTester = new ConnectorFactoryImpl.JBossConnectorTester();
Iterator lConnectors = (Iterator) lLocalServer.invoke(
lFactoryInstance.getObjectName(),
"getConnectors",
new Object[] {
lProperties,
lTester
},
new String[] {
lProperties.getClass().getName(),
lTester.getClass().getName()
}
);
</pre>
</p></li><li><p><a name="d0e10018"></a>
Create a connection to the selected Connector (lConnectorName is an instance returned
by the previous retrieved iterator). The ConnectorName contains the information about
the server, protocol and the JNDI name of a found JMX Connector.
<pre class="programlisting">
RemoteMBeanServer lConnector = (RemoteMBeanServer) lLocalServer.invoke(
lFactoryInstance.getObjectName(),
"createConnection",
new Object[] {
lConnectorName
},
new String[] {
lConnectorName.getClass().getName()
}
);
</pre>
</p></li><li><p><a name="d0e10024"></a>
Use the new Connector MBean on the local MBeanServer to get and set the attributes and
perform operation on the chosen MBeans on the remote MBeanServer.
<pre class="programlisting">
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>
</p></li><li><p><a name="d0e10030"></a>
Register a Notification Listener on a remote MBean and wait for notification events sent
from the remote MBean. The NotSerializableHandback is a helper class to be a serializable
proxy for a Handback which maybe is not serializable.
<pre class="programlisting">
Iterator i = pConnector.queryMBeans( null, nullitemizedlist).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 remove the connection by using the
Connector Factory to remove all the Notification Listener from the remote MBeanServer.
<pre class="programlisting">
lLocalServer.invoke( lFactoryInstance.getObjectName(),
"removeConnection",
new Object[] {
lConnectorName
},
new String[] {
lConnectorName.getClass().getName()
}
);
</pre>
</p></li></ol></div></div><div class="section"><a name="d0e10039"></a><div class="titlepage"><div><h3 class="title"><a name="d0e10039"></a>ToDo List</h3></div></div><p>
This list contains all the stuff to be done to make the JMX Connector full
fledged:
<div class="itemizedlist"><ul><li><p><a name="d0e10045"></a>Test all to make sure that it works from any other JVM that the JBoss VM </p></li></ul></div>
</p><p>
This list contains all the stuff to be done around JMX
<div class="itemizedlist"><ul><li><p><a name="d0e10052"></a>Initiate and start full fledged JMX Agent project</p></li><li><p><a name="d0e10055"></a>Design and implement Relation Service for the JMX Agent</p></li><li><p><a name="d0e10058"></a>Design and implement graphic management tool for JBoss</p></li></ul></div>
</p><p>
If anything is wrong or not correct please contact me at
andreas.schaefer@madplanet.com. Also if you want to know more in detail
or have a request for changes in the JMX Connector.
</p></div></div><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="432" height="79"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch13.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch13s26.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s26.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch13s55.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s55.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -