Java Dynamic Management Kit 3.2 Programming Guide
[ Previous ][ Fast Back ]Chapter 15. Event Handling, Alarm Clock, and Monitoring Services[ Fast Forward ][ Next ]

Discovery Service

The discovery service enables you to discover Java Dynamic Management agents in a network. Only agents that have a discovery responder registered in their framework can be discovered using this service. The discovery service can be functionally divided into two parts:

Discovery Search Service

The discovery search service consists of a discovery client that initiates the discovery operation and a discovery responder, each instance of which supplies the return information about the agent in which it is registered. The return information is represented in the discovery client by a discovery response object.

Figure 15-5. Discovery Search Service

fig837.epsi

Discovery Client

The DiscoveryClient class provides methods to discover agents. The discovery operation is initiated by the discovery client that sends a discovery request to a multicast group and waits for responses. These messages are proprietary and are not exposed to the user. Discovery clients can only discover agents listening on the same multicast group and port. The default multicast group is 224.224.224.224 and the default port is 9000. The multicast group and port can be reconfigured to other values by changing the multicastGroup and multicastPort properties on the DiscoveryClient object. The DiscoveryClient does not join the multicast group until the performStart() method is invoked.

You can instantiate multiple discovery clients on a single agent or manager. Each discovery client can be configured to use different multicast groups or ports. This allows you to use a single agent or manager for monitoring different groups of agents.

To instantiate a discovery client, create an instance of the Java class: com.sun.jaw.impl.agent.services.jawdiscovery.DiscoveryClient. The scope of the discovery depends on the time-to-live used by the multicast socket. Time-to-live is defined by the Java class java.net.MulticastSocket. By default, the time-to-live is 1. It can be changed by setting the property timeToLive on the discovery client.

After it has sent a discovery request, a discovery client waits for responses for a specific time. By default the time is 1 second. This can be customized by setting the timeOut property, in milliseconds, on the discovery client. The discovery client also requests the DiscoveryResponder response type; this can be unicast or multicast. The response type is specified using the returnPort variable, a negative number specifies a multicast response. For further information, see Unicast Mode. Example 15-30 shows the instantiation, initialization, and starting of a discovery client using a non-default multicast group and port.

Example 15-30. Instantiating and Initializing a Discovery Client
disc = new DiscoveryClient ();
   disc.setMulticastGroup("224.224.224.222");
   disc.setMulticastPort(9002);
   // instantiate a discovery client using non default
   // multicast group and port
...
int timeOut = 1000 ;       // wait for response timeout
int returnPort = -1 ;      // request multicast response
int ttlint = 2 ;           // scope

disc.setTimeOut(timeOut) ;
disc.setPointToPointResponsePort(returnPort) ;
disc.setTimeToLiveInt(ttlint) ;
disc.performStart() ;      // start the discovery client

Discovery Responder

The agents must have a DiscoveryResponder registered in their framework to be found by the discovery service. When a new DiscoveryResponder object registers in an agent, or when its performStart() method is invoked, it sends out a multicast registration message. Similarly, a responder that deregisters or has its performStop() method invoked, sends a multicast deregistration message. These messages are proprietary and are not exposed to the user. The registration/deregistration messages enable you to keep an accurate record of agents with discovery responders in the network; for further information, see Discovery Support Service.

Discovery responders reply to a request from a discovery client by sending a response that contains information on the hostname of the agent and, optionally, a list of adaptors available in the agent. The message is proprietary and is decoded and represented in the DiscoveryClient by the DiscoveryResponse object. The DiscoveryResponse object consists of a string representing the hostnames of discovered agents and a vector of ObjectName representing the adaptors found on each agent. Example 15-31 shows the initialization of a discovery responder.

Example 15-31. Initializing a Discovery Responder
private static final String multicastResponder=
      "com.sun.jaw.impl.agent.services.jawdiscovery.DiscoveryResponder" ;

// register a discovery responder with the framework
// the responder uses the multicast group 224.224.224.222
// and port 9002

String properties = ".group = 224.224.224.222, port = 9002";
DiscoveryResponder disc ;
     disc = (DiscoveryResponder) agent.framework.newObject(multicastResponder,
            agent.framework.getDomain() + ":" + multicastResponder
            + properties, null);

The discovery responder registered in the discovered agent can respond using one of two modes:

The response method used is specified when the discovery client is initialized. The default is unicast.

Unicast Mode

The discovery responder creates a datagram socket for the response to the discovery client. The response is not multicast to the group. The datagram socket address is the same as the local host; this cannot be customized. Unicast mode is enabled by invoking the setPointToPointResponse() method with the Boolean value -TRUE.

Figure 15-6. Unicast Discovery Mode

fig839.epsi

Multicast Mode

The discovery responder uses a multicast socket to send response messages. The response messages are multicast to the group. Multicast mode is enabled by invoking the setPointToPointResponse() method with the Boolean value -FALSE.

Figure 15-7. Multicast Discovery Mode

fig835.epsi

Performing a Discovery Operation

An application triggers a discovery operation by invoking the methods performFindHosts() or performFindAdaptors() on a DiscoveryClient object. Both methods return a vector of DiscoveryResponse objects. The DiscoveryResponse object returned by the performFindHosts() method contains a string which is the hostname of a discovered agent. The DiscoveryResponse object returned by the performFindAdaptors() method contains a string which is the hostname of a discovered agent and a vector of object names which represents a list of adaptors instantiated on that agent. Example 15-32 shows code for performing a discovery operation.

Example 15-32. Performing a Discovery Operation
Vector result ;

result = disc.performFindAdaptors () ;

Discovery Support Service

The discovery support service enables you to monitor discovery responders in a multicast group. A DiscoveryMonitor object listens for discovery responder objects registering or deregistering in the multicast group. When the discovery monitor hears a discovery responder registering or deregistering, it sends a discovery responder event to its listener. The listener is an instance of the Java class that implements the DiscoveryResponderListener interface.

Figure 15-8. Discovery Support Service

fig840.epsi

Discovery Monitor

The DiscoveryMonitor is an m-bean that listens for DiscoveryResponder objects registering or deregistering within a specific multicast group. The default multicast group is 224.224.224.224 and the default port is 9000.

To instantiate a discovery monitor, create an instance of the com.sun.jaw.impl.agent.services.jawdiscovery.DiscoveryMonitor class. A discovery monitor can also be created using a different multicast group or port, by specifying these when calling the constructor. Example 15-33 shows code for instantiating a discovery monitor on the remote agent from the client.

Example 15-33. Instantiating and Starting a Discovery Monitor
String domain = console;   // domain name of the remote agent
String DiscoveryMonitorClass =
   "com.sun.jaw.impl.agent.services.jawdiscovery.DiscoveryMonitor";

DiscoveryMonitorName = new ObjectName(domain +
   ":com.sun.jaw.impl.agent.services.jawdiscovery.DiscoveryMonitorMO.port
    = 9002);
monitor = (DiscoveryMonitorMO) adaptor.cb_newMO(DiscoveryMonitorClass,
           DiscoveryMonitorName, null);
           // adds the discovery monitor mbean to the remote agent
monitor.addDiscoveryResponderListenerMO(this);   // Registers listener with
                                                 // the remote event source.

monitor.performStart() ;                         // Starts the monitor

A discovery monitor can be stopped using the performStop() method. When it is stopped, the discovery monitor does not listen for registration/deregistration messages from DiscoveryResponder objects. The discovery monitor is restarted using the performStart() method. The discovery monitor has a state property that allows you to determine whether it is ONLINE, OFFLINE, or STOPPING. The STOPPING state is seen only when the discovery monitor is still dealing with active requests. When a DiscoveryMonitor is added in a Java Dynamic Management Kit agent, it is automatically started. When a DiscoveryMonitor is removed from a Java Dynamic Management Kit agent, it is automatically stopped.

Discovery Responder Listener

A discovery responder listener is an instance of the Java class that implements the DiscoveryResponderListener interface. For example, it may be implemented to update a list of agents in the network.


[ Previous ][ Home ][ Next ]
Monitoring Service[ Up ]Cascading Agent Service