com.rshtech.util
Class SoftCachedObject<T>

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

public class SoftCachedObject<T>
extends CachedObject<T>

A simple Cached implementation which allows you to track the lifecycle of an object (when it was created, whether it has expired, etc) and uses a SoftReference to hold the value. 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
static int DISABLED
           
 
Fields inherited from class com.rshtech.util.CachedObject
creationTime, expirationLimit, lastUseTime, manuallyExpired, unusedExpirationLimit
 
Constructor Summary
SoftCachedObject(T valueObj)
           
SoftCachedObject(T valueObj, long expirationVal, long unusedExpirationVal)
           
 
Method Summary
 boolean equals(java.lang.Object rhs)
           
 void expire()
          Forcibly expire the object regardless of its internal state.
 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 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 setValue(T value)
           
 java.lang.String toString()
           
 
Methods inherited from class com.rshtech.util.CachedObject
getCreationTime, getExpirationLimit, getLastUseTime, getUnusedExpirationLimit, setExpirationLimit, setUnusedExpirationLimit
 
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
Constructor Detail

SoftCachedObject

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

SoftCachedObject

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

getValue

public T getValue()
Overrides:
getValue in class CachedObject<T>
Returns:
Returns the value.

setValue

public void setValue(T value)
Overrides:
setValue in class CachedObject<T>
Parameters:
value - The value to set.

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
Overrides:
setLastUseTime in class CachedObject<T>

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
Overrides:
setLastUseTime in class CachedObject<T>
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
Overrides:
isExpired in class CachedObject<T>
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
Overrides:
isExpired in class CachedObject<T>
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
Overrides:
expire in class CachedObject<T>

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
Overrides:
renew in class CachedObject<T>

equals

public boolean equals(java.lang.Object rhs)
Overrides:
equals in class CachedObject<T>

hashCode

public int hashCode()
Overrides:
hashCode in class CachedObject<T>

toString

public java.lang.String toString()
Overrides:
toString in class CachedObject<T>

setCreationTime

protected void setCreationTime()
Overrides:
setCreationTime in class CachedObject<T>