org.terracotta.cache.value
Class AbstractStatelessTimestampedValue<V>

java.lang.Object
  extended by org.terracotta.cache.value.AbstractStatelessTimestampedValue<V>
All Implemented Interfaces:
TimestampedValue<V>
Direct Known Subclasses:
AbstractElementData, AbstractTimestampedValue

public abstract class AbstractStatelessTimestampedValue<V>
extends Object
implements TimestampedValue<V>

Author:
Alex Snaps

Field Summary
protected static int UNUSED
          Indicates the TTI or TTL is UNUSED (0).
 
Fields inherited from interface org.terracotta.cache.TimestampedValue
NEVER_EXPIRE
 
Constructor Summary
AbstractStatelessTimestampedValue()
           
 
Method Summary
 boolean equals(Object obj)
          Compare whether the value in this entry equals the value in another entry.
 int expiresAt(CacheConfig config)
          Get the time at which this timestamp will become invalid.
protected abstract  CapacityEvictionPolicyData fastGetCapacityEvictionPolicyData()
           
abstract  int getCreateTime()
          Retrieves the time when this value was created.
abstract  int getLastAccessedTime()
          Retrieves the time when this value was last accessed.
abstract  V getValue()
          Get the actual value in the cache.
 int hashCode()
           
 boolean isExpired(int atTime, CacheConfig config)
          Determine whether this timestamp is expired at the specified time.
 void markUsed(int usedAtTime, String lockId, CacheConfig config)
          Mark this timestamp as being used and reset the idle timer (if in use).
protected abstract  void setLastAccessedTimeInternal(int usedAtTime)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.terracotta.cache.TimestampedValue
getCapacityEvictionPolicyData, setCapacityEvictionPolicyData
 

Field Detail

UNUSED

protected static final int UNUSED
Indicates the TTI or TTL is UNUSED (0).

See Also:
Constant Field Values
Constructor Detail

AbstractStatelessTimestampedValue

public AbstractStatelessTimestampedValue()
Method Detail

fastGetCapacityEvictionPolicyData

protected abstract CapacityEvictionPolicyData fastGetCapacityEvictionPolicyData()

getValue

public abstract V getValue()
Description copied from interface: TimestampedValue
Get the actual value in the cache.

Specified by:
getValue in interface TimestampedValue<V>
Returns:
The value

markUsed

public final void markUsed(int usedAtTime,
                           String lockId,
                           CacheConfig config)
Mark this timestamp as being used and reset the idle timer (if in use). Updates lastAccessedTime of this entry to usedAtTime

Special case when tti=1; this will update the lastAccessedTime at usedAtTime + 1 instead. This is because as time is not continuous, the entry will expire in the next second even when the entry is accessed in the last second continuously. This is a result of time not being continuous. Effectively specifying tti=1 is equivalent to tti=2

Specified by:
markUsed in interface TimestampedValue<V>
Parameters:
usedAtTime - Mark used at this time
lockId - The lock string guarding this value, such as would be obtained by calling the underlying ConcurrentDistributedMap.getLockIdForKey() method
config - The cache configuration

getLastAccessedTime

public abstract int getLastAccessedTime()
Description copied from interface: TimestampedValue
Retrieves the time when this value was last accessed.

Specified by:
getLastAccessedTime in interface TimestampedValue<V>
Returns:
this value's last access time in seconds since epoch

setLastAccessedTimeInternal

protected abstract void setLastAccessedTimeInternal(int usedAtTime)

isExpired

public final boolean isExpired(int atTime,
                               CacheConfig config)
Determine whether this timestamp is expired at the specified time.

Specified by:
isExpired in interface TimestampedValue<V>
Parameters:
atTime - Usually the current time, in seconds since the epoch
config - The cache configuration
Returns:
True if this timestamp is expired at atTime

expiresAt

public int expiresAt(CacheConfig config)
Get the time at which this timestamp will become invalid. If the config specified ttl == tti == 0, making items eternal, then this method returns TimestampedValue.NEVER_EXPIRE.

Specified by:
expiresAt in interface TimestampedValue<V>
Parameters:
config - The configuration
Returns:
Timestamp of expiration, >0, may be NEVER_EXPIRE if eternal

getCreateTime

public abstract int getCreateTime()
Description copied from interface: TimestampedValue
Retrieves the time when this value was created.

Specified by:
getCreateTime in interface TimestampedValue<V>
Returns:
this value's creation time in seconds since epoch

equals

public boolean equals(Object obj)
Compare whether the value in this entry equals the value in another entry. Timestamps are ignored for equality purposes. Two null values will compare equals.

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010 Terracotta, Inc.. All Rights Reserved.