Class DatumHistory
This class maintains a fixed-size history of NodeDatum at various
time levels:
- raw
- Individual datum stored as-is.
Note that no time-based ordering of datum is maintained by this class.
They are maintained simply by insertion time, i.e. the time when
#add(Datum) is invoked. Concurrent invocation of #add(Datum)
is allowed, but the order of the added elements is undefined in that case.
- Since:
- 1.89
- Version:
- 1.2
- Author:
- matt
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DatumHistory.ConfigurationA default configuration instance. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.DatumHistory(DatumHistory.Configuration config, float loadFactor, int concurrencyLevel) Constructor.DatumHistory(DatumHistory.Configuration config, ConcurrentMap<String, Queue<NodeDatum>> raw) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a datum.Get the configuration.latest()Get anIterableover the latest available raw datum.Get the latest datum available with a given source ID.offset(int offset) Get anIterableover an offset from the latest available raw datum.Get the datum offset from the latest available raw datum for a given source ID.Get the datum offset from a given timestamp for a given source ID.Get anIterableover an offset from a datum offset from a given timestamp.Get a slice of a source ID's history.Get a slice of a source ID's history.
-
Field Details
-
DEFAULT_CONFIG
A default configuration instance.
-
-
Constructor Details
-
DatumHistory
Constructor.A default load factory and concurrency level will be used.
- Parameters:
config- the configuration to use
-
DatumHistory
Constructor.- Parameters:
config- the configuration to useloadFactor- a load factor to use for sizing the internal data structuresconcurrencyLevel- a concurrency level to use for sizing the internal data structures- Throws:
IllegalArgumentException- ifconfigis null
-
DatumHistory
Constructor.- Parameters:
config- the configuration to useraw- a map to use for raw datum- Throws:
IllegalArgumentException- ifconfigis null
-
-
Method Details
-
add
Add a datum.If
datumis null or does not have a source ID or creation date, nothing will be added.- Parameters:
datum- the datum to add
-
latest
Get anIterableover the latest available raw datum.This is equivalent to calling
offset(0).- Returns:
- the
Iterable, never null - See Also:
-
latest
Get the latest datum available with a given source ID.This is equivalent to calling
offset(sourceId, 0).- Parameters:
sourceId- the source ID to find- Returns:
- the datum, or null
- See Also:
-
offset
Get anIterableover an offset from the latest available raw datum.An offset of 0 means the latest datum, and 1 means the one before the latest datum, and so on.
- Parameters:
offset- the offset from the latest, 0 being the latest and 1 the next later, and so on- Returns:
- the
Iterable, never null - Since:
- 1.1
-
offset
Get the datum offset from the latest available raw datum for a given source ID.An offset of 0 means the latest datum, and 1 means the one before the latest datum, and so on.
- Parameters:
sourceId- the source ID to findoffset- the offset from the latest, 0 being the latest and 1 the next later, and so on- Returns:
- the
Iterable, never null - Since:
- 1.1
-
offset
Get anIterableover an offset from a datum offset from a given timestamp.An offset of 0 means the datum closest before or equal to the given timestamp, and 1 means the next one before that, and so on. Note that no sorting of datum is performed by this method: it assumes elements have been added in ascending timestamp order already.
- Parameters:
timestamp- the timestamp to offset fromoffset- the offset fromtimestamp, 0 being the latest and 1 the next later, and so on- Returns:
- the
Iterable, never null - Since:
- 1.1
-
offset
Get the datum offset from a given timestamp for a given source ID.An offset of 0 means the datum closest before or equal to the given timestamp, and 1 means the next one before that, and so on. Note that no sorting of datum is performed by this method: it assumes elements have been added in ascending timestamp order already.
- Parameters:
sourceId- the source ID to findtimestamp- the timestamp to offset fromoffset- the offset from the latest, 0 being the latest and 1 the next later, and so on- Returns:
- the datum, or null if no such datum is available
- Since:
- 1.1
-
slice
Get a slice of a source ID's history.- Parameters:
sourceId- the source ID to findoffset- the offset from the latest, 0 being the latest and 1 the next later, and so oncount- the maximum number of datum to return, starting fromoffsetand iterating over earlier datum; the actual number returned will be limited by the configuration of this instance as well as the number of datum that have been captured- Returns:
- the history, ordered from oldest to newest
- Since:
- 1.2
-
slice
Get a slice of a source ID's history.- Parameters:
sourceId- the source ID to findtimestamp- the timestamp to offset fromoffset- the offset from the latest, 0 being the latest and 1 the next later, and so oncount- the maximum number of datum to return, starting fromoffsetand iterating over earlier datum; the actual number returned will be limited by the configuration of this instance as well as the number of datum that have been captured- Returns:
- the history, ordered from oldest to newest
- Since:
- 1.2
-
getConfig
Get the configuration.- Returns:
- the configuration, never null
-