|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.jdmk.discovery.DiscoveryClient
public class DiscoveryClient
Provides methods to discover Java DMK agents.
A Java DMK agent can only discovered if it has a
DiscoveryResponder
registered in its MBean server.
A discovery operation is executed in two steps:
DiscoveryClient
broadcasts a discovery request on a
multicast groupDiscoveryResponder
MBeans listening on the multicast group
catch the request. Each DiscoveryResponder
sends a discovery response to the DiscoveryClient
A DiscoveryClient
can only reach the
DiscoveryResponder
objects that listen on the same multicast group and
port. The default group is 224.224.224.224 and the default port is 9000. Other values
can be used by configuring the multicastGroup
and
multicastPort
properties on the DiscoveryClient
and DiscoveryResponder
objects.
The scope of the discovery depends on the time-to-live used by
the MulticastSocket
. By default, the time-to-live is 1. It
can be changed by setting the property timeToLive
on the
DiscoveryClient
.
After it has sent its discovery request, a DiscoveryClient
waits a finite time for responses. The default is 1 second.
This can be customized by setting the timeOut
property on the
DiscoveryClient
.
An application triggers a discovery operation by invoking either the
findMBeanServers
method or the findCommunicators
method on a DiscoveryClient
object.
These methods represent the discovery result by a Vector
of
DiscoveryResponse
. A DiscoveryResponse
is included
for each discovered Java DMK agent. It provides the host name and the MBean server information of the
agent ( see MBeanServerDelegate
and DiscoveryResponse
) and optionally
the list of communicator (Adaptor and connector) available in the agent.
A DiscoveryResponder
can send back responses using two modes:
DiscoveryResponder
to the DiscoveryClient
. The response is NOT multicasted to the group.
The default datagram socket port is 9001.
To enable unicast mode, set the pointToPointResponse
property to true
.
(Unicast mode is enabled by default.)
DiscoveryResponder
and the DiscoveryClient
. The response is multicasted to the group. This
behavior allows DiscoveryMonitor
objects to be aware of changes.
To enable multicast mode, set the pointToPointResponse
property to false
.
It is possible to instantiate multiple DiscoveryClient
objects with
different groups and ports for multicast responses and datagram sockets for unicast responses.
Field Summary | |
---|---|
static int |
OFFLINE
Marks the "state" property as stopped. |
static int |
ONLINE
Marks the "state" property as running. |
protected int |
state
Reflects the current state of the discovery client. |
Fields inherited from interface com.sun.jdmk.discovery.DiscoveryClientMBean |
---|
STOPPING |
Constructor Summary | |
---|---|
DiscoveryClient()
Constructs a DiscoveryClient . |
|
DiscoveryClient(String multicastGroup,
int multicastPort)
Constructs a DiscoveryClient . |
|
DiscoveryClient(String multicastGroup,
int multicastPort,
InetAddress inf)
Constructs a DiscoveryClient . |
Method Summary | |
---|---|
Vector |
findCommunicators()
Discovers all Java DMK agents and associated communicators (adaptors or connectors). |
Vector |
findCommunicators(String SelectedHost)
Discovers all Java DMK agents and associated communicators (adaptors or connectors) present on an host. |
Vector |
findMBeanServers()
Discovers all Java DMK agents. |
Vector |
findMBeanServers(String SelectedHost)
Discovers whether Java DMK agents with a DiscoveryResponder
registered in any MBean server is on a host. |
String |
getMulticastGroup()
Returns the multicast group. |
int |
getMulticastPort()
Returns the multicast port. |
boolean |
getPointToPointResponse()
Get the unicast datagram socket mode for the Java DMK agent response. |
Integer |
getState()
Returns the state of this DiscoveryClient . |
String |
getStateString()
Returns the state of this DiscoveryClient in string form. |
int |
getTimeOut()
Returns the time to wait for discovery responses in milliseconds. |
int |
getTimeToLive()
Get the time-to-live. |
boolean |
isActive()
Tests if the DiscoveryClient 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 |
setPointToPointResponse(boolean pointToPointResponse)
Set unicast datagram socket mode for the Java DMK agent response. |
void |
setTimeOut(int timeOut)
Sets the time during which the DiscoveryClient waits
for discovery responses. |
void |
setTimeToLive(int ttl)
Sets the default time-to-live for this DiscoveryClient . |
void |
start()
Create a multicast socket and join the multicast group. |
void |
stop()
Leaves the multicast group. |
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
protected transient volatile int state
Constructor Detail |
---|
public DiscoveryClient()
DiscoveryClient
.
This constructor initializes multicast group and a multicast port to the default values (224.224.224.224 and 9000). No check is done on the default values. Check will be performed by the start method.
public DiscoveryClient(String multicastGroup, int multicastPort)
DiscoveryClient
.
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.public DiscoveryClient(String multicastGroup, int multicastPort, InetAddress inf)
DiscoveryClient
.
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.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
DiscoveryClient
will then join the multicast group.
start
in interface DiscoveryClientMBean
IOException
- The creation of the Multicast socket failed.public void stop()
DiscoveryClient
leaves its multicast group,
and the multicast socket is released.
stop
in interface DiscoveryClientMBean
public boolean isActive()
DiscoveryClient
is active.
True
is returned if the DiscoveryClient
is started (DiscoveryClient
has join the multicast group).
isActive
in interface DiscoveryClientMBean
public Vector findMBeanServers() throws CommunicationException
Returns a vector of DiscoveryResponse
, one element for each discovered Java DMK agent.
Each DiscoveryResponse
contains the host name and the MBean server information of the
discovered agent ( see MBeanServerDelegate
and DiscoveryResponse
).
The communicators list is not relevant: it is set to null.
findMBeanServers
in interface DiscoveryClientMBean
DiscoveryResponse
.
CommunicationException
- An error occurred during the discovery.public Vector findMBeanServers(String SelectedHost) throws CommunicationException
DiscoveryResponder
registered in any MBean server is on a host.
Returns a vector of DiscoveryResponse
, one element for each discovered Java DMK agent on the specified host.
Each DiscoveryResponse
only contains the host name and the MBean server information of the
discovered agent ( see MBeanServerDelegate
and DiscoveryResponse
) of the specified host.
The communicators list is not relevant: it is set to null.
findMBeanServers
in interface DiscoveryClientMBean
SelectedHost
- The host on which the discovery is to be performed.
DiscoveryResponse
.
CommunicationException
- An error occurred during the discovery.public Vector findCommunicators() throws CommunicationException
Returns a vector of DiscoveryResponse
, one element for each discovered Java DMK agent.
Each DiscoveryResponse
contains the host name, the MBean server information of the
discovered agent ( see MBeanServerDelegate
and DiscoveryResponse
) and
the communicators list.
findCommunicators
in interface DiscoveryClientMBean
DiscoveryResponse
.
CommunicationException
- An error occurred during the discovery.public Vector findCommunicators(String SelectedHost) throws CommunicationException
Returns a vector of DiscoveryResponse
, one element for each discovered Java DMK agent.
Each DiscoveryResponse
contains the host name, the MBean server information of the
discovered agent ( see MBeanServerDelegate
and DiscoveryResponse
) and
the communicators list.
findCommunicators
in interface DiscoveryClientMBean
SelectedHost
- The host on which the discovery is to be performed.
DiscoveryResponse
.
CommunicationException
- An error occurred during the discovery.public String getMulticastGroup()
getMulticastGroup
in interface DiscoveryClientMBean
public void setMulticastGroup(String multicastGroup) throws IllegalStateException
Only available if the state is OFFLINE
setMulticastGroup
in interface DiscoveryClientMBean
multicastGroup
- The multicast group name.
IllegalStateException
- This method has been invoked while
the DiscoveryClient
was ONLINE or STARTING.public int getMulticastPort()
getMulticastPort
in interface DiscoveryClientMBean
public void setMulticastPort(int multicastPort) throws IllegalStateException
Only available if the state is OFFLINE
setMulticastPort
in interface DiscoveryClientMBean
multicastPort
- The multicast port.
IllegalStateException
- This method has been invoked while
the DiscoveryClient
was ONLINE or STARTING.public void setTimeOut(int timeOut) throws IOException
DiscoveryClient
waits
for discovery responses.
This time is expressed in milliseconds. The default value is 1000.
If the specified argument is negative or zero, the timeOut
is
reset to the default value.
The methods findMBeanServers
and findCommunicators
block until this
time elapsed.
setTimeOut
in interface DiscoveryClientMBean
timeOut
- The timeOut
in milliseconds.
IOException
- If the socket rejected the specified value (See java.net.MulticastSocket
).
This exception can be thrown only if the state in ONLINE: the actual java.net.MulticastSocket
setting
is done when the DiscoveryClient
is ONLINE
.public int getTimeOut()
getTimeOut
in interface DiscoveryClientMBean
timeOut
in milliseconds.public void setTimeToLive(int ttl) throws IOException, IllegalArgumentException
DiscoveryClient
.
The time-to-live is the number of 'hops' that the multicast packet is forwarded on the network.
setTimeToLive
in interface DiscoveryClientMBean
ttl
- A number between 1 and 255.
IllegalArgumentException
- The input ttl value is not in the 1 to 255 range.
IOException
- If the socket rejected the specified value (See java.net.MulticastSocket
).
This exception can be thrown only if the state in ONLINE: the actual java.net.MulticastSocket
setting
is done when the DiscoveryClient
is ONLINE
.public int getTimeToLive()
TimeToLive
has not
been set.
getTimeToLive
in interface DiscoveryClientMBean
public boolean getPointToPointResponse()
true
.
getPointToPointResponse
in interface DiscoveryClientMBean
true
indicates that unicast datagram socket is
being used.
false
indicates that the multicast response mode
is being used.public void setPointToPointResponse(boolean pointToPointResponse)
The client sends a request for a unicast response in each discovery request. The multicast group Inet address is used for the unicast response.
setPointToPointResponse
in interface DiscoveryClientMBean
pointToPointResponse
- The datagram socket mode.
false value unsets the use of unicast socket for the response,
multicast is used instead.public Integer getState()
DiscoveryClient
.
getState
in interface DiscoveryClientMBean
ONLINE
, OFFLINE
.public String getStateString()
DiscoveryClient
in string form.
getStateString
in interface DiscoveryClientMBean
|
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 |