groupmgmt.impl
Class BeaconingDetector

java.lang.Object
  extended bygroupmgmt.MemberDetector
      extended bygroupmgmt.impl.BeaconingDetector
All Implemented Interfaces:
BeaconListener, java.util.EventListener, GroupChangedListener

public class BeaconingDetector
extends MemberDetector
implements BeaconListener, GroupChangedListener

The BeaconingDetector class; Detects members based on beacons, using a BeaconServer. If a new beacon is received, reportChange is called and it passes the change on to the Disseminator. No additional filtering is done. If a beacon is received with 'stopping' set, then reportChange is called to remove the member. This class is also in charge of multicasting beacons to its neighbors.
Everything here is done locally, there is no need for a MemberDetector leader because all Members act the same. (It would be possible to implement a less chatty [fewer beacons] and thus more scalable model by designating a MemberDetector leader.)
Uses: MemberBeacon, BeaconEvent, BeaconListener, BeaconServer.

Version:
July 2003
Author:
Christine Julien, Tom Elgin

Field Summary
private  BeaconServer beaconServer
          The BeaconServer for this host.
private  boolean debugging
          Determines whether to output log messages.
private  java.util.Hashtable neighborBeacons
          The neighbors table.
private  java.lang.Boolean stopping
          Object to use for waiting to exit the Group after I set my beacon to stopping.
 
Fields inherited from class groupmgmt.MemberDetector
disseminator
 
Constructor Summary
BeaconingDetector(int beaconPort, java.lang.String beaconAddress, int beaconPeriod)
          Constructor.
 
Method Summary
 void groupChanged(GroupChangedEvent evt)
          Implements the GroupChangedListener interface.
private  void log(java.lang.String msg)
          For testing.
 void newMemberBeacon(BeaconEvent memberBeaconEvent)
          Implements the BeaconListener interface.
private  void reportArriving(Member member)
          Private utility method to report an arriving Member to the Disseminator.
private  void reportDeparting(Member member)
          Private utility method to report a departing Member to the Disseminator.
 void setDebug(boolean debugging)
          Determine whether to output logging messages.
protected  void start()
          Begin looking for changes in the group (hosts to engage/disengage with) and start sending beacons.
protected  void stop()
          Stop reporting changes in the group, stop looking for beacons, and stop sending beacons.
 
Methods inherited from class groupmgmt.MemberDetector
isActive, reportChange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

beaconServer

private BeaconServer beaconServer
The BeaconServer for this host. It is the object responsible for sending and listening for beacons. Part of the beacon package.


neighborBeacons

private java.util.Hashtable neighborBeacons
The neighbors table. Contains a MemberBeacon object corresponding to every neighbor of this Member (everyone we are connected to). The table is keyed by Member and contains the most recent MemberBeacon.


stopping

private java.lang.Boolean stopping
Object to use for waiting to exit the Group after I set my beacon to stopping.


debugging

private boolean debugging
Determines whether to output log messages.

Constructor Detail

BeaconingDetector

public BeaconingDetector(int beaconPort,
                         java.lang.String beaconAddress,
                         int beaconPeriod)
Constructor. Sets the beaconing parameters and initializes the BeaconServer. This does NOT start the BeaconServer, activate() must be called.

Parameters:
beaconPort - The port to multicast beacons to at 230.0.0.1.
beaconAddress - The multicast address to send beacons to.
beaconPeriod - How often to send beacons (milliseconds).
Method Detail

setDebug

public void setDebug(boolean debugging)
Determine whether to output logging messages.

Parameters:
debugging - Outputs messages if true.

start

protected void start()
Begin looking for changes in the group (hosts to engage/disengage with) and start sending beacons.

Specified by:
start in class MemberDetector

stop

protected void stop()
Stop reporting changes in the group, stop looking for beacons, and stop sending beacons. Blocks until we have been removed from the group.

Specified by:
stop in class MemberDetector

groupChanged

public void groupChanged(GroupChangedEvent evt)
Implements the GroupChangedListener interface. Only used while stopping. If the new group I'm in is just me, then I've successfully stopped.

Specified by:
groupChanged in interface GroupChangedListener
Parameters:
evt - The GroupChangedEvent.

newMemberBeacon

public void newMemberBeacon(BeaconEvent memberBeaconEvent)
Implements the BeaconListener interface. Updates the neighbors table and adds or removes neighbors based on whether they're stopping or not.

Specified by:
newMemberBeacon in interface BeaconListener
Parameters:
memberBeaconEvent - The event generated by the receipt of the new beacon.

reportArriving

private void reportArriving(Member member)
Private utility method to report an arriving Member to the Disseminator.

Parameters:
member - The member that's arriving.

reportDeparting

private void reportDeparting(Member member)
Private utility method to report a departing Member to the Disseminator.

Parameters:
member - The member that's departing.

log

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