tuwien.auto.calimero.buffer.cache
Class CacheObject

java.lang.Object
  extended by tuwien.auto.calimero.buffer.cache.CacheObject
Direct Known Subclasses:
LDataObject

public class CacheObject
extends java.lang.Object

Holds a key and a value entry and is used by a Cache.

The key object is not allowed to change after creation of a cache object.
An access count is maintained to tell the number of requests for this CacheObject by a cache.
The usage value might be used by a caching policy to store a different way of access counting.
A timestamp is stored of the most recent assignment of a value object hold by this CacheObject. This timestamp is created with System.currentTimeMillis().

See Also:
Cache, System.currentTimeMillis()

Field Summary
protected  java.lang.Object value
          The value object hold by this cache object.
 
Constructor Summary
CacheObject(java.lang.Object key, java.lang.Object value)
          Creates a CacheObject associated with key holding a value entry.
 
Method Summary
 int getCount()
          Returns the access count this cache object was queried from the cache.
 java.lang.Object getKey()
          Returns the key associated with this cache object.
 long getTimestamp()
          Returns the most up to date timestamp of the moment the current value object was assigned to this cache object, or the moment this object was Cache.put(CacheObject) into a cache.
 int getUsage()
          Returns the usage value of this cache object as defined by a particular cache.
 java.lang.Object getValue()
          Gets the value entry hold by this cache object.
 void incCount()
          Increments the access count by 1.
protected  void resetCount()
          Sets the access count to 0.
 void resetTimestamp()
          Sets the timestamp to time = now.
protected  void setUsage(int newUsage)
          Sets a new usage value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

value

protected java.lang.Object value
The value object hold by this cache object.

Constructor Detail

CacheObject

public CacheObject(java.lang.Object key,
                   java.lang.Object value)
Creates a CacheObject associated with key holding a value entry.

Parameters:
key - key of this CacheObject
value - value of this CacheObject
Method Detail

getCount

public final int getCount()
Returns the access count this cache object was queried from the cache.

Returns:
the access count

getKey

public java.lang.Object getKey()
Returns the key associated with this cache object.

Returns:
the key object

getTimestamp

public final long getTimestamp()
Returns the most up to date timestamp of the moment the current value object was assigned to this cache object, or the moment this object was Cache.put(CacheObject) into a cache.

Returns:
the timestamp in milliseconds of type long
See Also:
System.currentTimeMillis()

getUsage

public final int getUsage()
Returns the usage value of this cache object as defined by a particular cache.

Returns:
the usage value

getValue

public java.lang.Object getValue()
Gets the value entry hold by this cache object.

Note that the value is guaranteed to be always a non null reference.

Returns:
the value object

incCount

public final void incCount()
Increments the access count by 1.

It is invoked by a Cache implementation to record a client access to this object.


resetCount

protected final void resetCount()
Sets the access count to 0.


resetTimestamp

public final void resetTimestamp()
Sets the timestamp to time = now.

The timestamp is obtained by System.currentTimeMillis().


setUsage

protected final void setUsage(int newUsage)
Sets a new usage value.

The usage value might be used by a caching policy to store a different way of access counting.

Parameters:
newUsage - new usage value