org.android.activityminer.model.timeseries
Class SensorObservationCache<T extends Enum<T> & Dimensions,U>

Package class diagram package SensorObservationCache
java.lang.Object
  extended by org.android.activityminer.logic.util.AbstractActivatableComponentImpl
      extended by org.android.activityminer.model.timeseries.SensorObservationCache<T,U>
Type Parameters:
T - the enumeration type for the dimensions
U - the data type for the dimension values
All Implemented Interfaces:
SensorDataSource<SensorObservation<T,U>>, ActivatableComponent

public class SensorObservationCache<T extends Enum<T> & Dimensions,U>
extends AbstractActivatableComponentImpl
implements SensorDataSource<SensorObservation<T,U>>

Cache for sensor observations.


Field Summary
protected  ConcurrentLinkedQueue<SensorObservation<T,U>> cache
          The sample cache.
private  SensorObservation<T,U> lastObservation
          The last scanned sensor observation.
private  long lastObservationOrgTs
          Last observation original time stamp.
private  long maxToleratedGap
          The maximum tolerated gap for samples before an error notification is fired
 
Constructor Summary
SensorObservationCache()
          Constructor
 
Method Summary
 void add(SensorObservation<T,U> observation)
          Does add a new observation to the cache.
 boolean isEmpty()
          Checks if is empty.
protected  void onActivationStateChange(boolean active)
          Handler for activation state changes
 void onDestroy()
          This method is for cleanup in case of termination.
 List<SensorObservation<T,U>> removeObservations()
          Does remove and returns all observations in the cache.
 SensorObservation<T,U> takeSample(Long ts)
          Getter for the current sample
 
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


lastObservation

private SensorObservation<T extends Enum<T> & Dimensions,U> lastObservation
The last scanned sensor observation.


lastObservationOrgTs

private long lastObservationOrgTs
Last observation original time stamp.


cache

protected final ConcurrentLinkedQueue<SensorObservation<T extends Enum<T> & Dimensions,U>> cache
The sample cache.

Constructor Detail

SensorObservationCache

public SensorObservationCache()
Constructor

Method Detail

takeSample

public SensorObservation<T,U> takeSample(Long ts)
Description copied from interface: SensorDataSource
Getter for the current sample

Specified by:
takeSample in interface SensorDataSource<SensorObservation<T extends Enum<T> & Dimensions,U>>
Parameters:
ts - the requested time stamp
Returns:
the current sample

isEmpty

public final boolean isEmpty()
Checks if is empty.

Returns:
true, if is empty

removeObservations

public List<SensorObservation<T,U>> removeObservations()
Does remove and returns all observations in the cache.

Returns:
all observations in the cache

add

public final void add(SensorObservation<T,U> observation)
Does add a new observation to the cache.

Parameters:
observation - the observation to add

onDestroy

public void onDestroy()
Description copied from interface: SensorDataSource
This method is for cleanup in case of termination.

Specified by:
onDestroy in interface SensorDataSource<SensorObservation<T extends Enum<T> & Dimensions,U>>

onActivationStateChange

protected 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