Class BeaconCacheImpl
- java.lang.Object
-
- java.util.Observable
-
- com.dynatrace.openkit.core.caching.BeaconCacheImpl
-
- All Implemented Interfaces:
BeaconCache
public class BeaconCacheImpl extends java.util.Observable implements BeaconCache
Class used in OpenKit to cache serializedBeacondata.This cache needs to deal with high concurrency, since it's possible that a lot of threads insert new data concurrently. Furthermore two OpenKit internal threads are also accessing the cache.
-
-
Constructor Summary
Constructors Constructor Description BeaconCacheImpl(Logger logger)Create BeaconCache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddActionData(BeaconKey key, long timestamp, java.lang.String data)Add action data for a givenbeaconIDto this cache.voidaddEventData(BeaconKey key, long timestamp, java.lang.String data)Add event data for a givenkeyto this cache.voiddeleteCacheEntry(BeaconKey key)Delete a cache entry for a givenkey.intevictRecordsByAge(BeaconKey key, long minTimestamp)Evictbeacon cache recordsby age for a given beacon.intevictRecordsByNumber(BeaconKey key, int numRecords)Evictbeacon cache recordsby number for given beacon.java.lang.String[]getActions(BeaconKey key)Get a shallow copy of actions collected so far.java.util.Set<BeaconKey>getBeaconKeys()Get a Set of currently insertedBeaconKeys.java.lang.String[]getEvents(BeaconKey key)Get a shallow copy of events collected so far.java.lang.StringgetNextBeaconChunk(BeaconKey key, java.lang.String chunkPrefix, int maxSize, char delimiter)Get the next chunk for sending to the backend.longgetNumBytesInCache()Get number of bytes currently stored in cache.booleanhasDataForSending(BeaconKey key)Test if there is more data to send.booleanisEmpty(BeaconKey key)Tests if an cached entry forkeyis empty.voidprepareDataForSending(BeaconKey key)Prepare all data, that has been recorded so far, for sending.voidremoveChunkedData(BeaconKey key)Remove all data that was previously included in chunks.voidresetChunkedData(BeaconKey key)Reset all data that was previously included in chunks.-
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.dynatrace.openkit.core.caching.BeaconCache
addObserver
-
-
-
-
Constructor Detail
-
BeaconCacheImpl
public BeaconCacheImpl(Logger logger)
Create BeaconCache.- Parameters:
logger- For trace messages.
-
-
Method Detail
-
addEventData
public void addEventData(BeaconKey key, long timestamp, java.lang.String data)
Description copied from interface:BeaconCacheAdd event data for a givenkeyto this cache.All registered observers are notified, after the event data has been added.
- Specified by:
addEventDatain interfaceBeaconCache- Parameters:
key- The key of the beacon (aka Session ID and Session seq. no.) for which to add event data.timestamp- The data's timestamp.data- serialized event data to add.
-
addActionData
public void addActionData(BeaconKey key, long timestamp, java.lang.String data)
Description copied from interface:BeaconCacheAdd action data for a givenbeaconIDto this cache.- Specified by:
addActionDatain interfaceBeaconCache- Parameters:
key- The key of the beacon (aka Session ID and Session seq. no.) for which to add action data.timestamp- The data's timestamp.data- serialized action data to add.
-
deleteCacheEntry
public void deleteCacheEntry(BeaconKey key)
Description copied from interface:BeaconCacheDelete a cache entry for a givenkey.- Specified by:
deleteCacheEntryin interfaceBeaconCache- Parameters:
key- The beacon's ID (aka Session ID and Session seq. no.) which to delete.
-
prepareDataForSending
public void prepareDataForSending(BeaconKey key)
Description copied from interface:BeaconCachePrepare all data, that has been recorded so far, for sending.Note: This method must only be invoked from the beacon sending thread.
- Specified by:
prepareDataForSendingin interfaceBeaconCache- Parameters:
key- The beacon's ID (aka Session ID and Session seq. no.) for which to copy the collected data.
-
hasDataForSending
public boolean hasDataForSending(BeaconKey key)
Description copied from interface:BeaconCacheTest if there is more data to send.- Specified by:
hasDataForSendingin interfaceBeaconCache- Parameters:
key- key The beacon's ID (aka Session ID and Session seq. no.) for which to test if there is more data to send.- Returns:
trueif there is data for sending,falseifBeaconKeydoes not exist or there is no data for sending.
-
getNextBeaconChunk
public java.lang.String getNextBeaconChunk(BeaconKey key, java.lang.String chunkPrefix, int maxSize, char delimiter)
Description copied from interface:BeaconCacheGet the next chunk for sending to the backend.Note: This method must only be invoked from the beacon sending thread.
- Specified by:
getNextBeaconChunkin interfaceBeaconCache- Parameters:
key- The key of the beacon for which to get the next chunk.chunkPrefix- Prefix to append to the beginning of the chunk.maxSize- Maximum chunk size. As soon as chunk's size is greater than or equal to maxSize result is returned.delimiter- Delimiter between consecutive chunks.- Returns:
nullif givenkeydoes not exist, an empty string, if there is no more data to send or the next chunk to send.
-
removeChunkedData
public void removeChunkedData(BeaconKey key)
Description copied from interface:BeaconCacheRemove all data that was previously included in chunks.This method must be called, when data retrieved via
BeaconCache.getNextBeaconChunk(BeaconKey, String, int, char)was successfully sent to the backend, otherwise subsequent calls toBeaconCache.getNextBeaconChunk(BeaconKey, String, int, char)will retrieve the same data again and again.Note: This method must only be invoked from the beacon sending thread.
- Specified by:
removeChunkedDatain interfaceBeaconCache- Parameters:
key- The key of the beacon for which to remove already chunked data.
-
resetChunkedData
public void resetChunkedData(BeaconKey key)
Description copied from interface:BeaconCacheReset all data that was previously included in chunks.Note: This method must only be invoked from the beacon sending thread.
- Specified by:
resetChunkedDatain interfaceBeaconCache- Parameters:
key- The key of the beacon for which to remove already chunked data.
-
getEvents
public java.lang.String[] getEvents(BeaconKey key)
Get a shallow copy of events collected so far.Although this method is intended for debugging purposes only, it still does appropriate locking.
- Parameters:
key- The key of the beacon for which to retrieve the events.- Returns:
- List of event data.
-
getActions
public java.lang.String[] getActions(BeaconKey key)
Get a shallow copy of actions collected so far.Although this method is intended for debugging purposes only, it still does appropriate locking.
- Parameters:
key- The key of the beacon for which to retrieve the events.- Returns:
- List of event data.
-
getBeaconKeys
public java.util.Set<BeaconKey> getBeaconKeys()
Description copied from interface:BeaconCacheGet a Set of currently insertedBeaconKeys.The return value is a snapshot of currently inserted beacon keys. All changes made after this call are not reflected in the returned Set.
- Specified by:
getBeaconKeysin interfaceBeaconCache- Returns:
- Snapshot of all beacon keys in the cache.
-
evictRecordsByAge
public int evictRecordsByAge(BeaconKey key, long minTimestamp)
Description copied from interface:BeaconCacheEvictbeacon cache recordsby age for a given beacon.- Specified by:
evictRecordsByAgein interfaceBeaconCache- Parameters:
key- The key identifying a beacon.minTimestamp- The minimum timestamp allowed.- Returns:
- Returns the number of evicted cache records.
-
evictRecordsByNumber
public int evictRecordsByNumber(BeaconKey key, int numRecords)
Description copied from interface:BeaconCacheEvictbeacon cache recordsby number for given beacon.- Specified by:
evictRecordsByNumberin interfaceBeaconCache- Parameters:
key- The key identifying a beacon beacon.numRecords- The maximum number of records to evict.- Returns:
- Returns the number of evicted cache records.
-
getNumBytesInCache
public long getNumBytesInCache()
Description copied from interface:BeaconCacheGet number of bytes currently stored in cache.- Specified by:
getNumBytesInCachein interfaceBeaconCache- Returns:
- Number of bytes currently stored in cache.
-
isEmpty
public boolean isEmpty(BeaconKey key)
Description copied from interface:BeaconCacheTests if an cached entry forkeyis empty.- Specified by:
isEmptyin interfaceBeaconCache- Parameters:
key- The key identifying a beacon.- Returns:
trueif the cached entry is empty,falseotherwise.
-
-