com.adventnet.services.discovery
Class DiscoveryClient

java.lang.Object
  extended by com.adventnet.services.discovery.DiscoveryClient
All Implemented Interfaces:
java.lang.Runnable

public class DiscoveryClient
extends java.lang.Object
implements java.lang.Runnable

The DiscoveryClient class is the client class to discover AdventNet JMX agents. JMX agent can only discovered if it has a DiscoveryService mbean registered with it. DiscoveryClient will broadcast a discovery request on a multicast socket . The JMX agents(discovery service) listening on the multicast group will receive the request. Each JMX agent will send a discovery response to the DiscoveryClient. The discovery client also joins the same default muticast group 225.225.225.225 and the default port is 8222 as of DiscoveryService


Field Summary
(package private)  java.util.Hashtable finderTable
           
(package private)  java.net.InetAddress group
           
(package private) static int handbackID
           
(package private)  boolean initialDiscovery
           
(package private)  java.util.Vector initialVector
           
(package private)  java.util.Hashtable listenerTable
           
(package private)  java.lang.Thread recvThread
           
(package private)  boolean state
           
(package private)  boolean toBeStopped
           
 
Constructor Summary
DiscoveryClient()
          The default constructor
DiscoveryClient(int mcPort)
          The constructor with multicast port number as parameter
 
Method Summary
 void addDiscoveryObjectListener(DiscoveryObjectListener listener)
          the method to add DiscoveryObjectListener which are interested to listen for DiscoveryEvent
(package private)  DiscoveryObject convertToDiscoveryObject(DiscoveryPacket pack)
           
(package private)  DiscoveryPacket createDiscoveryPacket()
           
 DiscoveryEvent discoverJMXAgents()
          Discovers all JMX agents(MBeanServers) and its associated adaptors/connectors in the network.
 DiscoveryEvent discoverJMXAgents(java.lang.String host)
          Discovers all JMX agents(MBeanServers) and its associated adaptors/connectors in the specified host.The discovery time is specified by the timeout in DiscoveryClient.
(package private)  void doInitialDiscovery()
           
 java.lang.String getMulticastGroup()
          Gets the multicast group.
 int getMulticastPort()
          Gets the multicast port.
 boolean getState()
          Gets the state of this client.
 int getTimeout()
          Gets the timeout for receiving the response for the broadcasted discovery request.
 int getTimeToLive()
          Gets the time to live (hop count).
(package private)  void handleInitialDiscovery(DiscoveryPacket pack)
           
(package private)  void processPacket(DiscoveryPacket pack)
           
(package private)  DiscoveryPacket receivePacket()
           
 void removeDiscoveryObjectListener(DiscoveryObjectListener listener)
          method to remove DiscoveryObjectListener object
 void run()
          The receiver thread runnable
(package private)  void sendPacket(DiscoveryPacket packet, java.net.InetAddress group, int port)
           
 void setDiscoveryToSingleHost(java.lang.String host)
          Method used for sending discovery packets for single host,instead of broadcasting it to a group
 void setMulticastGroup(java.lang.String mcGroup)
          Sets the multicast group.
 void setMulticastPort(int mcPort)
          Sets the multicast port.
 void setTimeout(int timeout)
          Sets the timeout
 void setTimeToLive(int ttl)
          Sets the time to live for the client request packet.
 void start()
          Method to start the discovery client
 void stop()
          Method to stop the discovery client
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

group

java.net.InetAddress group

recvThread

java.lang.Thread recvThread

toBeStopped

boolean toBeStopped

initialVector

java.util.Vector initialVector

state

boolean state

initialDiscovery

boolean initialDiscovery

listenerTable

java.util.Hashtable listenerTable

handbackID

static int handbackID

finderTable

java.util.Hashtable finderTable
Constructor Detail

DiscoveryClient

public DiscoveryClient(int mcPort)
                throws java.lang.Exception
The constructor with multicast port number as parameter

Throws:
java.lang.Exception

DiscoveryClient

public DiscoveryClient()
                throws java.lang.Exception
The default constructor

Throws:
java.lang.Exception
Method Detail

getMulticastGroup

public java.lang.String getMulticastGroup()
Gets the multicast group. Default group is 225.225.225.225


setMulticastGroup

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


getMulticastPort

public int getMulticastPort()
Gets the multicast port. Default port is 8222


setMulticastPort

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


getTimeToLive

public int getTimeToLive()
Gets the time to live (hop count). Default value is 2


setTimeToLive

public void setTimeToLive(int ttl)
Sets the time to live for the client request packet.


getTimeout

public int getTimeout()
Gets the timeout for receiving the response for the broadcasted discovery request. Default value is 5000 (5 sec)


setTimeout

public void setTimeout(int timeout)
Sets the timeout


getState

public boolean getState()
Gets the state of this client.


start

public void start()
           throws java.lang.Exception
Method to start the discovery client

Throws:
java.lang.Exception

doInitialDiscovery

void doInitialDiscovery()
                  throws java.lang.Exception
Throws:
java.lang.Exception

createDiscoveryPacket

DiscoveryPacket createDiscoveryPacket()

sendPacket

void sendPacket(DiscoveryPacket packet,
                java.net.InetAddress group,
                int port)
          throws java.lang.Exception
Throws:
java.lang.Exception

stop

public void stop()
          throws java.lang.Exception
Method to stop the discovery client

Throws:
java.lang.Exception

handleInitialDiscovery

void handleInitialDiscovery(DiscoveryPacket pack)

convertToDiscoveryObject

DiscoveryObject convertToDiscoveryObject(DiscoveryPacket pack)

run

public void run()
The receiver thread runnable

Specified by:
run in interface java.lang.Runnable

discoverJMXAgents

public DiscoveryEvent discoverJMXAgents()
                                 throws java.lang.Exception
Discovers all JMX agents(MBeanServers) and its associated adaptors/connectors in the network. The discovery time is specified by the timeout in DiscoveryClient.

Returns:
DiscoveryEvent. Each DiscoveryObject in this event constitutes a MBeanServer and has information about the adaptors/connectors about that MBeanServer.
Throws:
java.lang.Exception

discoverJMXAgents

public DiscoveryEvent discoverJMXAgents(java.lang.String host)
                                 throws java.lang.Exception
Discovers all JMX agents(MBeanServers) and its associated adaptors/connectors in the specified host.The discovery time is specified by the timeout in DiscoveryClient.

Parameters:
host - the host name tobe discovered
Returns:
DiscoveryEvent. Each DiscoveryObject in this event constitutes a MBeanServer and has information about the adaptors/connectors about that MBeanServer in the specified host.
Throws:
java.lang.Exception

receivePacket

DiscoveryPacket receivePacket()
                        throws java.lang.Exception
Throws:
java.lang.Exception

processPacket

void processPacket(DiscoveryPacket pack)
             throws java.lang.Exception
Throws:
java.lang.Exception

addDiscoveryObjectListener

public void addDiscoveryObjectListener(DiscoveryObjectListener listener)
the method to add DiscoveryObjectListener which are interested to listen for DiscoveryEvent


removeDiscoveryObjectListener

public void removeDiscoveryObjectListener(DiscoveryObjectListener listener)
method to remove DiscoveryObjectListener object


setDiscoveryToSingleHost

public void setDiscoveryToSingleHost(java.lang.String host)
Method used for sending discovery packets for single host,instead of broadcasting it to a group