Java Reference
In-Depth Information
to the client. When creating an MBean, clients should expect either the SUCCESS
message or an error returned.
To complete this task, the client must send the classname of the MBean, a
String value for an object name, and the arguments and signature if a construc-
tor with arguments is to be used. If arguments are sent, the method breaks them
into the needed Object and String arrays for the MBean server's createMBean()
method. After acquiring all the necessary information from the client, the cre-
ateMBean() method invokes the createMBean() method on the MBean server to
complete the task. If no exception is thrown, the task completes.
The invoke() method works similarly to the createMBean() method. For this
task, the adapter must gather the operation name, object name, and possible
arguments from the client in order to invoke an MBean operation. After doing
so, the invoke() method calls the invoke() method of the MBean server and
prepares the return value to be sent back to the client. The return value is put
into String form via the toString() method to be sent over the socket. No object
serialization is used.
D
Adding the adapter to the JMXBookAgent class
Before you write the test program, let's add the code to the JMXBookAgent class
that will create TCP adapter when the agent is started. Listing 9.10 shows the
new startTCPAdapter() method for the agent class.
Listing 9.10
The startTCPAdapter() method
protected void startTCPAdapter()
{
TCPServer tcp = new TCPServer();
ObjectName adapterName = null;
try
{
adapterName = new ObjectName(
"JMXBookAgent:name=TCPAdapter");
server.registerMBean( tcp, adapterName);
tcp.start();
}
catch(Exception e)
{
e.printStackTrace();
}
}
Search WWH ::




Custom Search