Class BeaconCacheImpl

  • All Implemented Interfaces:
    BeaconCache

    public class BeaconCacheImpl
    extends java.util.Observable
    implements BeaconCache
    Class used in OpenKit to cache serialized 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 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: BeaconCache
        Add event data for a given key to this cache.

        All registered observers are notified, after the event data has been added.

        Specified by:
        addEventData in interface BeaconCache
        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: BeaconCache
        Add action data for a given beaconID to this cache.
        Specified by:
        addActionData in interface BeaconCache
        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: BeaconCache
        Delete a cache entry for a given key.
        Specified by:
        deleteCacheEntry in interface BeaconCache
        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: BeaconCache
        Prepare all data, that has been recorded so far, for sending.

        Note: This method must only be invoked from the beacon sending thread.

        Specified by:
        prepareDataForSending in interface BeaconCache
        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: BeaconCache
        Test if there is more data to send.
        Specified by:
        hasDataForSending in interface BeaconCache
        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:
        true if there is data for sending, false if BeaconKey does 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: BeaconCache
        Get the next chunk for sending to the backend.

        Note: This method must only be invoked from the beacon sending thread.

        Specified by:
        getNextBeaconChunk in interface BeaconCache
        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:
        null if given key does not exist, an empty string, if there is no more data to send or the next chunk to send.
      • resetChunkedData

        public void resetChunkedData​(BeaconKey key)
        Description copied from interface: BeaconCache
        Reset all data that was previously included in chunks.

        Note: This method must only be invoked from the beacon sending thread.

        Specified by:
        resetChunkedData in interface BeaconCache
        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: BeaconCache
        Get a Set of currently inserted BeaconKeys.

        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:
        getBeaconKeys in interface BeaconCache
        Returns:
        Snapshot of all beacon keys in the cache.
      • evictRecordsByAge

        public int evictRecordsByAge​(BeaconKey key,
                                     long minTimestamp)
        Description copied from interface: BeaconCache
        Evict beacon cache records by age for a given beacon.
        Specified by:
        evictRecordsByAge in interface BeaconCache
        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: BeaconCache
        Evict beacon cache records by number for given beacon.
        Specified by:
        evictRecordsByNumber in interface BeaconCache
        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: BeaconCache
        Get number of bytes currently stored in cache.
        Specified by:
        getNumBytesInCache in interface BeaconCache
        Returns:
        Number of bytes currently stored in cache.
      • isEmpty

        public boolean isEmpty​(BeaconKey key)
        Description copied from interface: BeaconCache
        Tests if an cached entry for key is empty.
        Specified by:
        isEmpty in interface BeaconCache
        Parameters:
        key - The key identifying a beacon.
        Returns:
        true if the cached entry is empty, false otherwise.