Java Reference
In-Depth Information
Figure 9.4 The TCPServer MBean handling incoming requests. Each time a
client connects, a new TCPAdapter object is created.
TCPServerMBean —MBean interface that declares the methods exposed for
the adapter
TCPServer —Implements the MBean interface and creates the ServerSocket
TCPAdapter —Created by the TCPServer to handle each incoming client
TCPTester —Class used to test the TCP adapter
The first step to create the adapter is to write the MBean interface for the TCP-
Server MBean. The MBean is a Standard MBean (look back to chapter 4 if nec-
essary), and its interface follows:
package jmxbook.ch9;
public interface TCPServerMBean
{
public void setPort( int port );
public int getPort();
public boolean start();
public boolean stop();
}
The TCPServerMBean interface declares two operations and one read/write
attribute. The Port attribute is the port number to which the ServerSocket will lis-
ten for incoming clients. The start() method initiates the ServerSocket and tells
the MBean to begin listening. Alternatively, the stop() method closes the Server-
Socket and stops the TCPServer MBean from receiving any new clients. Existing
clients will continue to have access to the agent until they close their connection.
Listing 9.8 shows the implementation of the TCPServerMBean interface in the
TCPServer class.
Search WWH ::




Custom Search