org.android.activityminer.logic.devices
Class AccelerometerDataCache

Package class diagram package AccelerometerDataCache
java.lang.Object
  extended by org.android.activityminer.logic.util.AbstractActivatableComponentImpl
      extended by org.android.activityminer.logic.devices.AccelerometerDataCache
All Implemented Interfaces:
ObservableEventSource<SampleGapErrorEvent>, ObserverRegistration<SampleGapErrorEvent>, ActivatableComponent

public class AccelerometerDataCache
extends AbstractActivatableComponentImpl
implements ObservableEventSource<SampleGapErrorEvent>

The data cache to hold accelerometer samples for scanner polls.


Nested Class Summary
private  class AccelerometerDataCache.CacheData
          The cache data
 
Field Summary
protected  ConcurrentLinkedQueue<AccelerometerDataCache.CacheData> cache
          The sample cache.
private  AccelerometerDataCache.CacheData lastTakenSample
          Last taken sample.
private  long maxToleratedGap
          The maximum tolerated gap for samples before an error notification is fired
private  ObservableEventSource<SampleGapErrorEvent> observableGapErrorSource
          The event source to delegate signaling of sample gap errors to.
 
Constructor Summary
AccelerometerDataCache(long sampleRate)
          Constructor
 
Method Summary
 void add(double[] currentData, long ts)
          Does add a new sample to the cache.
 boolean hasObservers()
           
 void notify(SampleGapErrorEvent data)
           
protected  void onActivationStateChange(boolean active)
          Handler for activation state changes
 void registerEventObserver(EventObserver<? extends SampleGapErrorEvent> observer)
           
 void removeAllObservers()
           
 double[] takeSample(long ts)
          Does return the closest sample data from cache
 void unregisterEventObserver(EventObserver<? extends SampleGapErrorEvent> observer)
           
 
Methods inherited from class org.android.activityminer.logic.util.AbstractActivatableComponentImpl
isActive, setActivationState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxToleratedGap

private final long maxToleratedGap
The maximum tolerated gap for samples before an error notification is fired


lastTakenSample

private final AccelerometerDataCache.CacheData lastTakenSample
Last taken sample.


observableGapErrorSource

private final ObservableEventSource<SampleGapErrorEvent> observableGapErrorSource
The event source to delegate signaling of sample gap errors to.


cache

protected final ConcurrentLinkedQueue<AccelerometerDataCache.CacheData> cache
The sample cache.

Constructor Detail

AccelerometerDataCache

public AccelerometerDataCache(long sampleRate)
Constructor

Parameters:
sampleRate - the configured sample rate
Method Detail

takeSample

public final double[] takeSample(long ts)
Does return the closest sample data from cache

Parameters:
ts - the time stamp
Returns:
the sample data for the given time stamp

onActivationStateChange

protected final void onActivationStateChange(boolean active)
Description copied from class: AbstractActivatableComponentImpl
Handler for activation state changes

Specified by:
onActivationStateChange in class AbstractActivatableComponentImpl
Parameters:
active - the new activation state

add

public final void add(double[] currentData,
                      long ts)
Does add a new sample to the cache.

Parameters:
currentData - the accelerometer data to add
ts - the original sample time stamp

registerEventObserver

public final void registerEventObserver(EventObserver<? extends SampleGapErrorEvent> observer)
Specified by:
registerEventObserver in interface ObserverRegistration<SampleGapErrorEvent>

unregisterEventObserver

public final void unregisterEventObserver(EventObserver<? extends SampleGapErrorEvent> observer)
Specified by:
unregisterEventObserver in interface ObserverRegistration<SampleGapErrorEvent>

removeAllObservers

public final void removeAllObservers()
Specified by:
removeAllObservers in interface ObserverRegistration<SampleGapErrorEvent>

notify

public final void notify(SampleGapErrorEvent data)
Specified by:
notify in interface ObservableEventSource<SampleGapErrorEvent>

hasObservers

public final boolean hasObservers()
Specified by:
hasObservers in interface ObservableEventSource<SampleGapErrorEvent>