com.rshtech.util
Class CachedObject<T>

java.lang.Object
  extended by com.rshtech.util.CachedObject<T>
All Implemented Interfaces:
Cached
Direct Known Subclasses:
SoftCachedObject

public class CachedObject<T>
extends java.lang.Object
implements Cached

A simple Cached implementation which allows you to track the lifecycle of an object (when it was created, whether it has expired, etc). This enclosure allows you to handle single object caching; that is, if you do not need a collection of keyed objects (see ObjectCache) but just one object.

Version:
$Revision: 3129 $
Author:
$Author: kostya $

Field Summary
protected  long creationTime
           
static int DISABLED
           
protected  long expirationLimit
           
protected  long lastUseTime
           
protected  boolean manuallyExpired
           
protected  long unusedExpirationLimit
           
 
Constructor Summary
protected CachedObject()
           
  CachedObject(T valueObj)
           
  CachedObject(T valueObj, long expirationVal, long unusedExpirationVal)
           
protected CachedObject(T valueObj, long expirationVal, long unusedExpirationVal, boolean ignoreNull)
           
 
Method Summary
 boolean equals(java.lang.Object rhs)
           
 void expire()
          Forcibly expire the object regardless of its internal state.
 long getCreationTime()
          Returns the time (in milliseconds) the object was created.
 long getExpirationLimit()
          Get the expiration limit (in milliseconds).
 long getLastUseTime()
          Returns the last time (in milliseconds) this object was used or accessed.
 long getUnusedExpirationLimit()
          Get the expiration limit (in milliseconds).
 T getValue()
           
 int hashCode()
           
 boolean isExpired()
          Is the implementation expired (should it be removed from a cache or discarded)?
 boolean isExpired(long expirationVal, long unusedExpirationVal)
          Is the implementation expired (should it be removed from a cache or discarded) based on the supplied criteria?
 void renew()
          Renew an object (at least removing a forcible expiration, possibly resetting internal state).
protected  void setCreationTime()
           
 void setExpirationLimit(long expirationVal)
          Set the expiration limit (in milliseconds).
 void setLastUseTime()
          Notify the implementation that it should mark the last use time using the current time.
 void setLastUseTime(long lastUseTime)
          Set the last use time for the implementation using the specified value (in milliseconds).
 void setUnusedExpirationLimit(long expirationVal)
          Set the unused expiration limit (in milliseconds).
 void setValue(T value)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DISABLED

public static final int DISABLED
See Also:
Constant Field Values

creationTime

protected long creationTime

lastUseTime

protected long lastUseTime

expirationLimit

protected long expirationLimit

unusedExpirationLimit

protected long unusedExpirationLimit

manuallyExpired

protected boolean manuallyExpired
Constructor Detail

CachedObject

public CachedObject(T valueObj)
Parameters:
valueObj - the object to cache

CachedObject

public CachedObject(T valueObj,
                    long expirationVal,
                    long unusedExpirationVal)
Parameters:
valueObj - the object to cache

CachedObject

protected CachedObject()
Parameters:
valueObj - the object to cache

CachedObject

protected CachedObject(T valueObj,
                       long expirationVal,
                       long unusedExpirationVal,
                       boolean ignoreNull)
Parameters:
valueObj - the object to cache
Method Detail

getValue

public T getValue()
Returns:
Returns the value.

setValue

public void setValue(T value)
Parameters:
value - The value to set.

getCreationTime

public long getCreationTime()
Description copied from interface: Cached
Returns the time (in milliseconds) the object was created. The created time usually reflects when the object was cached, not when it was necessarily created (although the two can be the same).

Specified by:
getCreationTime in interface Cached
Returns:
the creation time in milliseconds

getLastUseTime

public long getLastUseTime()
Description copied from interface: Cached
Returns the last time (in milliseconds) this object was used or accessed. It is the job of the implementation to set this value or the enclosing code or data structure must do it using setLastUseTime().

Specified by:
getLastUseTime in interface Cached
Returns:
the last time (in milliseconds) this object was used.

setLastUseTime

public void setLastUseTime()
Description copied from interface: Cached
Notify the implementation that it should mark the last use time using the current time.

Specified by:
setLastUseTime in interface Cached

setLastUseTime

public void setLastUseTime(long lastUseTime)
Description copied from interface: Cached
Set the last use time for the implementation using the specified value (in milliseconds).

Specified by:
setLastUseTime in interface Cached
Parameters:
lastUseTime - the milliseconds value to use.

isExpired

public boolean isExpired()
Description copied from interface: Cached
Is the implementation expired (should it be removed from a cache or discarded)?

Specified by:
isExpired in interface Cached
Returns:
true of the internal state of the implementation shows it to be expired or stale, false otherwise.

isExpired

public boolean isExpired(long expirationVal,
                         long unusedExpirationVal)
Description copied from interface: Cached
Is the implementation expired (should it be removed from a cache or discarded) based on the supplied criteria?

Specified by:
isExpired in interface Cached
Parameters:
expirationVal - the amount of milliseconds that can pass since the creation time before the implementation is considered expired. A value of -1 is considered a "disabled" value and such values should then be ignored (that is the implementation should never expire on the creation time).
unusedExpirationVal - the amount of milliseconds that can pass since the last use time before the implementation is considered expired. A value of -1 is considered a "disabled" value and such values should then be ignored (that is the implementation should never expire on the last use time).
Returns:
true of the internal state of the implementation shows it to be expired or stale, false otherwise.

expire

public void expire()
Description copied from interface: Cached
Forcibly expire the object regardless of its internal state.

Specified by:
expire in interface Cached

renew

public void renew()
Description copied from interface: Cached
Renew an object (at least removing a forcible expiration, possibly resetting internal state).

Specified by:
renew in interface Cached

getExpirationLimit

public long getExpirationLimit()
Description copied from interface: Cached
Get the expiration limit (in milliseconds). The expiration limit is the amount of milliseconds that can pass since the creation time before the implementation is considered expired. A value of -1 is considered a "disabled" value and such values should then be ignored (that is the implementation should never expire on the creation time).

Specified by:
getExpirationLimit in interface Cached

setExpirationLimit

public void setExpirationLimit(long expirationVal)
Description copied from interface: Cached
Set the expiration limit (in milliseconds).

Specified by:
setExpirationLimit in interface Cached
Parameters:
expirationVal - the amount of milliseconds that can pass since the creation time before the implementation is considered expired. A value of -1 is considered a "disabled" value and such values should then be ignored (that is the implementation should never expire on the creation time).

getUnusedExpirationLimit

public long getUnusedExpirationLimit()
Description copied from interface: Cached
Get the expiration limit (in milliseconds). The expiration limit is the amount of milliseconds that can pass since the last use time before the implementation is considered expired. A value of -1 is considered a "disabled" value and such values should then be ignored (that is the implementation should never expire on the last use time).

Specified by:
getUnusedExpirationLimit in interface Cached

setUnusedExpirationLimit

public void setUnusedExpirationLimit(long expirationVal)
Description copied from interface: Cached
Set the unused expiration limit (in milliseconds).

Specified by:
setUnusedExpirationLimit in interface Cached
Parameters:
expirationVal - the amount of milliseconds that can pass since the last use time before the implementation is considered expired. A value of -1 is considered a "disabled" value and such values should then be ignored (that is the implementation should never expire on the last use time).

equals

public boolean equals(java.lang.Object rhs)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setCreationTime

protected void setCreationTime()