|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.jdmk.discovery.DiscoveryResponder
public class DiscoveryResponder
Implements the MBean that responds to the discovery requests. Any agent
that needs to be discovered must instantiate and register a
DiscoveryResponder
in its MBean server.
When the DiscoveryResponder
start
method is
called, the MBean creates a multicast socket.
The DiscoveryResponder
then sends a join message
to the multicast group.
When a DiscoveryResponder
is unregistered from the MBean server,
or when stop
method is called, the MBean
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 MBean server.
When start
method is called, and when 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 using appropriate constructor.
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. It can be changed using
setTimeToLive
method when the DiscoveryResponder
is OFFLINE.
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 | |
---|---|
DiscoveryResponder()
Constructs a DiscoveryResponder . |
|
DiscoveryResponder(String multicastGroup,
int multicastPort)
Constructs a DiscoveryResponder . |
|
DiscoveryResponder(String multicastGroup,
int multicastPort,
InetAddress inf)
Constructs a DiscoveryResponder . |
|
DiscoveryResponder(String multicastGroup,
int multicastPort,
InetAddress inf,
String local)
Constructs a DiscoveryResponder . |
Method Summary | |
---|---|
String |
getMulticastGroup()
Returns the multicast group. |
int |
getMulticastPort()
Returns the multicast port. |
Integer |
getState()
Returns the state of this DiscoveryResponder . |
String |
getStateString()
Returns the state of this DiscoveryResponder in string form. |
int |
getTimeToLive()
Returns the time-to-live value. |
byte[] |
getUserData()
Returns a byte[] containing the additional information that the user added in the DiscoveryResponse . |
boolean |
isActive()
Tests if the DiscoveryResponder is active. |
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 |
setTimeToLive(int ttl)
Sets the default Time to Live to be used to send join and leave message to the Multicast group. |
void |
setUserData(byte[] data)
Allows the user to specify additional information in the DiscoveryResponse message. |
void |
start()
Create a multicast socket and join the multicast group. |
void |
stop()
Sends a leave message to the multicast group and leaves it. |
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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int ONLINE
public static final int OFFLINE
public static final int STOPPING
public static final int STARTING
Constructor Detail |
---|
public DiscoveryResponder()
DiscoveryResponder
.
Creates a discovery responder using the
default multicast group (224.224.224.224) and the
default multicast port (9000).
No check is done on the default values: check will be performed by the start method.
The multicast group and port values can be overwritten using setter
the properties multicastGroup
and multicastPort
.
public DiscoveryResponder(String multicastGroup, int multicastPort)
DiscoveryResponder
.
Creates a discovery responder using the specified multicast group and the
specified multicast port.
The multicast group and port values can be overwritten using setter
the properties multicastGroup
and multicastPort
.
No check is done on the parameter values: check will be performed by the start method.
multicastGroup
- The multicast group name.multicastPort
- The multicast port number.public DiscoveryResponder(String multicastGroup, int multicastPort, InetAddress inf)
DiscoveryResponder
.
This constructor initialize multicast group and a multicast port. No check is done on the parameter values. Check will be performed by the start method.
multicastGroup
- The multicast group name.multicastPort
- The multicast port number.inf
- the interface used by a MulticastSocket.public DiscoveryResponder(String multicastGroup, int multicastPort, InetAddress inf, String local)
DiscoveryResponder
.
This constructor initialize multicast group and a multicast port. No check is done on the parameter values. Check will be performed by the start method.
multicastGroup
- The multicast group name.multicastPort
- The multicast port number.inf
- the interface used by a MulticastSocket.local
- the local host address used to answer a request.Method Detail |
---|
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
preRegister
in interface MBeanRegistration
server
- The MBean server in which the MBean will be registered.name
- The object name of the MBean.
Exception
- This exception should be caught by the
MBean server and re-thrown as an MBeanRegistrationException
.public void postRegister(Boolean registrationDone)
postRegister
in interface MBeanRegistration
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.public void preDeregister() throws Exception
preDeregister
in interface MBeanRegistration
java.langException
- This exception should be caught by the MBean server and re-thrown
as an MBeanRegistrationException
.
Exception
public void postDeregister()
postDeregister
in interface MBeanRegistration
public void start() throws IOException
DiscoveryResponder
will then join the multicast group and send a join message.
This method has no effect if the DiscoveryResponder
is ONLINE
or
STOPPING
or STARTING
.
start
in interface DiscoveryResponderMBean
IOException
- The creation of the Multicast socket failed.public void stop()
DiscoveryResponder
leaves its multicast group.
This method has no effect if the DiscoveryResponder
is OFFLINE
or
STOPPING
or STARTING
.
stop
in interface DiscoveryResponderMBean
public boolean isActive()
DiscoveryResponder
is active.
True
is returned if the DiscoveryResponder
is started (DiscoveryResponder
has join the multicast group).
isActive
in interface DiscoveryResponderMBean
public boolean waitState(int state, long timeout)
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:
waitState
returns immediately (i.e. does not wait at all),waitState
waits until the value of this MBean's State attribute
is the same as the state parameter (i.e. will wait
indefinitely if this condition is never met).
waitState
in interface DiscoveryResponderMBean
state
- The value of this MBean's State attribute to wait for.
state can be one of:
DiscoveryResponder.OFFLINE
,
DiscoveryResponder.ONLINE
,
DiscoveryResponder.STARTING
,
DiscoveryResponder.STOPPING
.timeout
- The maximum time to wait for, in
milliseconds, if positive.
Infinite time out if 0, or no waiting at all if negative.
true
if the value of this MBean's State attribute
is the same as the state parameter;
false
otherwise.public String getMulticastGroup()
getMulticastGroup
in interface DiscoveryResponderMBean
public void setMulticastGroup(String multicastGroup) throws IllegalStateException
Only available if state in OFFLINE
setMulticastGroup
in interface DiscoveryResponderMBean
multicastGroup
- The multicast group name.
IllegalStateException
- This method has been invoked while
the DiscoveryResponder
was ONLINE or STARTING.public int getMulticastPort()
getMulticastPort
in interface DiscoveryResponderMBean
public void setMulticastPort(int multicastPort) throws IllegalStateException
Only available if state in OFFLINE
setMulticastPort
in interface DiscoveryResponderMBean
multicastPort
- The multicast port.
IllegalStateException
- This method has been invoked while
the DiscoveryResponder
was ONLINE or STARTING.public int getTimeToLive()
getTimeToLive
in interface DiscoveryResponderMBean
public void setTimeToLive(int ttl) throws IllegalStateException
Time to Live should an integer verifying the following condition: 0 < ttl <= 255 Only available if state in OFFLINE
setTimeToLive
in interface DiscoveryResponderMBean
ttl
- The Time to live value.
IllegalArgumentException
- The input ttl value is not
in the 1 to 255 range.
IllegalStateException
- This method has been invoked while
the DiscoveryResponder
was ONLINE or STARTING.public Integer getState()
DiscoveryResponder
.
getState
in interface DiscoveryResponderMBean
ONLINE
, OFFLINE
or STOPPING
or STARTING
.public String getStateString()
DiscoveryResponder
in string form.
getStateString
in interface DiscoveryResponderMBean
public void setUserData(byte[] data)
DiscoveryResponse
message.
The following limitation applies to the length of the byte array
parameter:
The length of a UDP packet is maximum 64 Kbytes. In addition to the
specified user data, the discovery response UDP packet contains the
following :
setUserData
in interface DiscoveryResponderMBean
public byte[] getUserData()
DiscoveryResponse
.
If no additional information has been added, this method returns null
.
getUserData
in interface DiscoveryResponderMBean
|
Open Source build 02 opendmk-1.0-b02 2007.10.01_19:17:46_MEST |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |