tuwien.auto.calimero.buffer.cache
Class PositiveListCache

java.lang.Object
  extended by tuwien.auto.calimero.buffer.cache.ExpiringCache
      extended by tuwien.auto.calimero.buffer.cache.PositiveListCache
All Implemented Interfaces:
Cache

public class PositiveListCache
extends ExpiringCache

A static Cache using a positive list with allowed keys for the cache.

The positive list contains key objects which are allowed to be cached. On a put(CacheObject) operation, CacheObject.getKey() is checked for a positive match in that list in order to be allowed for caching.

This cache does not use a replacement policy (static cache).
Nevertheless, a timeout can be given to specify the expiring time of cache values.

The usage value of CacheObject.getUsage() equals the access count, CacheObject.getCount().


Nested Class Summary
 
Nested classes/interfaces inherited from interface tuwien.auto.calimero.buffer.cache.Cache
Cache.Statistic
 
Field Summary
 
Fields inherited from class tuwien.auto.calimero.buffer.cache.ExpiringCache
defaultSweepInterval, map, sweepInterval
 
Constructor Summary
PositiveListCache(java.util.Collection positiveList, int timeToExpire)
          Creates a new PositiveListCache and inits the positive key list.
PositiveListCache(int timeToExpire)
          Creates a new PositiveListCache.
 
Method Summary
 void addToPositiveList(java.lang.Object key)
          Adds a new allowed key to the positive list, if it is not already present.
 void clear()
          Empties the cache of all CacheObjects.
 CacheObject get(java.lang.Object key)
          Gets the CacheObject associated with key from the cache.
 java.lang.Object[] getPositiveList()
          Returns the positive list currently used by this cache.
 void put(CacheObject obj)
          For a CacheObject to be put into the cache, its key CacheObject.getKey() has to be equal to one in the positive list of this cache.
 void remove(java.lang.Object key)
          Removes the CacheObject associated with key from the cache, if found.
 void removeFromPositiveList(java.lang.Object key)
          Removes the key from the positive list, if it is present.
 void setPositiveList(java.util.Collection positiveList)
          Sets a new positive list for this cache.
 Cache.Statistic statistic()
          Returns information collected by this cache since its creation.
 
Methods inherited from class tuwien.auto.calimero.buffer.cache.ExpiringCache
notifyRemoved, removeExpired, startSweeper, stopSweeper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PositiveListCache

public PositiveListCache(java.util.Collection positiveList,
                         int timeToExpire)
Creates a new PositiveListCache and inits the positive key list.

Optionally, an expiring time can be specified.

Parameters:
positiveList - a Collection holding the allowed keys for this cache
timeToExpire - timespan in seconds for cache objects to stay valid, or 0 for no expiring

PositiveListCache

public PositiveListCache(int timeToExpire)
Creates a new PositiveListCache.

Optionally, an expiring time can be specified.

Parameters:
timeToExpire - timespan in seconds for cache objects to stay valid, or 0 for no expiring
Method Detail

addToPositiveList

public final void addToPositiveList(java.lang.Object key)
Adds a new allowed key to the positive list, if it is not already present.

Parameters:
key - the new key object

clear

public void clear()
Empties the cache of all CacheObjects.


This does not affect the positive list.


get

public CacheObject get(java.lang.Object key)
Description copied from interface: Cache
Gets the CacheObject associated with key from the cache.

If found, the access count of the CacheObject is incremented by 1.

Parameters:
key - key to search
Returns:
the CacheObject or null if key does not exist in the cache

getPositiveList

public final java.lang.Object[] getPositiveList()
Returns the positive list currently used by this cache.

Returns:
array of all allowed key objects.

put

public void put(CacheObject obj)
For a CacheObject to be put into the cache, its key CacheObject.getKey() has to be equal to one in the positive list of this cache.
If expiring of cache objects is set, and the timestamp of a CacheObject is renewed externally after it has been put into the cache, a new put(CacheObject) is required for that object to apply the new timestamp and keep the cache in a consistent state.

Parameters:
obj - CacheObject to put into the cache

remove

public void remove(java.lang.Object key)
Description copied from interface: Cache
Removes the CacheObject associated with key from the cache, if found.

Parameters:
key - key of CacheObject to remove

removeFromPositiveList

public final void removeFromPositiveList(java.lang.Object key)
Removes the key from the positive list, if it is present.

The cache objects will be updated immediately according to the removed key.

Parameters:
key - key object to remove

setPositiveList

public final void setPositiveList(java.util.Collection positiveList)
Sets a new positive list for this cache.

The old list is discarded. All cache objects will be updated immediately according to the new list.

Parameters:
positiveList - a Collection holding the allowed keys for this cache

statistic

public Cache.Statistic statistic()
Description copied from interface: Cache
Returns information collected by this cache since its creation.

Returns:
a Cache.Statistic object