Java Reference
In-Depth Information
Listing 3.3
startRMIConnector() method that adds the RMI connector server
to the agent
protected void startRMIConnector()
{
RmiConnectorServer connector = new RmiConnectorServer();
ObjectName connectorName = null;
try
{
connector.setPort( 2099 );
connectorName = new ObjectName(
"JMXBookAgent:name=RMIConnector");
server.registerMBean( connector, connectorName );
connector.start();
}
catch(Exception e)
{
ExceptionUtil.printException( e );
}
}
The implementation of this method is almost identical to the
startHTML-
Adapter()
method we already examined. First, you create the
RmiConnec-
torServer
instance (which is the connector MBean) and register it on the
MBeanServer
using a new
ObjectName
instance. After registering the connector,
you invoke its
start()
method, preparing it to receive clients. After we examine
the
main()
method of the agent, you will create the
RMI
client factory class used
to create clients for the
RMI
connector.
3.2.3
Finishing with a main() method
Listing 3.4 shows the
main()
method used to start this agent from a command-
line prompt. It simply constructs an instance of the agent and print out messages
for the user.
Listing 3.4
The main() method of the JMXBookAgent class
public static void main(String[] args)
{
System.out.println("\n~~~~~~~~~~~~~~~~~~~~~~~" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("\n>>> START of JMXBook Agent");
System.out.println("\n>>> CREATE the agent...");
JMXBookAgent agent = new JMXBookAgent();
System.out.println("\nAgent is Ready for Service...\n");
}