|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.TimerTask org.jboss.ha.framework.server.util.DistributedTimedCachePolicy
An implementation of a timed cache. This is a cache whose entries have a limited lifetime with the ability to refresh their lifetime. The entries managed by the cache implement the TimedCachePolicy.TimedEntry interface. If an object inserted into the cache does not implement this interface, it will be wrapped in a DefaultTimedEntry and will expire without the possibility of refresh after getDefaultLifetime() seconds. This is a lazy cache policy in that objects are not checked for expiration until they are accessed.
Nested Class Summary | |
static interface |
DistributedTimedCachePolicy.TimedEntry
The interface that cache entries support. |
Field Summary | |
protected String |
category
|
protected int |
defaultLifetime
The lifetime in seconds to use for objects inserted that do not implement the TimedEntry interface. |
protected DistributedState |
entryMap
The map of cached TimedEntry objects. |
protected static org.jboss.logging.Logger |
log
|
protected long |
now
The caches notion of the current time |
protected String |
partitionName
|
protected int |
resolution
The resolution in seconds of the cach current time |
protected static Timer |
resolutionTimer
|
Constructor Summary | |
DistributedTimedCachePolicy(String category,
String partitionName,
int defaultLifetime)
Creates a new TimedCachePolicy with the given default entry lifetime that does not synchronized access to its policy store and uses a 60 second resolution. |
|
DistributedTimedCachePolicy(String category,
String partitionName,
int defaultLifetime,
int resolution)
Creates a new TimedCachePolicy with the given default entry lifetime that does/does not synchronized access to its policy store depending on the value of threadSafe. |
Method Summary | |
void |
create()
Initializes the cache for use. |
long |
currentTimeMillis()
Get the cache time. |
void |
destroy()
Clears the cache of all entries. |
void |
flush()
Remove all entries from the cache. |
Object |
get(Object key)
Get the cache value for key if it has not expired. |
int |
getDefaultLifetime()
Get the default lifetime of cache entries. |
void |
insert(Object key,
Object value)
Insert a value into the cache. |
Object |
peek(Object key)
Get the cache value for key. |
DistributedTimedCachePolicy.TimedEntry |
peekEntry(Object key)
Get the raw TimedEntry for key without performing any expiration check. |
void |
remove(Object key)
Remove the entry associated with key and call destroy on the entry if found. |
void |
run()
The TimerTask run method. |
void |
setDefaultLifetime(int defaultLifetime)
Set the default lifetime of cache entries for new values added to the cache. |
int |
size()
|
void |
start()
Schedules this with the class resolutionTimer Timer object for execution every resolution seconds. |
void |
stop()
Stop cancels the resolution timer and flush()es the cache. |
Methods inherited from class java.util.TimerTask |
cancel, scheduledExecutionTime |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static Timer resolutionTimer
protected static org.jboss.logging.Logger log
protected DistributedState entryMap
protected String category
protected String partitionName
protected int defaultLifetime
protected long now
protected int resolution
Constructor Detail |
public DistributedTimedCachePolicy(String category, String partitionName, int defaultLifetime)
public DistributedTimedCachePolicy(String category, String partitionName, int defaultLifetime, int resolution)
category
- the name of the catetegory used in the DistributedState
access calls.partitionName
- the name of the HAPartition who's replicated
state service will be used as the cache store.defaultLifetime
- the lifetime in seconds to use for objects inserted
that do not implement the TimedEntry interface.resolution
- the resolution in seconds of the cache timer. A cache does
not query the system time on every get() invocation. Rather the cache
updates its notion of the current time every 'resolution' seconds.DistributedState
Method Detail |
public void create() throws Exception
create
in interface org.jboss.util.CachePolicy
Exception
public void start()
start
in interface org.jboss.util.CachePolicy
public void stop()
stop
in interface org.jboss.util.CachePolicy
public void destroy()
destroy
in interface org.jboss.util.CachePolicy
public Object get(Object key)
get
in interface org.jboss.util.CachePolicy
public Object peek(Object key)
peek
in interface org.jboss.util.CachePolicy
public void insert(Object key, Object value)
insert
in interface org.jboss.util.CachePolicy
key
- the key for the cache entryvalue
- Either an instance of TimedEntry that will be inserted without
change, or an abitrary value that will be wrapped in a non-refreshing
TimedEntry.public void remove(Object key)
remove
in interface org.jboss.util.CachePolicy
public void flush()
flush
in interface org.jboss.util.CachePolicy
public int size()
size
in interface org.jboss.util.CachePolicy
public int getDefaultLifetime()
public void setDefaultLifetime(int defaultLifetime)
defaultLifetime
- lifetime in seconds of cache values that do
not implement TimedEntry.public void run()
public long currentTimeMillis()
public DistributedTimedCachePolicy.TimedEntry peekEntry(Object key)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |