com.sun.jaw.impl.agent.services.jawdiscovery
Class DiscoveryMonitor

java.lang.Object
  |
  +--com.sun.jaw.impl.agent.services.jawdiscovery.DiscoveryMonitor

public class DiscoveryMonitor
extends java.lang.Object
implements java.io.Serializable

The DiscoveryMonitor class implements the m-bean that listens for registering and deregistering information sent by DiscoveryResponder objects on a given multicast group. Any agent that is to use multicast discovery must have a DiscoveryResponder registered in its framework. When a DiscoveryResponder is registered with or deregistered from a framework, it informs the rest of the multicast group by sending a multicast message. The format of this message is not exposed. Whenever a DiscoveryMonitor receives a registration or deregistration message, it sends a DiscoveryResponderEvent to its event listener.

A DiscoveryMonitor can be instantiated either in stand alone mode (Client side) or added to an agent. In the first case, the client should call the appropriate constructor to initialize the multicastGroup and multicastPort parameters. When a DiscoveryMonitor is added to a Java DMK agent, it uses the group and port specified by the properties multicastGroup and multicastPort. The default values for the group and the port are 224.224.224.224 and 9000. These values can be changed when the DiscoveryResponder is registered with the framework by specifying the group and port keys in the ObjectName. For instance if you want to register a DiscoveryMonitor which uses the group 224.224.224.222 and port 4404, use the following object name:

A DiscoveryMonitor can be stopped by calling the performStop method. When it is stopped, the DiscoveryMonitor no longer listens for registering and deregistering messages from DiscoveryResponder objects. A DiscoveryMonitor can be restarted by invoking the performStart method.

A DiscoveryMonitor has a state property which reflects its activity.

DiscoveryMonitor State
running ONLINE
stopped OFFLINE
stopping STOPPING

The transition between ONLINE and OFFLINE may not be immediate. The DiscoveryMonitor may need some time to finish or interrupt the active requests. During this time the state of the DiscoveryMonitor is STOPPING. When a DiscoveryMonitor is added to a Java DMK agent, it is automatically started. When a DiscoveryMonitor is removed from a Java DMK agent, it is automatically stopped.

See Also:
DiscoveryResponder, Serialized Form

Field Summary
static int OFFLINE
          Marks the "state" property as stopped.
static int ONLINE
          Marks the "state" property as runnig.
static int STOPPING
          Marks the "state" property as in-transition from ONLINE to OFFLINE.
 
Constructor Summary
DiscoveryMonitor()
          Constructs a DiscoveryMonitor.
 
Method Summary
 void addDiscoveryResponderListener(DiscoveryResponderListener x)
          Registers a listener for receiving DiscoveryResponderListener events.
 void deleteCmf()
          Invoked by the framework when it is requested to delete the DiscoveryClient.
 void deliverEvent(DiscoveryResponderEvent event)
          For Java DMK internal use only.
 java.lang.String getClassVersion()
          Returns the version of this class.
 java.lang.String getMulticastGroup()
          Returns the multicast group.
 int getMulticastPort()
          Returns the multicast port.
 java.lang.Integer getState()
          Returns the state of this DiscoveryMonitor.
 java.lang.String getStateString()
          Returns the state of this DiscoveryMonitor in string form.
 void initCmf(Framework cmf, ObjectName name, boolean db, ModificationList list)
          Invoked by the framework when it is requested to register the DiscoveryClient.
 void performStart()
          Starts listening for DiscoveryResponder objects registering/deregistering.
 void performStop()
          Stops this DiscoveryMonitor.
 void removeDiscoveryResponderListener(DiscoveryResponderListener x)
          Removes a listener.
 void setMulticastGroup(java.lang.String multicastGroup)
          Sets the multicast group name.
 void setMulticastPort(int multicastPort)
          Sets the multicast port.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONLINE

public static final int ONLINE
Marks the "state" property as runnig.

OFFLINE

public static final int OFFLINE
Marks the "state" property as stopped.

STOPPING

public static final int STOPPING
Marks the "state" property as in-transition from ONLINE to OFFLINE.
Constructor Detail

DiscoveryMonitor

public DiscoveryMonitor()
                 throws java.io.IOException
Constructs a DiscoveryMonitor.

This constructor creates and initializes a multicast socket used to listen for DiscoveryResponder objects registering or deregistering. The default group (224.224.224.224) and port (9000) are used.

Throws:
java.io.IOException - The creation of the socket failed.
Method Detail

initCmf

public void initCmf(Framework cmf,
                    ObjectName name,
                    boolean db,
                    ModificationList list)
             throws InstanceAlreadyExistException
Invoked by the framework when it is requested to register the DiscoveryClient.

For Java DMK internal use only.

Parameters:
cmf - The core management framework to register the service with.
name - Object name containing configuration information.
db - Indicates if persistent storage is required.
list - The modification list to use for setting up parameters.
Throws:
InstanceAlreadyExistException - The m-bean is already registered in the repository.

deleteCmf

public void deleteCmf()
Invoked by the framework when it is requested to delete the DiscoveryClient.

For Java DMK internal use only.


performStart

public void performStart()
Starts listening for DiscoveryResponder objects registering/deregistering.

This method has no effect if the DiscoveryMonitor is ONLINE or STOPPING.


performStop

public void performStop()
Stops this DiscoveryMonitor.

This method has no effect if the monitor is OFFLINE or STOPPING.


addDiscoveryResponderListener

public void addDiscoveryResponderListener(DiscoveryResponderListener x)
Registers a listener for receiving DiscoveryResponderListener events.
Parameters:
x - The listener to add.

removeDiscoveryResponderListener

public void removeDiscoveryResponderListener(DiscoveryResponderListener x)
Removes a listener.
Parameters:
x - The listener to remove.

deliverEvent

public void deliverEvent(DiscoveryResponderEvent event)
For Java DMK internal use only.

getClassVersion

public java.lang.String getClassVersion()
Returns the version of this class.
Returns:
The version of this class.

getState

public java.lang.Integer getState()
Returns the state of this DiscoveryMonitor.
Returns:
ONLINE,OFFLINE or STOPPING.

getStateString

public java.lang.String getStateString()
Returns the state of this DiscoveryMonitor in string form.
Returns:
One of the strings "ONLINE", "OFFLINE" or "STOPPING".

getMulticastGroup

public java.lang.String getMulticastGroup()
Returns the multicast group.
Returns:
A string containing the multicast group name.

setMulticastGroup

public void setMulticastGroup(java.lang.String multicastGroup)
Sets the multicast group name.

Only available if state in OFFLINE

Parameters:
multicastGroup - The multicast group name.

getMulticastPort

public int getMulticastPort()
Returns the multicast port.
Returns:
The multicast port number.

setMulticastPort

public void setMulticastPort(int multicastPort)
Sets the multicast port.

Only available if state in OFFLINE

Parameters:
multicastPort - The multicast port.