Methods Summary |
---|
public void | create()Initializes the cache for use. Prior to this the cache has no store.
// Lookup the parition
InitialContext ctx = new InitialContext();
String jndiName = "/HAPartition/" + partitionName;
HAPartition partition = (HAPartition) ctx.lookup(jndiName);
this.entryMap = partition.getDistributedStateService();
log.debug("Obtained DistributedState from partition="+partitionName);
now = System.currentTimeMillis();
|
public long | currentTimeMillis()Get the cache time.
return now;
|
public void | destroy()Clears the cache of all entries.
|
public void | flush()Remove all entries from the cache.
Collection keys = entryMap.getAllKeys(category);
// Notify the entries of their removal
Iterator iter = keys.iterator();
while( iter.hasNext() )
{
Serializable key = (Serializable) iter.next();
TimedEntry entry = (TimedEntry) entryMap.get(category, key);
entry.destroy();
}
|
public java.lang.Object | get(java.lang.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.
Serializable skey = (Serializable) key;
TimedEntry entry = (TimedEntry) entryMap.get(category, skey);
if( entry == null )
return null;
if( entry.isCurrent(now) == false )
{ // Try to refresh the entry
if( entry.refresh() == false )
{ // Failed, remove the entry and return null
entry.destroy();
try
{
entryMap.remove(category, skey);
}
catch(Exception e)
{
log.debug("Failed to remove expired entry", e);
}
return null;
}
}
Object value = entry.getValue();
return value;
|
public int | getDefaultLifetime()Get the default lifetime of cache entries.
return defaultLifetime;
|
public void | insert(java.lang.Object key, java.lang.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.
Serializable skey = (Serializable) key;
TimedEntry entry = (TimedEntry) entryMap.get(category, skey);
if( entry != null )
throw new IllegalStateException("Attempt to insert duplicate entry");
if( (value instanceof TimedEntry) == false )
{ // Wrap the value in a DefaultTimedEntry
Serializable svalue = (Serializable) value;
entry = new DefaultTimedEntry(defaultLifetime, svalue);
}
else
{
entry = (TimedEntry) value;
}
entry.init(now);
try
{
entryMap.set(category, skey, entry);
}
catch(Exception e)
{
log.error("Failed to set entry", e);
}
|
public java.lang.Object | peek(java.lang.Object key)Get the cache value for key. This method does not check to see if
the entry has expired.
Serializable skey = (Serializable) key;
TimedEntry entry = (TimedEntry) entryMap.get(category, skey);
Object value = null;
if( entry != null )
value = entry.getValue();
return value;
|
public org.jboss.ha.framework.server.util.DistributedTimedCachePolicy$TimedEntry | peekEntry(java.lang.Object key)Get the raw TimedEntry for key without performing any expiration check.
Serializable skey = (Serializable) key;
TimedEntry entry = (TimedEntry) entryMap.get(category, skey);
return entry;
|
public void | remove(java.lang.Object key)Remove the entry associated with key and call destroy on the entry
if found.
Serializable skey = (Serializable) key;
try
{
TimedEntry entry = (TimedEntry) entryMap.remove(category, skey);
if( entry != null )
entry.destroy();
}
catch(Exception e)
{
log.error("Failed to remove entry", e);
}
|
public void | run()The TimerTask run method. It updates the cache time to the
current system time.
now = System.currentTimeMillis();
|
public void | setDefaultLifetime(int defaultLifetime)Set the default lifetime of cache entries for new values added to the cache.
this.defaultLifetime = defaultLifetime;
|
public int | size()
return entryMap.getAllKeys(category).size();
|
public void | start()Schedules this with the class resolutionTimer Timer object for
execution every resolution seconds.
resolutionTimer.scheduleAtFixedRate(this, 0, 1000*resolution);
|
public void | stop()Stop cancels the resolution timer and flush()es the cache.
super.cancel();
|