public class TelemetryBuffer<T>
extends java.lang.Object
Telemetry
It is responsible for managing the buffers. Once a new buffer is created it will schedule a call to
pick up the buffer.
If the buffer is full before the timeout expired, it will initiate a 'send now' activity to send the buffer asap.
The class is responsible for handing the corner cases that might rise
Created by gupele on 12/17/2014.| Constructor and Description |
|---|
TelemetryBuffer(TelemetriesTransmitter<T> sender,
LimitsEnforcer maxTelemetriesInBatchEnforcer,
LimitsEnforcer transmitBufferTimeoutInSecondsEnforcer)
The constructor needs to get the 'sender' we work with
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(T telemetry)
The method will add the incoming
Telemetry to its internal container of Telemetries
If that is the first instance in the container, we schedule a 'pick-up' in a configurable amount of time
If by adding that item we exceeded the maximum number of instances, we trigger a send request now. |
void |
flush()
The method will flush the telemetries currently in the buffer to the
TelemetriesTransmitter |
int |
getMaxTelemetriesInBatch()
Gets the maximum number of telemetries in a batch
|
int |
getTransmitBufferTimeoutInSeconds()
Gets the transmit buffer timeout in seconds
|
void |
setMaxTelemetriesInBatch(int value)
Sets the maximum number of telemetries in a batch
|
void |
setTransmitBufferTimeoutInSeconds(int value)
Sets the transmit buffer timeout in seconds
|
public TelemetryBuffer(TelemetriesTransmitter<T> sender, LimitsEnforcer maxTelemetriesInBatchEnforcer, LimitsEnforcer transmitBufferTimeoutInSecondsEnforcer)
sender - The sender object for transmitting the telemetriesmaxTelemetriesInBatchEnforcer - For getting the number of maximum number of telemetries in a batch within limitstransmitBufferTimeoutInSecondsEnforcer - For getting the number of transmit buffer timeout in seconds within limitspublic void setMaxTelemetriesInBatch(int value)
value - The max amount of Telemetries that are allowed in a batch.public int getMaxTelemetriesInBatch()
public void setTransmitBufferTimeoutInSeconds(int value)
value - The amount of time to wait before sending the buffer.public int getTransmitBufferTimeoutInSeconds()
public void add(T telemetry)
Telemetry to its internal container of Telemetries
If that is the first instance in the container, we schedule a 'pick-up' in a configurable amount of time
If by adding that item we exceeded the maximum number of instances, we trigger a send request now.
Note that a lock is used to make sure we avoid race conditions and to make sure that we cleanly
move from a ready to send buffer to a new onetelemetry - The Telemetry to add to the buffer.public void flush()
TelemetriesTransmitter