站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss 4.0.1 sp1 cluster API Documentation 英文版文档

DistributedTimedCachePolicy (JBoss Cluster API) - JBoss 4.0.1 sp1 cluster API Documentation 英文版文档


org.jboss.ha.framework.server.util
Class DistributedTimedCachePolicy

java.lang.Object
  extended byjava.util.TimerTask
      extended byorg.jboss.ha.framework.server.util.DistributedTimedCachePolicy
All Implemented Interfaces:
org.jboss.util.CachePolicy, Runnable

public class DistributedTimedCachePolicy
extends TimerTask
implements org.jboss.util.CachePolicy

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.

Version:
$Revision: 1.2 $
Author:
Scott Stark.

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

resolutionTimer

protected static Timer resolutionTimer

log

protected static org.jboss.logging.Logger log

entryMap

protected DistributedState entryMap
The map of cached TimedEntry objects.


category

protected String category

partitionName

protected String partitionName

defaultLifetime

protected int defaultLifetime
The lifetime in seconds to use for objects inserted that do not implement the TimedEntry interface.


now

protected long now
The caches notion of the current time


resolution

protected int resolution
The resolution in seconds of the cach current time

Constructor Detail

DistributedTimedCachePolicy

public 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

public 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.

Parameters:
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.
See Also:
DistributedState
Method Detail

create

public void create()
            throws Exception
Initializes the cache for use. Prior to this the cache has no store.

Specified by:
create in interface org.jboss.util.CachePolicy
Throws:
Exception

start

public void start()
Schedules this with the class resolutionTimer Timer object for execution every resolution seconds.

Specified by:
start in interface org.jboss.util.CachePolicy

stop

public void stop()
Stop cancels the resolution timer and flush()es the cache.

Specified by:
stop in interface org.jboss.util.CachePolicy

destroy

public void destroy()
Clears the cache of all entries.

Specified by:
destroy in interface org.jboss.util.CachePolicy

get

public Object get(Object key)
Get the cache value for key if it has not expired. If the TimedEntry is expired its destroy method is called and then removed from the cache.

Specified by:
get in interface org.jboss.util.CachePolicy
Returns:
the TimedEntry value or the original value if it was not an instance of TimedEntry if key is in the cache, null otherwise.

peek

public Object peek(Object key)
Get the cache value for key. This method does not check to see if the entry has expired.

Specified by:
peek in interface org.jboss.util.CachePolicy
Returns:
the TimedEntry value or the original value if it was not an instancee of TimedEntry if key is in the cache, null otherwise.

insert

public void insert(Object key,
                   Object value)
Insert a value into the cache. In order to have the cache entry reshresh itself value would have to implement TimedEntry and implement the required refresh() method logic.

Specified by:
insert in interface org.jboss.util.CachePolicy
Parameters:
key - the key for the cache entry
value - Either an instance of TimedEntry that will be inserted without change, or an abitrary value that will be wrapped in a non-refreshing TimedEntry.

remove

public void remove(Object key)
Remove the entry associated with key and call destroy on the entry if found.

Specified by:
remove in interface org.jboss.util.CachePolicy

flush

public void flush()
Remove all entries from the cache.

Specified by:
flush in interface org.jboss.util.CachePolicy

size

public int size()
Specified by:
size in interface org.jboss.util.CachePolicy

getDefaultLifetime

public int getDefaultLifetime()
Get the default lifetime of cache entries.

Returns:
default lifetime in seconds of cache entries.

setDefaultLifetime

public void setDefaultLifetime(int defaultLifetime)
Set the default lifetime of cache entries for new values added to the cache.

Parameters:
defaultLifetime - lifetime in seconds of cache values that do not implement TimedEntry.

run

public void run()
The TimerTask run method. It updates the cache time to the current system time.

Specified by:
run in interface Runnable

currentTimeMillis

public long currentTimeMillis()
Get the cache time.

Returns:
the cache time last obtained from System.currentTimeMillis()

peekEntry

public DistributedTimedCachePolicy.TimedEntry peekEntry(Object key)
Get the raw TimedEntry for key without performing any expiration check.

Returns:
the TimedEntry value associated with key if one exists, null otherwise.


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.