com.sun.jdmk.discovery
Class DiscoveryMonitor

java.lang.Object
  extended by javax.management.NotificationBroadcasterSupport
      extended by com.sun.jdmk.discovery.DiscoveryMonitor
All Implemented Interfaces:
DiscoveryMonitorMBean, Serializable, MBeanRegistration, NotificationBroadcaster, NotificationEmitter

public class DiscoveryMonitor
extends NotificationBroadcasterSupport
implements Serializable, DiscoveryMonitorMBean, MBeanRegistration

Describe an MBean that listens for registering and unregistering 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 MBean server. When a DiscoveryResponder is registered in an MBean server and when its start or stop methods are called, 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 unregistration message, it sends a DiscoveryResponderNotification to its notification listener.

A DiscoveryMonitor can be instantiated either in stand alone mode (Client side) or added to an MBean Server. In the first case, the client should call the appropriate constructor to initialize the multicastGroup and multicastPort parameters. The default values for the group and the port are 224.224.224.224 and 9000. A DiscoveryMonitor can be stopped by calling the stop method. When it is stopped, the DiscoveryMonitor no longer listens for registering and unregistering messages from DiscoveryResponder objects. A DiscoveryMonitor can be restarted by invoking the start method.

A DiscoveryMonitor has a state property which reflects its activity.

DiscoveryMonitor State
running ONLINE
stopped OFFLINE
stopping STOPPING
starting STARTING

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 removed from a Java DMK agent, it is automatically stopped.

See Also:
Serialized Form

Field Summary
static int OFFLINE
          Marks the "state" property as stopped.
static int ONLINE
          Marks the "state" property as running.
static int STARTING
          Marks the "state" property as in-transition from OFFLINE to ONLINE.
static int STOPPING
          Marks the "state" property as in-transition from ONLINE to OFFLINE.
 
Constructor Summary
DiscoveryMonitor()
          Constructs a DiscoveryMonitor.
DiscoveryMonitor(String multicastGroup, int multicastPort)
          Constructs a DiscoveryMonitor.
DiscoveryMonitor(String multicastGroup, int multicastPort, InetAddress inf)
          Constructs a DiscoveryMonitor.
 
Method Summary
 String getMulticastGroup()
          Returns the multicast group.
 int getMulticastPort()
          Returns the multicast port.
 Integer getState()
          Returns the state of this DiscoveryMonitor.
 String getStateString()
          Returns the state of this DiscoveryMonitor in string form.
 void postDeregister()
          Allows the MBean to perform any operations needed after having been unregistered in the MBean server.
 void postRegister(Boolean registrationDone)
          Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.
 void preDeregister()
          Allows the MBean to perform any operations it needs before being unregistered by the MBean server.
 ObjectName preRegister(MBeanServer server, ObjectName name)
          Allows the MBean to perform any operations it needs before being registered in the MBean server.
 void setMulticastGroup(String multicastGroup)
          Sets the multicast group name.
 void setMulticastPort(int multicastPort)
          Sets the multicast port.
 void start()
          Starts listening for DiscoveryResponder objects registering/unregistering.
 void stop()
          Stops this DiscoveryMonitor.
 boolean waitState(int state, long timeout)
          Waits until either the State attribute of this MBean equals the specified state parameter, or the specified timeout has elapsed.
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
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 running.

See Also:
Constant Field Values

OFFLINE

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

See Also:
Constant Field Values

STOPPING

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

See Also:
Constant Field Values

STARTING

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

See Also:
Constant Field Values
Constructor Detail

DiscoveryMonitor

public DiscoveryMonitor()
Constructs a DiscoveryMonitor.

This constructor creates and initializes a multicast socket used to listen for DiscoveryResponder objects registering or unregistering. The default group (224.224.224.224) and port (9000) are used. No check is done on the default values: check will be performed by the start method.


DiscoveryMonitor

public DiscoveryMonitor(String multicastGroup,
                        int multicastPort)
Constructs a DiscoveryMonitor.

This constructor creates and initializes a multicast socket used to listen for DiscoveryResponder objects registering or unregistering. No check is done on the parameter values: check will be performed by the start method.

Parameters:
multicastGroup - The multicast group name.
multicastPort - The multicast port number.

DiscoveryMonitor

public DiscoveryMonitor(String multicastGroup,
                        int multicastPort,
                        InetAddress inf)
Constructs a DiscoveryMonitor.

This constructor creates and initializes a multicast socket used to listen for DiscoveryResponder objects registering or unregistering. No check is done on the parameter values: check will be performed by the start method.

Parameters:
multicastGroup - The multicast group name.
multicastPort - The multicast port number.
inf - The interface used by a MulticastSocket.
Since:
Java DMK 5.0
Method Detail

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws Exception
Allows the MBean to perform any operations it needs before being registered in the MBean server. If the name of the MBean is not specified, the MBean can provide a name for its registration. If any exception is raised, the MBean will not be registered in the MBean server.

Specified by:
preRegister in interface MBeanRegistration
Parameters:
server - The MBean server in which the MBean will be registered.
name - The object name of the MBean.
Returns:
The name of the MBean registered.
Throws:
Exception - This exception should be caught by the MBean server and re-thrown as an MBeanRegistrationException.

postRegister

public void postRegister(Boolean registrationDone)
Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.

Specified by:
postRegister in interface MBeanRegistration
Parameters:
registrationDone - Indicates whether or not the MBean has been successfully registered in the MBean server. The value false means that the registration phase has failed.

preDeregister

public void preDeregister()
                   throws Exception
Allows the MBean to perform any operations it needs before being unregistered by the MBean server.

Specified by:
preDeregister in interface MBeanRegistration
Throws:
java.langException - This exception should be caught by the MBean server and re-thrown as an MBeanRegistrationException.
Exception

postDeregister

public void postDeregister()
Allows the MBean to perform any operations needed after having been unregistered in the MBean server.

Specified by:
postDeregister in interface MBeanRegistration

start

public void start()
           throws IOException
Starts listening for DiscoveryResponder objects registering/unregistering.

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

Specified by:
start in interface DiscoveryMonitorMBean
Throws:
IOException - The creation of the Multicast socket failed.

stop

public void stop()
Stops this DiscoveryMonitor.

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

Specified by:
stop in interface DiscoveryMonitorMBean

getState

public Integer getState()
Returns the state of this DiscoveryMonitor.

Specified by:
getState in interface DiscoveryMonitorMBean
Returns:
ONLINE,OFFLINE, STOPPING or STARTING.

getStateString

public String getStateString()
Returns the state of this DiscoveryMonitor in string form.

Specified by:
getStateString in interface DiscoveryMonitorMBean
Returns:
One of the strings "ONLINE", "OFFLINE", "STOPPING" or "STARTING".

getMulticastGroup

public String getMulticastGroup()
Returns the multicast group. A multicast group is specified by a class D IP address, those in the range 224.0.0.1 to 239.255.255.255.

Specified by:
getMulticastGroup in interface DiscoveryMonitorMBean
Returns:
A string containing the multicast group name.

setMulticastGroup

public void setMulticastGroup(String multicastGroup)
                       throws IllegalStateException
Sets the multicast group name. A multicast group is specified by a class D IP address, those in the range 224.0.0.1 to 239.255.255.255.

Only available if state in OFFLINE

Specified by:
setMulticastGroup in interface DiscoveryMonitorMBean
Parameters:
multicastGroup - The multicast group name.
Throws:
IllegalStateException - This method has been invoked while the DiscoveryMonitor was ONLINE or STARTING.

getMulticastPort

public int getMulticastPort()
Returns the multicast port. It can be any standard UDP port number.

Specified by:
getMulticastPort in interface DiscoveryMonitorMBean
Returns:
The multicast port number.

setMulticastPort

public void setMulticastPort(int multicastPort)
                      throws IllegalStateException
Sets the multicast port. It can be any standard UDP port number.

Only available if state in OFFLINE

Specified by:
setMulticastPort in interface DiscoveryMonitorMBean
Parameters:
multicastPort - The multicast port.
Throws:
IllegalStateException - This method has been invoked while the DiscoveryMonitor was ONLINE or STARTING.

waitState

public boolean waitState(int state,
                         long timeout)
Waits until either the State attribute of this MBean equals the specified state parameter, or the specified timeout has elapsed. The method waitState returns with a boolean value indicating whether the specified state parameter equals the value of this MBean's State attribute at the time the method terminates.

Two special cases for the timeout parameter value are:

Specified by:
waitState in interface DiscoveryMonitorMBean
Parameters:
state - The value of this MBean's State attribute to wait for. state can be one of: DiscoveryMonitor.OFFLINE, DiscoveryMonitor.ONLINE, DiscoveryMonitor.STARTING, DiscoveryMonitor.STOPPING.
timeout - The maximum time to wait for, in milliseconds, if positive. Infinite time out if 0, or no waiting at all if negative.
Returns:
true if the value of this MBean's State attribute is the same as the state parameter; false otherwise.

Open Source build 02
opendmk-1.0-b02 2007.10.01_19:17:46_MEST

Copyright 1998-2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.