public class BeaconCacheImpl extends java.util.Observable implements BeaconCache
Beacon data.
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 and Description |
|---|
BeaconCacheImpl(Logger logger)
Create BeaconCache.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addActionData(java.lang.Integer beaconID,
long timestamp,
java.lang.String data)
Add action data for a given
beaconID to this cache. |
void |
addEventData(java.lang.Integer beaconID,
long timestamp,
java.lang.String data)
Add event data for a given
beaconID to this cache. |
void |
deleteCacheEntry(java.lang.Integer beaconID)
Delete a cache entry for a given
beaconID. |
int |
evictRecordsByAge(java.lang.Integer beaconID,
long minTimestamp)
Evict
beacon cache records by age for a given beacon. |
int |
evictRecordsByNumber(java.lang.Integer beaconID,
int numRecords)
Evict
beacon cache records by number for given beacon. |
java.lang.String[] |
getActions(java.lang.Integer beaconID)
Get a shallow copy of actions collected so far.
|
java.util.Set<java.lang.Integer> |
getBeaconIDs()
Get a Set of currently inserted Beacon ids.
|
java.lang.String[] |
getEvents(java.lang.Integer beaconID)
Get a shallow copy of events collected so far.
|
java.lang.String |
getNextBeaconChunk(java.lang.Integer beaconID,
java.lang.String chunkPrefix,
int maxSize,
char delimiter)
Get the next chunk for sending to the backend.
|
long |
getNumBytesInCache()
Get number of bytes currently stored in cache.
|
boolean |
isEmpty(java.lang.Integer beaconID)
Tests if an cached entry for
beaconID is empty. |
void |
removeChunkedData(java.lang.Integer beaconID)
Remove all data that was previously included in chunks.
|
void |
resetChunkedData(java.lang.Integer beaconID)
Reset all data that was previously included in chunks.
|
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChangedclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddObserverpublic BeaconCacheImpl(Logger logger)
logger - public void addEventData(java.lang.Integer beaconID,
long timestamp,
java.lang.String data)
BeaconCachebeaconID to this cache.
All registered observers are notified, after the event data has been added.
addEventData in interface BeaconCachebeaconID - The beacon's ID (aka Session ID) for which to add event data.timestamp - The data's timestamp.data - serialized event data to add.public void addActionData(java.lang.Integer beaconID,
long timestamp,
java.lang.String data)
BeaconCachebeaconID to this cache.addActionData in interface BeaconCachebeaconID - The beacon's ID (aka Session ID) for which to add action data.timestamp - The data's timestamp.data - serialized action data to add.public void deleteCacheEntry(java.lang.Integer beaconID)
BeaconCachebeaconID.deleteCacheEntry in interface BeaconCachebeaconID - The beacon's ID (aka Session ID) which to delete.public java.lang.String getNextBeaconChunk(java.lang.Integer beaconID,
java.lang.String chunkPrefix,
int maxSize,
char delimiter)
BeaconCacheNote: This method must only be invoked from the beacon sending thread.
getNextBeaconChunk in interface BeaconCachebeaconID - The beacon id 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.null if given beaconID does not exist, an empty string, if there is no more data to send
or the next chunk to send.public void removeChunkedData(java.lang.Integer beaconID)
BeaconCache
This method must be called, when data retrieved via BeaconCache.getNextBeaconChunk(Integer, String, int, char)
was successfully sent to the backend, otherwise subsequent calls to BeaconCache.getNextBeaconChunk(Integer, String, int, char)
will retrieve the same data again and again.
Note: This method must only be invoked from the beacon sending thread.
removeChunkedData in interface BeaconCachebeaconID - The beacon id for which to remove already chunked data.public void resetChunkedData(java.lang.Integer beaconID)
BeaconCacheNote: This method must only be invoked from the beacon sending thread.
resetChunkedData in interface BeaconCachebeaconID - The beacon id for which to remove already chunked data.public java.lang.String[] getEvents(java.lang.Integer beaconID)
Although this method is intended for debugging purposes only, it still does appropriate locking.
beaconID - The beacon id for which to retrieve the events.public java.lang.String[] getActions(java.lang.Integer beaconID)
Although this method is intended for debugging purposes only, it still does appropriate locking.
beaconID - The beacon id for which to retrieve the events.public java.util.Set<java.lang.Integer> getBeaconIDs()
BeaconCacheThe return value is a snapshot of currently inserted beacon ids. All changes made after this call are not reflected in the returned Set.
getBeaconIDs in interface BeaconCachepublic int evictRecordsByAge(java.lang.Integer beaconID,
long minTimestamp)
BeaconCachebeacon cache records by age for a given beacon.evictRecordsByAge in interface BeaconCachebeaconID - The beacon's identifier.minTimestamp - The minimum timestamp allowed.public int evictRecordsByNumber(java.lang.Integer beaconID,
int numRecords)
BeaconCachebeacon cache records by number for given beacon.evictRecordsByNumber in interface BeaconCachebeaconID - The beacon's identifier.numRecords - The maximum number of records to evict.public long getNumBytesInCache()
BeaconCachegetNumBytesInCache in interface BeaconCachepublic boolean isEmpty(java.lang.Integer beaconID)
BeaconCachebeaconID is empty.isEmpty in interface BeaconCachebeaconID - beaconID The beacon's identifier.true if the cached entry is empty, false otherwise.