Class Broadcaster

java.lang.Object
  extended byjava.lang.Thread
      extended byBroadcaster
All Implemented Interfaces:
java.util.EventListener, javax.sound.sampled.LineListener, java.lang.Runnable

public class Broadcaster
extends java.lang.Thread
implements javax.sound.sampled.LineListener

This class periodically broadcasts its host computer's room information via 802.11. Concurrently with this broadcast, an ultrasound pulse is emitted from the speakers. Any nearby mobile clients listening for these broadcasts will hear the 802.11 room information and the ultrasound pulse, thus correctly identifying its location.

The ultrasound pulse comes from a WAV file whose name is hard-coded into this class as a constant, and the room information to transmit is passed into this class's constructor.


Field Summary
static java.lang.String DEFAULTMSG
           
static java.lang.String GROUPADDR
           
 int MAXTIME
           
 int MINTIME
           
static int PORTNUM
           
static java.lang.String WAVEFILE
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Broadcaster()
          This is a default constructor that is provided in the case that an array of bytes containing room-identifying information is not provided.
Broadcaster(byte[] msg)
          This is the main class constructor.
 
Method Summary
 void run()
          This is where all the thread activity occurs in a continous loop.
 void terminate()
          This method is used by external classes running this Broadcaster thread.
 void update(javax.sound.sampled.LineEvent event)
          This method is called by the 'audioClip' data line whenever an event occurs.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WAVEFILE

public static final java.lang.String WAVEFILE
See Also:
Constant Field Values

GROUPADDR

public static final java.lang.String GROUPADDR
See Also:
Constant Field Values

PORTNUM

public static final int PORTNUM
See Also:
Constant Field Values

DEFAULTMSG

public static final java.lang.String DEFAULTMSG
See Also:
Constant Field Values

MINTIME

public int MINTIME

MAXTIME

public int MAXTIME
Constructor Detail

Broadcaster

public Broadcaster()
This is a default constructor that is provided in the case that an array of bytes containing room-identifying information is not provided. By default, the message "Unidentified Room" will be broadcasted.


Broadcaster

public Broadcaster(byte[] msg)
This is the main class constructor. It takes an array of bytes to be saved in an instance variable for later broadcast. Since this class is a thread, the broadcasting will not begin until the start() method is called. This constructor establishes both the datagram communication system and the audio playback system.

Parameters:
msg - Array of bytes containing room-identifying information
Method Detail

run

public void run()
This is where all the thread activity occurs in a continous loop. During each loop iteration, an 802.11 message is broadcasted with the room-identifying information stored in 'buf' and an ultrasound pulse is generated by playing the wave file 'WAVEFILE.' At the end of each loop iteration, the thread sleeps for MINTIME to MAXTIME milliseconds.

Specified by:
run in interface java.lang.Runnable

terminate

public void terminate()
This method is used by external classes running this Broadcaster thread. The purpose of this method is to terminate the thread by setting the internal 'keepRunning' boolean to false so that the thread's run() method breaks out of the while loop and gracefully shuts down all audio and communication systems.


update

public void update(javax.sound.sampled.LineEvent event)
This method is called by the 'audioClip' data line whenever an event occurs. In this Broadcaster thread class, the only event of interest is the STOP event, which will occur when the clip has finished going through all of its audio frames. When the stop event occurs, this method will "rewind" the clip to the beginning by setting the frame position to 0.

Specified by:
update in interface javax.sound.sampled.LineListener
Parameters:
event - The line event that has occured in the clip object