Java Reference
In-Depth Information
The startJINIConnector() method
In chapter 3, which introduced the
JMXBookAgent
class, you gave it a
startRMI-
Connector()
method that added the
RMI
connector MBean to the agent. How-
ever, in that chapter, we did not discuss what took place in the code. Listing 9.7
shows the
startJINIConnector()
method.
Listing 9.7
The startJINIConnector() method of the JMXBookAgent class
protected void startJINIConnector()
{
ObjectName connectorName = null;
try
{
System.setSecurityManager( new RMISecurityManager() );
JINIServer jini = new JINIServer();
ObjectName jiniName = null;
jiniName =
new ObjectName( "JMXBookAgent:name=JINIConnector" );
server.registerMBean( jini, jiniName );
jini.enableConnections();
}
catch(Exception e)
{
e.printStackTrace();
}
}
The method creates an instance of the connector MBean (the
JINIServer
class)
and a new
ObjectName
instance for the MBean, and registers the MBean on the
MBean server. Finally, it calls the
enableConnections()
method of the MBean to
create and start the Jini service within.
Running the example
Now you have written all the code, you need to test this connector. To compile
and run the connector, however, you must download the latest Jini developer kit
from http://www.javasoft.com. Once you have it, complete the following steps to
test the connector:
Compile the
jmxbook.ch9
package. You need the
JMX
JAR
s, the
JMX
_re-
moting.jar file from the contrib/jars folder, and the Jini
JAR
files in your
CLASSPATH
in order to compile the agent. To compile the connector
source files, you need the
JMX
JAR
s and the Jini
JAR
s in your
CLASSPATH
.
1