Class GenericTimeStampedCache<T extends TimeStamped>
- java.lang.Object
-
- org.orekit.utils.GenericTimeStampedCache<T>
-
- Type Parameters:
T
- Type of the cached data.
- All Implemented Interfaces:
TimeStampedCache<T>
public class GenericTimeStampedCache<T extends TimeStamped> extends Object implements TimeStampedCache<T>
Generic thread-safe cache fortime-stamped
data.- Author:
- Luc Maisonobe
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_CACHED_SLOTS_NUMBER
Default number of independent cached time slots.
-
Constructor Summary
Constructors Constructor Description GenericTimeStampedCache(int maxNeighborsSize, int maxSlots, double maxSpan, double newSlotInterval, TimeStampedGenerator<T> generator)
Simple constructor.GenericTimeStampedCache(int maxNeighborsSize, int maxSlots, double maxSpan, double newSlotInterval, TimeStampedGenerator<T> generator, double overridingMeanStep)
Simple constructor with overriding minimum step.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
getEarliest()
Get the earliest entry in this cache.int
getEntries()
Get the total number of entries cached.int
getGenerateCalls()
Get the number of calls to the generate method.TimeStampedGenerator<T>
getGenerator()
Get the generator.int
getGetNeighborsCalls()
Get the number of calls to theTimeStampedCache.getNeighbors(AbsoluteDate)
method.T
getLatest()
Get the latest entry in this cache.int
getMaxNeighborsSize()
Get the maximum size of the lists returned byTimeStampedCache.getNeighbors(AbsoluteDate, int)
.int
getMaxSlots()
Get the maximum number of independent cached time slots.double
getMaxSpan()
Get the maximum duration span in seconds of one slot.Stream<T>
getNeighbors(AbsoluteDate central, int n)
Get the entries surrounding a central date.double
getNewSlotQuantumGap()
Get quantum gap above which a new slot is created instead of extending an existing one.int
getSlots()
Get the number of slots in use.int
getSlotsEvictions()
Get the number of slots evictions.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.orekit.utils.TimeStampedCache
getNeighbors
-
-
-
-
Field Detail
-
DEFAULT_CACHED_SLOTS_NUMBER
public static final int DEFAULT_CACHED_SLOTS_NUMBER
Default number of independent cached time slots.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GenericTimeStampedCache
public GenericTimeStampedCache(int maxNeighborsSize, int maxSlots, double maxSpan, double newSlotInterval, TimeStampedGenerator<T> generator)
Simple constructor.- Parameters:
maxNeighborsSize
- maximum size of the arrays to be returned bygetNeighbors(AbsoluteDate, int)
, must be at least 2maxSlots
- maximum number of independent cached time slotsmaxSpan
- maximum duration span in seconds of one slot (can be set toDouble.POSITIVE_INFINITY
if desired)newSlotInterval
- time interval above which a new slot is created instead of extending an existing onegenerator
- generator to use for yet non-existent data
-
GenericTimeStampedCache
public GenericTimeStampedCache(int maxNeighborsSize, int maxSlots, double maxSpan, double newSlotInterval, TimeStampedGenerator<T> generator, double overridingMeanStep)
Simple constructor with overriding minimum step.- Parameters:
maxNeighborsSize
- maximum size of the arrays to be returned bygetNeighbors(AbsoluteDate, int)
, must be at least 2maxSlots
- maximum number of independent cached time slotsmaxSpan
- maximum duration span in seconds of one slot (can be set toDouble.POSITIVE_INFINITY
if desired)newSlotInterval
- time interval above which a new slot is created instead of extending an existing onegenerator
- generator to use for yet non-existent dataoverridingMeanStep
- overriding mean step designed for non-homogeneous tabulated values. To be used for example when caching monthly tabulated values. UseDouble.NaN
otherwise.- Throws:
OrekitIllegalArgumentException
- if :- neighbors size < 2
- maximum allowed number of slots < 1
- minimum step ≤ 0
-
-
Method Detail
-
getGenerator
public TimeStampedGenerator<T> getGenerator()
Get the generator.- Returns:
- generator
-
getMaxSlots
public int getMaxSlots()
Get the maximum number of independent cached time slots.- Returns:
- maximum number of independent cached time slots
-
getMaxSpan
public double getMaxSpan()
Get the maximum duration span in seconds of one slot.- Returns:
- maximum duration span in seconds of one slot
-
getNewSlotQuantumGap
public double getNewSlotQuantumGap()
Get quantum gap above which a new slot is created instead of extending an existing one.The quantum gap is the
newSlotInterval
value provided at construction rounded to the nearest quantum step used internally by the cache.- Returns:
- quantum gap in seconds
-
getGetNeighborsCalls
public int getGetNeighborsCalls()
Get the number of calls to theTimeStampedCache.getNeighbors(AbsoluteDate)
method.This number of calls is used as a reference to interpret
getGenerateCalls()
.- Returns:
- number of calls to the
TimeStampedCache.getNeighbors(AbsoluteDate)
method - See Also:
getGenerateCalls()
-
getGenerateCalls
public int getGenerateCalls()
Get the number of calls to the generate method.This number of calls is related to the number of cache misses and may be used to tune the cache configuration. Each cache miss implies at least one call is performed, but may require several calls if the new date is far offset from the existing cache, depending on the number of elements and step between elements in the arrays returned by the generator.
- Returns:
- number of calls to the generate method
- See Also:
getGetNeighborsCalls()
-
getSlotsEvictions
public int getSlotsEvictions()
Get the number of slots evictions.This number should remain small when the max number of slots is sufficient with respect to the number of concurrent requests to the cache. If it increases too much, then the cache configuration is probably bad and cache does not really improve things (in this case, the
number of calls to the generate method
will probably increase too.- Returns:
- number of slots evictions
-
getSlots
public int getSlots()
Get the number of slots in use.- Returns:
- number of slots in use
-
getEntries
public int getEntries()
Get the total number of entries cached.- Returns:
- total number of entries cached
-
getEarliest
public T getEarliest() throws IllegalStateException
Get the earliest entry in this cache.- Specified by:
getEarliest
in interfaceTimeStampedCache<T extends TimeStamped>
- Returns:
- earliest cached entry
- Throws:
IllegalStateException
- if this cache is empty
-
getLatest
public T getLatest() throws IllegalStateException
Get the latest entry in this cache.- Specified by:
getLatest
in interfaceTimeStampedCache<T extends TimeStamped>
- Returns:
- latest cached entry
- Throws:
IllegalStateException
- if this cache is empty
-
getMaxNeighborsSize
public int getMaxNeighborsSize()
Get the maximum size of the lists returned byTimeStampedCache.getNeighbors(AbsoluteDate, int)
.- Specified by:
getMaxNeighborsSize
in interfaceTimeStampedCache<T extends TimeStamped>
- Returns:
- size of the list
-
getNeighbors
public Stream<T> getNeighbors(AbsoluteDate central, int n)
Get the entries surrounding a central date.If the central date is well within covered range, the returned array will be balanced with half the points before central date and half the points after it (depending on n parity, of course). If the central date is near the boundary, then the returned array will be unbalanced and will contain only the n earliest (or latest) entries. A typical example of the later case is leap seconds cache, since the number of leap seconds cannot be arbitrarily increased.
This method is safe for multiple threads to execute concurrently.
- Specified by:
getNeighbors
in interfaceTimeStampedCache<T extends TimeStamped>
- Parameters:
central
- central daten
- number of neighbors (cannot exceedTimeStampedCache.getMaxNeighborsSize()
)- Returns:
- stream of cached entries surrounding the specified date.
-
-