groupmgmt.impl
Class SafeDistanceDetector

java.lang.Object
  |
  +--groupmgmt.MemberDetector
        |
        +--groupmgmt.impl.SafeDistanceDetector
All Implemented Interfaces:
groupmgmt.impl.BeaconListener, java.util.EventListener, GroupChangedListener, LocationListener

public class SafeDistanceDetector
extends MemberDetector
implements groupmgmt.impl.BeaconListener, LocationListener, GroupChangedListener

The SafeDistanceDetector class; Detects members based on beacons, using a BeaconServer. If a new beacon is received, we check the distance, and if it is within a safe range, reportChange is called and it passes the change on to the Disseminator. If a beacon is received with 'stopping' set or if a beacon moves beyond the safe distance, 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. also uses Location and LocationGenerator from the location package.

Version:
July 2003
Author:
Christine Julien, Tom Elgin

Fields inherited from class groupmgmt.MemberDetector
disseminator
 
Constructor Summary
SafeDistanceDetector(int beaconPort, java.lang.String beaconAddress, int beaconPeriod, double range, double maxSpeed, double networkLatency, LocationGenerator locationGenerator)
          Constructor.
 
Method Summary
 void groupChanged(GroupChangedEvent evt)
          Implements the GroupChangedListener interface.
 void locationChanged(LocationEvent event)
          Implements the LocationListener interface.
 void newMemberBeacon(groupmgmt.impl.BeaconEvent memberBeaconEvent)
          Implements the BeaconListener interface.
 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
 

Constructor Detail

SafeDistanceDetector

public SafeDistanceDetector(int beaconPort,
                            java.lang.String beaconAddress,
                            int beaconPeriod,
                            double range,
                            double maxSpeed,
                            double networkLatency,
                            LocationGenerator locationGenerator)
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.
beaconAddress - The multicast address to send beacons to.
beaconPeriod - How often to send beacons (milliseconds).
range - The transmission range of the network (meters).
maxSpeed - The maximum speed of the host (meters/second).
networkLatency - Lag in the network (milliseconds).
locationGenerator - Where to receive locationChanged events from.
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.
Overrides:
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.
Overrides:
stop in class MemberDetector

locationChanged

public void locationChanged(LocationEvent event)
Implements the LocationListener interface. Updates the current location and changes the beacon.
Specified by:
locationChanged in interface LocationListener
Parameters:
event - The LocationEvent containing the new Location.

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(groupmgmt.impl.BeaconEvent memberBeaconEvent)
Implements the BeaconListener interface. Updates the neighbors table and adds or removes neighbors based on location and stopping information.
Specified by:
newMemberBeacon in interface groupmgmt.impl.BeaconListener
Parameters:
memberBeaconEvent - The event generated by the receipt of the new beacon.