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

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

public class DiscoveryResponder
extends java.lang.Object
implements java.io.Serializable, ActivatableIf

The DiscoveryResponder class implements the m-bean that responds to the discovery requests. Any agent that needs to be discovered must instantiate and register a DiscoveryResponder in its framework.

When a DiscoveryResponder is registered in the framework, or when performStart method is called, the m-bean starts a thread which creates a multicast socket. The DiscoveryResponder then sends a join message to the multicast group. When a DiscoveryResponder is deleted from the framework, or when performStop method is called, the m-bean sends a leave message to the multicast group. The format of these messages is not exposed. These messages allow DiscoveryMonitor objects to maintain a list of agents with DiscoveryResponder objects registered in their frameworks. When a DiscoveryResponder has registered in the framework -or when performStart method is called - and a join message has been sent, the DiscoveryResponder starts to listen for discovery requests.

The multicast socket 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 in the framework by specifying the group and port keys in the ObjectName. These values can be also changed using setMulticastGroup and setMulticastPort methods when the DiscoveryResponder is OFFLINE

When join/leave message are sent to the multicast group, a default time-to-live (see java.net.MulticastSocket) value is used. The time-to-live value specifies how many "hops" that the packet is forwarded on the network before it expires. DiscoveryResponder objects use a time-to-live specified by the property ttl. The default time-to-live value is 1. This can be changed when the DiscoveryResponder is registered in the framework by specifying the ttl keys in the ObjectName. It can be be also changed using setTimeToLive method when the DiscoveryResponder is OFFLINE

For example, to register a DiscoveryResponder that uses the group 224.224.224.222, port 4404 and sends multicast join and leave messages through 4 hops, use the following object name:

See Also:
DiscoveryClient, DiscoveryMonitor, Serialized Form

Field Summary
static int OFFLINE
          Marks the "state" property as stopped.
static int ONLINE
          Marks the "state" property as runnig.
protected  int state
          Reflects the current state of the discovery responder.
static int STOPPING
          Marks the "state" property as in-transition from ONLINE to OFFLINE.
 
Constructor Summary
DiscoveryResponder()
          Constructs a DiscoveryResponder.
DiscoveryResponder(Framework cmf)
          Constructs a DiscoveryResponder.
 
Method Summary
 void deleteCmf()
          Invoked by the framework when it is requested to delete the DiscoveryClient.
 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 DiscoveryResponder.
 java.lang.String getStateString()
          Returns the state of this DiscoveryResponder in string form.
 int getTimeToLive()
          Returns the time-to-live value.
 void initCmf(Framework cmf, ObjectName name, boolean db, ModificationList list)
          Invoked by the framework when it is requested to register the DiscoveryClient.
 boolean isActive()
          Tests if the DiscoveryResponder is active.
 void performStart()
          Starts a thread which creates a multicast socket and sends a join message to the multicast group.
 void performStop()
          Sends a leave message to the multicast group and stops the multicast socket thread.
 void setMulticastGroup(java.lang.String multicastGroup)
          Sets the multicast group name.
 void setMulticastPort(int multicastPort)
          Sets the multicast port.
 void setTimeToLive(int ttl)
          Sets the default Time to Live to be used to send join and leave message to the Multicast group.
 
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.

state

protected transient int state
Reflects the current state of the discovery responder.
Constructor Detail

DiscoveryResponder

public DiscoveryResponder()
Constructs a DiscoveryResponder.

For Java DMK internal use only.


DiscoveryResponder

public DiscoveryResponder(Framework cmf)
Constructs a DiscoveryResponder.

Creates a discovery responder using the default multicast group (224.224.224.224) and the default multicast port (9000). The multicast group and port values can be overwritten using setter the properties multicastGroup and multicastPort.

Parameters:
cmf - The actual JDMK framework object.
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 a thread which creates a multicast socket and sends a join message to the multicast group.
Specified by:
performStart in interface ActivatableIf

performStop

public void performStop()
Sends a leave message to the multicast group and stops the multicast socket thread.
Specified by:
performStop in interface ActivatableIf

isActive

public boolean isActive()
Tests if the DiscoveryResponder is active.
Specified by:
isActive in interface ActivatableIf

getClassVersion

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

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.

getTimeToLive

public int getTimeToLive()
Returns the time-to-live value.
Returns:
The time-to-live value.

setTimeToLive

public void setTimeToLive(int ttl)
Sets the default Time to Live to be used to send join and leave message to the Multicast group.

Time to Live should an integer verifying the following condition: 0 < ttl <= 255 Only available if state in OFFLINE

Parameters:
ttl - The Time to live value.

getState

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

getStateString

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