de.unikassel.android.sdcframework.transmission
Class SampleGatheringController

Package class diagram package SampleGatheringController
java.lang.Object
  extended by de.unikassel.android.sdcframework.transmission.SampleGatheringController
All Implemented Interfaces:
SampleRateChangeResponder, UpdatableTransmissionComponent<TransmissionConfiguration>

public class SampleGatheringController
extends Object
implements UpdatableTransmissionComponent<TransmissionConfiguration>, SampleRateChangeResponder

A class to realize a controller for the task to select samples from the database for transfer.

It does control the available sample count in database and calculates the necessary wait time to reach the required minimum sample count.
The available count of samples for is limited by a configurable minimum and maximum.
The wait time calculation does depend on the current sample rate and the required minimum of samples.


Field Summary
private static float AF
          The amplification factor
private  AtomicLong availableSampleCount
          The available sample count in database
private  long lastRecordCount
          The last record count in database
private  AtomicLong lastTimeStamp
          The internal time stamp of last wait time calculation
private static long MAX_FREQUENCY
          The upper limit for wait times in milliseconds
private  AtomicInteger maxSampleCount
          The maximum sample count to transfer
private static long MIN_FREQUENCY
          The lower limit for wait times in milliseconds
private  AtomicInteger minSampleCount
          The minimum sample count to transfer
private static long SAMPLE_RATE_DELAY
          The delay for sample rate calculation in case of a rate change
private  boolean sampleRateHasChanged
          Flag indicating a sample rate change
 
Constructor Summary
SampleGatheringController()
          Constructor
 
Method Summary
private  long calculateNewWaitTime(long sampleIncrement, long timeInterval)
          Method to calculate an updated time to wait for samples
 long calculatetWaitTime(long currentRecordCount)
          Does calculate the necessary wait time depending on the current record count in database
 void consumAvailableSamples()
          Method to consume available samples
 long getAvailableSampleCount()
          Getter for the count of available samples
 int getMaxSampleCount()
          Getter for the maximum sample count to transfer
 int getMinSampleCount()
          Getter for the minimum sample count to transfer
 long getMissingSampleCount()
          Method to determine the current missing sample count
 void onSampleRateChanged()
          Method to react on signaled sample rate changes
 void reset(long currentRecordCount)
          Does reset all values
 void updateConfiguration(Context context, TransmissionConfiguration config)
          Method to update the component by a configuration
private  void updateFields(long currentRecordCount, long timeStamp)
          Method to calculate the available sample count for collecting task
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AF

private static final float AF
The amplification factor

See Also:
Constant Field Values

MAX_FREQUENCY

private static final long MAX_FREQUENCY
The upper limit for wait times in milliseconds

See Also:
Constant Field Values

MIN_FREQUENCY

private static final long MIN_FREQUENCY
The lower limit for wait times in milliseconds

See Also:
Constant Field Values

SAMPLE_RATE_DELAY

private static final long SAMPLE_RATE_DELAY
The delay for sample rate calculation in case of a rate change

See Also:
Constant Field Values

lastTimeStamp

private final AtomicLong lastTimeStamp
The internal time stamp of last wait time calculation


minSampleCount

private final AtomicInteger minSampleCount
The minimum sample count to transfer


maxSampleCount

private final AtomicInteger maxSampleCount
The maximum sample count to transfer


availableSampleCount

private final AtomicLong availableSampleCount
The available sample count in database


lastRecordCount

private long lastRecordCount
The last record count in database


sampleRateHasChanged

private boolean sampleRateHasChanged
Flag indicating a sample rate change

Constructor Detail

SampleGatheringController

public SampleGatheringController()
Constructor

Method Detail

reset

public final void reset(long currentRecordCount)
Does reset all values

Parameters:
currentRecordCount - the current record count in database

getMinSampleCount

public final int getMinSampleCount()
Getter for the minimum sample count to transfer

Returns:
the minimum sample count to transfer

getMaxSampleCount

public final int getMaxSampleCount()
Getter for the maximum sample count to transfer

Returns:
the maximum sample count to transfer

getAvailableSampleCount

public final long getAvailableSampleCount()
Getter for the count of available samples

Returns:
the count of available samples

consumAvailableSamples

public final void consumAvailableSamples()
Method to consume available samples


updateConfiguration

public final void updateConfiguration(Context context,
                                      TransmissionConfiguration config)
Description copied from interface: UpdatableTransmissionComponent
Method to update the component by a configuration

Specified by:
updateConfiguration in interface UpdatableTransmissionComponent<TransmissionConfiguration>
Parameters:
context - the application context
config - the configuration to update from

calculatetWaitTime

public final long calculatetWaitTime(long currentRecordCount)
Does calculate the necessary wait time depending on the current record count in database

Parameters:
currentRecordCount - the current record count in database
Returns:
the current wait time

calculateNewWaitTime

private final long calculateNewWaitTime(long sampleIncrement,
                                        long timeInterval)
Method to calculate an updated time to wait for samples

Parameters:
sampleIncrement - the current sample increment
timeInterval - the current time interval the current error
Returns:
the new calculated time in milliseconds

getMissingSampleCount

public final long getMissingSampleCount()
Method to determine the current missing sample count

Returns:
the current missing sample count

updateFields

private final void updateFields(long currentRecordCount,
                                long timeStamp)
Method to calculate the available sample count for collecting task

Parameters:
currentRecordCount - the current record count in database
timeStamp - the current time stamp

onSampleRateChanged

public final void onSampleRateChanged()
Description copied from interface: SampleRateChangeResponder
Method to react on signaled sample rate changes

Specified by:
onSampleRateChanged in interface SampleRateChangeResponder