ca.cbc.sportwire.util
Class TTLCacheMap
java.lang.Object
|
+--java.lang.Thread
|
+--ca.cbc.sportwire.util.PeriodicData
|
+--ca.cbc.sportwire.util.TTLCacheMap
- All Implemented Interfaces:
- java.util.Map, java.lang.Runnable, Stoppable
- Direct Known Subclasses:
- MRUCacheMap
- public class TTLCacheMap
- extends PeriodicData
- implements java.util.Map
TTLCacheMap.java: non-synchronized Map which runs an
independent thread to remove expired items.
Created: Fri Jan 4 13:07:03 2002
$Log: TTLCacheMap.java,v $
Revision 1.2 2002/02/11 07:09:25 garym
TTL will now test for Stoppable instead of Periodic
Revision 1.1 2002/01/18 03:10:42 garym
accidentally omitted from cvs
- Version:
- $Id: TTLCacheMap.java,v 1.2 2002/02/11 07:09:25 garym Exp $
- Author:
- Gary Lawrence Murphy
| Inner classes inherited from class java.util.Map |
java.util.Map.Entry |
|
Field Summary |
(package private) static org.apache.log4j.Category |
cat
Set up a reporting category in Log4J |
private java.util.Map |
m
|
private long |
ttl
|
| Fields inherited from class java.lang.Thread |
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ, userDaemon |
|
Constructor Summary |
TTLCacheMap()
TTLCacheMap null constructor |
TTLCacheMap(int ttlsec,
int periodsec)
TTLCacheMap constructor |
TTLCacheMap(long ttl)
TTLCacheMap constructor |
TTLCacheMap(long ttl,
int periodsec)
TTLCacheMap constructor allows setting the
periodicity of the expiry sweep; it is important to realize
that items expire no sooner than the expiry, but may
linger until the next sweep. |
|
Method Summary |
void |
clear()
clear: returns the result from the
underlying representation |
boolean |
containsKey(java.lang.Object key)
containsKey: returns the result from the
underlying representation |
boolean |
containsValue(java.lang.Object value)
containsValue: returns the result from the
underlying representation |
java.util.Set |
entrySet()
entrySet: returns the result from the
underlying representation |
java.lang.Object |
get(java.lang.Object key)
get: returns the result from the
underlying representation |
private TTLCacheMap.TTLEntry |
getEntry(java.lang.Object key)
|
protected java.util.Map |
getMap()
getMap: |
protected long |
getTTL()
getTTL: |
boolean |
isEmpty()
isEmpty: returns the result from the
underlying representation |
java.util.Set |
keySet()
keySet: returns the result from the
underlying representation |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
put: enters the item with a default expire TTL. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value,
long ms)
put: |
void |
putAll(java.util.Map t)
putAll: returns the result from the
underlying representation |
protected void |
refresh()
refresh: PeriodicData method called by the
concurrent timer thread; prunes out the expired items. |
java.lang.Object |
remove(java.lang.Object key)
remove: returns the result from the
underlying representation |
void |
setTTL(int sec)
setTTL: |
void |
setTTL(long ms)
setTTL: |
int |
size()
size: returns the result from the
underlying representation |
java.util.Collection |
values()
values: returns the result from the
underlying representation |
| Methods inherited from class java.lang.Thread |
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
equals, hashCode |
cat
static org.apache.log4j.Category cat
- Set up a reporting category in Log4J
m
private java.util.Map m
ttl
private long ttl
TTLCacheMap
public TTLCacheMap()
TTLCacheMap null constructor
TTLCacheMap
public TTLCacheMap(long ttl)
TTLCacheMap constructor
- Parameters:
ttl - a long millisecond value
TTLCacheMap
public TTLCacheMap(long ttl,
int periodsec)
TTLCacheMap constructor allows setting the
periodicity of the expiry sweep; it is important to realize
that items expire no sooner than the expiry, but may
linger until the next sweep.
- Parameters:
ttl - a long millisecond TTLvalueperiodsec - a int second periodicity
TTLCacheMap
public TTLCacheMap(int ttlsec,
int periodsec)
TTLCacheMap constructor
- Parameters:
ttlsec - a int seconds TTLvalueperiodsec - a int seconds periodicity
getMap
protected java.util.Map getMap()
getMap:
- Returns:
- a
Map value
clear
public void clear()
clear: returns the result from the
underlying representation
- Specified by:
clear in interface java.util.Map
containsKey
public boolean containsKey(java.lang.Object key)
containsKey: returns the result from the
underlying representation
- Specified by:
containsKey in interface java.util.Map
- Parameters:
key - an Object value- Returns:
- a
boolean true if found value
containsValue
public boolean containsValue(java.lang.Object value)
containsValue: returns the result from the
underlying representation
- Specified by:
containsValue in interface java.util.Map
- Parameters:
value - an Object value- Returns:
- a
boolean value
entrySet
public java.util.Set entrySet()
entrySet: returns the result from the
underlying representation
- Specified by:
entrySet in interface java.util.Map
- Returns:
- a
Set value
get
public java.lang.Object get(java.lang.Object key)
get: returns the result from the
underlying representation
- Specified by:
get in interface java.util.Map
- Parameters:
key - an Object value- Returns:
- an
Object value
isEmpty
public boolean isEmpty()
isEmpty: returns the result from the
underlying representation
- Specified by:
isEmpty in interface java.util.Map
- Returns:
- a
boolean value
keySet
public java.util.Set keySet()
keySet: returns the result from the
underlying representation
- Specified by:
keySet in interface java.util.Map
- Returns:
- a
Set value
put
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
put: enters the item with a default expire TTL.
- Specified by:
put in interface java.util.Map
- Parameters:
key - an Object valuevalue - an Object value- Returns:
- the
Object previously under this key or null
put
public java.lang.Object put(java.lang.Object key,
java.lang.Object value,
long ms)
put:
- Parameters:
key - an Object valuevalue - an Object valuems - a long value- Returns:
- an
Object value
putAll
public void putAll(java.util.Map t)
putAll: returns the result from the
underlying representation
- Specified by:
putAll in interface java.util.Map
- Parameters:
t - a Map value
remove
public java.lang.Object remove(java.lang.Object key)
remove: returns the result from the
underlying representation
- Specified by:
remove in interface java.util.Map
- Parameters:
key - an Object value- Returns:
- an
Object value
size
public int size()
size: returns the result from the
underlying representation
- Specified by:
size in interface java.util.Map
- Returns:
- an
int value
values
public java.util.Collection values()
values: returns the result from the
underlying representation
- Specified by:
values in interface java.util.Map
- Returns:
- a
Collection value
getEntry
private TTLCacheMap.TTLEntry getEntry(java.lang.Object key)
setTTL
public void setTTL(int sec)
setTTL:
- Parameters:
sec - an int value
setTTL
public void setTTL(long ms)
setTTL:
- Parameters:
ms - a long value
getTTL
protected long getTTL()
getTTL:
- Returns:
- a
long value
refresh
protected void refresh()
refresh: PeriodicData method called by the
concurrent timer thread; prunes out the expired items. Be very
careful if you use any sort of iterator over this collection as
the contents can change while you are passing over it.
- Overrides:
refresh in class PeriodicData