org.placelab.spotter
Class SyncSpotter

java.lang.Object
  extended byorg.placelab.spotter.AbstractSpotter
      extended byorg.placelab.spotter.SyncSpotter
All Implemented Interfaces:
Spotter
Direct Known Subclasses:
FakeSpotter, GSMSpotter, LogSpotter, RemoteGSMSpotter, WiFiSpotter

public abstract class SyncSpotter
extends AbstractSpotter

This convenience class provides the groundwork for Spotters whose implementations are most naturally synchronous. An example of such a Spotter is WiFiSpotter. Subclasses provide their own blocking getMeasurementImpl and the SyncSpotter uses that to offer up the asynchronous spotter interface for users of the Spotter.


Constructor Summary
SyncSpotter()
           
 
Method Summary
 void errorInBackgroundThreadAndThreadDeath(java.lang.Throwable t)
           
 Measurement getMeasurement()
          A blocking call to get a new Measurement.
protected abstract  Measurement getMeasurementImpl()
          Collects and returns a single Measurement.
protected abstract  long nextScanInterval()
           
protected  void scanUsingBackgroundThread(EventSystem evs)
           
protected  void scanUsingEventSystem(EventSystem evs)
           
 void startScanning()
          Start scanning for Measurements in the background and return the Measurements by notifying SpotterListeners with the SpotterListener.gotMeasurement(Spotter, Measurement) method.
 void startScanning(EventSystem evs)
          Start scanning for Measurements.
 void stopScanning()
          Stops a currently running background scan started from either scanOnce or startScanning.
 
Methods inherited from class org.placelab.spotter.AbstractSpotter
addListener, notifyEndOfScan, notifyEndOfScan, notifyGotException, notifyGotException, notifyGotMeasurement, notifyGotMeasurement, removeListener, scanOnce, scanOnce, waitForThread
 
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, open
 

Constructor Detail

SyncSpotter

public SyncSpotter()
Method Detail

nextScanInterval

protected abstract long nextScanInterval()
Returns:
the interval that the spotter should wait before invoking the next scan

getMeasurementImpl

protected abstract Measurement getMeasurementImpl()
                                           throws SpotterException
Collects and returns a single Measurement.

Throws:
SpotterException

getMeasurement

public Measurement getMeasurement()
                           throws SpotterException
Description copied from interface: Spotter
A blocking call to get a new Measurement. A spotter implementation may choose to just return the last cached Measurement, or go ahead and do a new scan and return the results of that scan. Note that the accuracy of timestamps returned by this usage model depends on the spotter implementation. You should not call this method while this Spotter is performing a continous scan. Doing so will result in a SpotterException being thrown.

Throws:
SpotterException

startScanning

public 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
Specified by:
startScanning in class AbstractSpotter

startScanning

public 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
Specified by:
startScanning in class AbstractSpotter

stopScanning

public 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
Specified by:
stopScanning in class AbstractSpotter

scanUsingBackgroundThread

protected void scanUsingBackgroundThread(EventSystem evs)

scanUsingEventSystem

protected void scanUsingEventSystem(EventSystem evs)

errorInBackgroundThreadAndThreadDeath

public void errorInBackgroundThreadAndThreadDeath(java.lang.Throwable t)