org.placelab.spotter
Class AbstractSpotter

java.lang.Object
  extended byorg.placelab.spotter.AbstractSpotter
All Implemented Interfaces:
Spotter
Direct Known Subclasses:
AsyncSpotter, GarminSimpleTextSpotter, NMEAGPSSpotter, SyncSpotter

public abstract class AbstractSpotter
extends java.lang.Object
implements Spotter

Provides common functionality for sending notifications to listeners and doing single scans. Spotters which use a stream based approach might choose to subclass this class, but generally Spotters should subclass either SyncSpotter or AsyncSpotter for the most convenience.

See Also:
SyncSpotter, AsyncSpotter

Constructor Summary
AbstractSpotter()
           
 
Method Summary
 void addListener(SpotterListener listener)
          Adds a SpotterListener to be called back whenever new Measurements are generated by the Spotter.
protected  void notifyEndOfScan()
           
protected  void notifyEndOfScan(EventSystem evs)
           
protected  void notifyGotException(EventSystem evs, SpotterException ex)
           
protected  void notifyGotException(SpotterException ex)
           
protected  void notifyGotMeasurement(EventSystem evs, Measurement m)
           
protected  void notifyGotMeasurement(Measurement m)
           
 void removeListener(SpotterListener listener)
           
 void scanOnce()
          Performs a single background scan for Measurements and returns the result to registered SpotterListeners' SpotterListener.gotMeasurement(Spotter, Measurement) method.
 void scanOnce(EventSystem evs)
          Like scanOnce() but instead uses the given EventSystem to deliver the callback to hide the background thread from the application.
abstract  void startScanning()
          Start scanning for Measurements in the background and return the Measurements by notifying SpotterListeners with the SpotterListener.gotMeasurement(Spotter, Measurement) method.
abstract  void startScanning(EventSystem evs)
          Start scanning for Measurements.
abstract  void stopScanning()
          Stops a currently running background scan started from either scanOnce or startScanning.
 void waitForThread(java.lang.Thread t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.placelab.spotter.Spotter
close, getMeasurement, open
 

Constructor Detail

AbstractSpotter

public AbstractSpotter()
Method Detail

addListener

public void addListener(SpotterListener listener)
Description copied from interface: Spotter
Adds a SpotterListener to be called back whenever new Measurements are generated by the Spotter.

Specified by:
addListener in interface Spotter

removeListener

public void removeListener(SpotterListener listener)
Specified by:
removeListener in interface Spotter

scanOnce

public void scanOnce()
Description copied from interface: Spotter
Performs a single background scan for Measurements and returns the result to registered SpotterListeners' SpotterListener.gotMeasurement(Spotter, Measurement) method. This may start a new thread and deliver the callback in that new thread.

Registered SpotterListeners that also implement the ScanOnceListener interface will also receive ScanOnceListener.endOfScan(Spotter) notifications.

Specified by:
scanOnce in interface Spotter
See Also:
Spotter.scanOnce(EventSystem)

scanOnce

public void scanOnce(EventSystem evs)
Description copied from interface: Spotter
Like Spotter.scanOnce() but instead uses the given EventSystem to deliver the callback to hide the background thread from the application.

Specified by:
scanOnce in interface Spotter

notifyGotMeasurement

protected void notifyGotMeasurement(Measurement m)

notifyGotException

protected void notifyGotException(SpotterException ex)

notifyGotMeasurement

protected void notifyGotMeasurement(EventSystem evs,
                                    Measurement m)

notifyGotException

protected void notifyGotException(EventSystem evs,
                                  SpotterException ex)

notifyEndOfScan

protected void notifyEndOfScan()

notifyEndOfScan

protected void notifyEndOfScan(EventSystem evs)

waitForThread

public void waitForThread(java.lang.Thread t)

startScanning

public abstract void startScanning()
Description copied from interface: Spotter
Start scanning for Measurements in the background and return the Measurements by notifying SpotterListeners with the SpotterListener.gotMeasurement(Spotter, Measurement) method. Depending on the Spotter implementation this may start up a new background thread. Callbacks to the SpotterListener are not guaranteed to (and probably won't) be in the the same thread as startScanning was called in.

Specified by:
startScanning in interface Spotter
See Also:
Spotter.startScanning(EventSystem)

startScanning

public abstract void startScanning(EventSystem evs)
Description copied from interface: Spotter
Start scanning for Measurements. This method may or may not create a new thread internally, but should never expose that thread to the application. Instead callbacks to SpotterListeners should be invoked via the Eventsystem.notifyTransientEvent() method, so that the callbacks get run through the EventSystem thread.

Specified by:
startScanning in interface Spotter
See Also:
Spotter.startScanning()

stopScanning

public abstract void stopScanning()
Description copied from interface: Spotter
Stops a currently running background scan started from either scanOnce or startScanning.

Specified by:
stopScanning in interface Spotter