org.objectweb.jonas.discovery
Class DiscoveryComm

java.lang.Object
  extended by org.objectweb.jonas.discovery.DiscoveryComm
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
DiscoveryGreetingResponder

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

Version:
1.0
Author:
Takoua Abdellatif

Field Summary
protected  java.lang.String domainName
          Domain name that this instance belongs to.
protected  java.lang.String jonasName
          Name for this jonas instance.
protected  java.net.MulticastSocket multicastSocket
          Used to multicast a discovery event on run() execution
protected  boolean notStopped
          Set to false if the thread is stopped
static int RECEIVE_BUFFER_SIZE
          Size of buffer to read incoming packets into.
protected  java.lang.String serverId
          The server ID of the jonas instance.
protected  java.net.DatagramSocket unicastSocket
          Uset to send a discovery event as response to a discovey message
protected  java.lang.String[] urls
          MBean server connection URLs for this server.
 
Constructor Summary
DiscoveryComm(DiscoveryManager dm)
          Constructs a DiscoveryComm associated to the DiscoveryManager
 
Method Summary
 DiscEvent createNotifMessage(java.lang.String state)
          Create a discovery event to notify about a state change of the event sender
protected  java.net.DatagramPacket getDatagram(int length)
          Construct a new datagram.
 java.lang.String getServerId()
           
protected  void join()
          Creates a MulticastSocket and joins the group of multicas host identified by the InetAddress destAddress
 void run()
           
 void sendNotif(DiscMessage msg)
          sends (multicasts) a Discovery Message to the group.
protected  void sendResponse(DiscMessage msg, java.net.InetAddress destAddress, int port)
          Send response to a DiscoveryMessage
protected  void setDomainName(java.lang.String domainName)
           
protected  void setJonasName(java.lang.String jonasName)
           
 void setServerId(java.lang.String serverId)
           
protected  void setUrls(java.lang.String[] urls)
           
 void stop()
          sends a notification message to notify that the server is stopping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RECEIVE_BUFFER_SIZE

public static final int RECEIVE_BUFFER_SIZE
Size of buffer to read incoming packets into.

See Also:
Constant Field Values

multicastSocket

protected java.net.MulticastSocket multicastSocket
Used to multicast a discovery event on run() execution


unicastSocket

protected java.net.DatagramSocket unicastSocket
Uset to send a discovery event as response to a discovey message


notStopped

protected boolean notStopped
Set to false if the thread is stopped


jonasName

protected java.lang.String jonasName
Name for this jonas instance.


domainName

protected java.lang.String domainName
Domain name that this instance belongs to.


serverId

protected java.lang.String serverId
The server ID of the jonas instance.


urls

protected java.lang.String[] urls
MBean server connection URLs for this server.

Constructor Detail

DiscoveryComm

public DiscoveryComm(DiscoveryManager dm)
Constructs a DiscoveryComm associated to the DiscoveryManager

Parameters:
dm - DiscoveryManager to which this thread is associated
Method Detail

join

protected void join()
Creates a MulticastSocket and joins the group of multicas host identified by the InetAddress destAddress


sendNotif

public void sendNotif(DiscMessage msg)
sends (multicasts) a Discovery Message to the group.

Parameters:
msg - The message to send.

sendResponse

protected void sendResponse(DiscMessage msg,
                            java.net.InetAddress destAddress,
                            int port)
Send response to a DiscoveryMessage

Parameters:
msg - Containes a DiscoveryMessage allowing to inform about the responder (name, state, URLs)
destAddress - the destination address picked up from the request
port - the destination port picked up from the request

createNotifMessage

public DiscEvent createNotifMessage(java.lang.String state)
                             throws java.lang.Exception
Create a discovery event to notify about a state change of the event sender

Parameters:
state - - RUNNING if the sender notifies that it gets running - STOPPING if the sender notifies that it stops running
Returns:
a Discovery event (notification)
Throws:
java.lang.Exception - is thrown if the jmx service is not reached.

getDatagram

protected java.net.DatagramPacket getDatagram(int length)
Construct a new datagram.

Parameters:
length - packets length to be received
Returns:
the created datagram

run

public void run()
Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

stop

public void stop()
sends a notification message to notify that the server is stopping.


setJonasName

protected void setJonasName(java.lang.String jonasName)
Parameters:
jonasName - The jonasName to set.

setDomainName

protected void setDomainName(java.lang.String domainName)
Parameters:
domainName - The domainName to set.

setUrls

protected void setUrls(java.lang.String[] urls)
Parameters:
urls - The urls to set.

getServerId

public java.lang.String getServerId()

setServerId

public void setServerId(java.lang.String serverId)