groupmgmt.impl
Class BeaconSender

java.lang.Object
  extended bygroupmgmt.impl.BeaconSender
All Implemented Interfaces:
java.lang.Runnable

class BeaconSender
extends java.lang.Object
implements java.lang.Runnable

The BeaconSender class; Responsible for periodically multicasting MemberBeacons. Controlled by the BeaconServer.

Based on the beacon package by Ali Hazemi.

Version:
July 2003
Author:
Christine Julien, Tom Elgin
See Also:
BeaconServer

Field Summary
private  MemberBeacon beacon
          The MemberBeacon to broadcast.
private  java.net.DatagramSocket dgramSocket
          The DatagramSocket to send beacons with.
private  java.net.InetAddress mcastAddress
          The multicast address to send beacons to.
private  int mcastPort
          The multicast port to send beacons to.
private  int period
          The period to wait between broadcasts (ms).
private  java.lang.Thread senderThread
          Thread to do the sending.
 
Constructor Summary
BeaconSender(java.net.InetAddress mcastAddress, int mcastPort)
          Construct a BeaconSender.
 
Method Summary
 MemberBeacon getBeacon()
          Accessor to the beacon.
private  void log(java.lang.String msg)
          For testing.
 void run()
          Run the BeaconSender thread.
 void sendBeacon()
          The method that sends the beacon.
 void setBeacon(MemberBeacon beacon)
          Set the beacon to be broadcasted.
 void setPeriod(int period)
          Set the period at which the beacon is broadcasted.
 void start()
          Start sending beacons.
 void stop()
          Stop sending beacons.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mcastAddress

private java.net.InetAddress mcastAddress
The multicast address to send beacons to.


mcastPort

private int mcastPort
The multicast port to send beacons to.


dgramSocket

private java.net.DatagramSocket dgramSocket
The DatagramSocket to send beacons with.


senderThread

private volatile java.lang.Thread senderThread
Thread to do the sending.


beacon

private MemberBeacon beacon
The MemberBeacon to broadcast.


period

private int period
The period to wait between broadcasts (ms). Defaults to 1000.

Constructor Detail

BeaconSender

public BeaconSender(java.net.InetAddress mcastAddress,
                    int mcastPort)
Construct a BeaconSender.

Parameters:
mcastAddress - The multicast address to beacon to.
mcastPort - The port to beacon to.
Method Detail

start

public void start()
Start sending beacons.


stop

public void stop()
Stop sending beacons.


setPeriod

public void setPeriod(int period)
Set the period at which the beacon is broadcasted.

Parameters:
period - How often to send the beacon (ms).

setBeacon

public void setBeacon(MemberBeacon beacon)
Set the beacon to be broadcasted.

Parameters:
beacon - The MemberBeacon to broadcast.

getBeacon

public MemberBeacon getBeacon()
Accessor to the beacon.

Returns:
The MemberBeacon currently being broadcasted.

run

public void run()
Run the BeaconSender thread. Sends a datagram message every [period] millisecond to a multicast [address]:[port]. The datagram contains the MemberBeacon object.

Specified by:
run in interface java.lang.Runnable

sendBeacon

public void sendBeacon()
The method that sends the beacon.


log

private void log(java.lang.String msg)
For testing. Output a message to the command line.