org.orekit.utils
Class TimeStampedCache<T extends TimeStamped>

java.lang.Object
  extended by org.orekit.utils.TimeStampedCache<T>
Type Parameters:
T - Type of the cached data.

public class TimeStampedCache<T extends TimeStamped>
extends Object

Generic thread-safe cache for time-stamped data.

Author:
Luc Maisonobe

Field Summary
static int DEFAULT_CACHED_SLOTS_NUMBER
          Default number of independent cached time slots.
 
Constructor Summary
TimeStampedCache(int neighborsSize, int maxSlots, double maxSpan, double newSlotInterval, TimeStampedGenerator<T> generator, Class<T> entriesClass)
          Simple constructor.
 
Method Summary
 T getEarliest()
          Get the earliest cached entry.
 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.
 T getLatest()
          Get the latest cached entry.
 int getMaxSlots()
          Get the maximum number of independent cached time slots.
 double getMaxSpan()
          Get the maximum duration span in seconds of one slot.
 T[] getNeighbors(AbsoluteDate central)
          Get the entries surrounding a central date.
 int getNeighborsSize()
          Get the fixed size of the arrays to be returned by getNeighbors(AbsoluteDate).
 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
 

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

TimeStampedCache

public TimeStampedCache(int neighborsSize,
                        int maxSlots,
                        double maxSpan,
                        double newSlotInterval,
                        TimeStampedGenerator<T> generator,
                        Class<T> entriesClass)
Simple constructor.

Parameters:
neighborsSize - fixed size of the arrays to be returned by getNeighbors(AbsoluteDate), must be at least 2
maxSlots - maximum number of independent cached time slots
maxSpan - maximum duration span in seconds of one slot (can be set to Double.POSITIVE_INFINITY if desired)
newSlotInterval - time interval above which a new slot is created instead of extending an existing one
generator - generator to use for yet non-existent data
entriesClass - class of the cached entries
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

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

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 cached entry.

Returns:
earliest cached entry
Throws:
IllegalStateException - if the cache has no slots at all
See Also:
getSlots()

getLatest

public T getLatest()
                                throws IllegalStateException
Get the latest cached entry.

Returns:
latest cached entry
Throws:
IllegalStateException - if the cache has no slots at all
See Also:
getSlots()

getNeighborsSize

public int getNeighborsSize()
Get the fixed size of the arrays to be returned by getNeighbors(AbsoluteDate).

Returns:
size of the array

getNeighbors

public T[] getNeighbors(AbsoluteDate central)
                                     throws TimeStampedCacheException
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 generator range boundary, then the returned array will be unbalanced and will contain only the n earliest (or latest) generated (and cached) entries. A typical example of the later case is leap seconds cache, since the number of leap seconds cannot be arbitrarily increased.

Parameters:
central - central date
Returns:
array of cached entries surrounding specified date (the size of the array is fixed to the one specified in the constructor)
Throws:
TimeStampedCacheException - if entries are not chronologically sorted or if new data cannot be generated
See Also:
getEarliest(), getLatest()


Copyright © 2017 CNES. All Rights Reserved.