groupmgmt.impl
Class BeaconReceiver

java.lang.Object
  extended bygroupmgmt.impl.BeaconReceiver

class BeaconReceiver
extends java.lang.Object

The BeaconReceiver class; Listens for MemberBeacons and notifies the registered BeaconListeners via a BeaconEvent.

Based on the beacon package by Ali Hazemi.

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

Nested Class Summary
private  class BeaconReceiver.BeaconEventQueue
          Private Thread class to do the notifying.
private  class BeaconReceiver.ReceiverListener
          Private Thread class to do the listening.
 
Field Summary
private  BeaconReceiver.BeaconEventQueue beaconEventQueue
          A separate thread to notify listeners of the BeaconEvents.
private  java.util.Vector beaconListeners
          A Vector list of the BeaconListeners to notify of new beacons.
private  java.net.InetAddress localHost
          Reference to this host's address, used to check if a beacon is our own or from another host.
private  java.net.InetAddress mcastAddress
          The multicast address to listen to.
private  int mcastPort
          The multicast port to listen to.
private  java.net.MulticastSocket mSocket
          The multicast socket used to broadcast the beacons.
private  boolean receiveOwn
          Determines whether this receiver should receive its own beacons.
private  BeaconReceiver.ReceiverListener receiverThread
          The thread that listens on the multicast address for incoming beacons.
private  boolean started
          Keeps track of whether this BeaconReceiver has started.
 
Constructor Summary
BeaconReceiver(java.net.InetAddress mcastAddress, int mcastPort)
          Creates a BeaconReceiver that does not receive its own beacons.
BeaconReceiver(java.net.InetAddress mcastAddress, int mcastPort, boolean receiveOwn)
          Create a BeaconReceiver.
 
Method Summary
 void addBeaconListener(BeaconListener beaconListener)
          Add a BeaconListener to be notified of new BeaconEvents.
 java.net.InetAddress getMcastAddress()
          Accessor to the multicast address.
 int getMcastPort()
          Accessor to the multicast port.
private  void log(java.lang.String msg)
          For testing.
 BeaconEvent makeBeaconEvent(MemberBeacon beacon)
          Allows construction of a new BeaconEvent whose source is the BeaconReceiver class.
 void notifyBeaconListeners(BeaconEvent evt)
          Notifies listeners of a BeaconEvent
 void removeBeaconListener(BeaconListener beaconListener)
          Stop sending BeaconEvents to a BeaconListener.
 void start()
          Starts this beacon receiver.
 void stop()
          Stops this beacon reciever from receiving beacons.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

receiverThread

private BeaconReceiver.ReceiverListener receiverThread
The thread that listens on the multicast address for incoming beacons.


beaconListeners

private java.util.Vector beaconListeners
A Vector list of the BeaconListeners to notify of new beacons.


mcastAddress

private java.net.InetAddress mcastAddress
The multicast address to listen to.


mcastPort

private int mcastPort
The multicast port to listen to.


localHost

private java.net.InetAddress localHost
Reference to this host's address, used to check if a beacon is our own or from another host.


mSocket

private java.net.MulticastSocket mSocket
The multicast socket used to broadcast the beacons.


receiveOwn

private boolean receiveOwn
Determines whether this receiver should receive its own beacons.


started

private boolean started
Keeps track of whether this BeaconReceiver has started.


beaconEventQueue

private BeaconReceiver.BeaconEventQueue beaconEventQueue
A separate thread to notify listeners of the BeaconEvents.

Constructor Detail

BeaconReceiver

public BeaconReceiver(java.net.InetAddress mcastAddress,
                      int mcastPort,
                      boolean receiveOwn)
Create a BeaconReceiver.

Parameters:
mcastAddress - The multicast address to listen for beacons on.
mcastPort - The port to listen for beacons on.
receiveOwn - True if this receiver should notify Listeners of beacons sent from this host.

BeaconReceiver

public BeaconReceiver(java.net.InetAddress mcastAddress,
                      int mcastPort)
Creates a BeaconReceiver that does not receive its own beacons.

Method Detail

getMcastAddress

public java.net.InetAddress getMcastAddress()
Accessor to the multicast address.

Returns:
The mcastAddress that we're listening for beacons on.

getMcastPort

public int getMcastPort()
Accessor to the multicast port.

Returns:
The mcastPort that we're listening for beacons on.

addBeaconListener

public void addBeaconListener(BeaconListener beaconListener)
Add a BeaconListener to be notified of new BeaconEvents.

Parameters:
beaconListener - The listener to be notified.

removeBeaconListener

public void removeBeaconListener(BeaconListener beaconListener)
Stop sending BeaconEvents to a BeaconListener.


notifyBeaconListeners

public void notifyBeaconListeners(BeaconEvent evt)
Notifies listeners of a BeaconEvent

Parameters:
evt - The BeaconEvent to send out.

makeBeaconEvent

public BeaconEvent makeBeaconEvent(MemberBeacon beacon)
Allows construction of a new BeaconEvent whose source is the BeaconReceiver class.

Parameters:
beacon - The beacon to be encapsulated in the event.
Returns:
The BeaconEvent created.

start

public void start()
Starts this beacon receiver.


stop

public void stop()
Stops this beacon reciever from receiving beacons.


log

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