|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.ehcache.constructs.EhcacheDecoratorAdapter net.sf.ehcache.constructs.blocking.BlockingCache
public class BlockingCache
A blocking decorator for an Ehcache, backed by a Ehcache
.
ReadWriteLockSync
class. If you wish to use
this class, you will need the concurrent package in your class path.
It features:
Field Summary | |
---|---|
protected int |
timeoutMillis
The amount of time to block a thread before a LockTimeoutException is thrown |
Fields inherited from class net.sf.ehcache.constructs.EhcacheDecoratorAdapter |
---|
underlyingCache |
Constructor Summary | |
---|---|
BlockingCache(Ehcache cache)
Creates a BlockingCache which decorates the supplied cache. |
|
BlockingCache(Ehcache cache,
int numberOfStripes)
Creates a BlockingCache which decorates the supplied cache. |
Method Summary | |
---|---|
Element |
get(Object key)
Looks up an entry. |
Element |
get(Serializable key)
Gets an element from the cache. |
Map |
getAllWithLoader(Collection keys,
Object loaderArgument)
This method is not appropriate to use with BlockingCache. |
protected Ehcache |
getCache()
Retrieve the EHCache backing cache |
protected Sync |
getLockForKey(Object key)
Gets the Sync to use for a given key. |
int |
getTimeoutMillis()
Gets the time to wait to acquire a lock. |
Element |
getWithLoader(Object key,
CacheLoader loader,
Object loaderArgument)
This method is not appropriate to use with BlockingCache. |
String |
liveness()
Synchronized version of getName to test liveness of the object lock. |
void |
load(Object key)
This method is not appropriate to use with BlockingCache. |
void |
loadAll(Collection keys,
Object argument)
This method is not appropriate to use with BlockingCache. |
void |
put(Element element)
Adds an entry and unlocks it |
void |
put(Element element,
boolean doNotNotifyCacheReplicators)
Put an element in the cache. |
Element |
putIfAbsent(Element element)
Put an element in the cache if no element is currently mapped to the elements key. |
Element |
putIfAbsent(Element element,
boolean doNotNotifyCacheReplicators)
Put an element in the cache if no element is currently mapped to the elements key. |
void |
putQuiet(Element element)
Put an element in the cache, without updating statistics, or updating listeners. |
void |
putWithWriter(Element element)
Put an element in the cache writing through a CacheWriter. |
void |
registerCacheLoader(CacheLoader cacheLoader)
Register a CacheLoader with the cache. |
void |
setTimeoutMillis(int timeoutMillis)
Sets the time to wait to acquire a lock. |
void |
unregisterCacheLoader(CacheLoader cacheLoader)
Unregister a CacheLoader with the cache. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected volatile int timeoutMillis
Constructor Detail |
---|
public BlockingCache(Ehcache cache, int numberOfStripes) throws CacheException
cache
- a backing ehcache.numberOfStripes
- how many stripes to has the keys against. Must be a non-zero even number. This is a trade-off between
memory use and concurrency
CacheException
- shouldn't happenpublic BlockingCache(Ehcache cache) throws CacheException
cache
- a backing ehcache.
CacheException
- shouldn't happenMethod Detail |
---|
protected Ehcache getCache()
public Element get(Object key) throws RuntimeException, LockTimeoutException
put(net.sf.ehcache.Element)
is done
to put an Element in.
If a put is not done, the lock is never released.
If this method throws an exception, it is the responsibility of the caller to catch that exception and call
put(new Element(key, null));
to release the lock acquired. See SelfPopulatingCache
for an example.
Note. If a LockTimeoutException is thrown while doing a get
it means the lock was never acquired,
therefore it is a threading error to call put(net.sf.ehcache.Element)
get
in interface Ehcache
get
in class EhcacheDecoratorAdapter
key
- an Object value
LockTimeoutException
- if timeout millis is non zero and this method has been unable to
acquire a lock in that time
RuntimeException
- if thrown the lock will not released. Catch and callput(new Element(key, null));
to release the lock acquired.Ehcache.isExpired(net.sf.ehcache.Element)
protected Sync getLockForKey(Object key)
key
- the key
public void put(Element element)
put
in interface Ehcache
put
in class EhcacheDecoratorAdapter
element
- An object. If Serializable it can fully participate in replication and the DiskStore.public void put(Element element, boolean doNotNotifyCacheReplicators) throws IllegalArgumentException, IllegalStateException, CacheException
EhcacheDecoratorAdapter
put
in interface Ehcache
put
in class EhcacheDecoratorAdapter
element
- An object. If Serializable it can fully participate in replication and the DiskStore.doNotNotifyCacheReplicators
- whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a
further notification to doNotNotifyCacheReplicators cache peers
IllegalArgumentException
- if the element is null
IllegalStateException
- if the cache is not Status.STATUS_ALIVE
CacheException
public void putQuiet(Element element) throws IllegalArgumentException, IllegalStateException, CacheException
EhcacheDecoratorAdapter
Ehcache.getQuiet(java.io.Serializable)
putQuiet
in interface Ehcache
putQuiet
in class EhcacheDecoratorAdapter
element
- An object. If Serializable it can fully participate in replication and the DiskStore.
IllegalArgumentException
- if the element is null
IllegalStateException
- if the cache is not Status.STATUS_ALIVE
CacheException
public void putWithWriter(Element element) throws IllegalArgumentException, IllegalStateException, CacheException
EhcacheDecoratorAdapter
putWithWriter
in interface Ehcache
putWithWriter
in class EhcacheDecoratorAdapter
element
- An object. If Serializable it can fully participate in replication and the DiskStore.
IllegalArgumentException
- if the element is null
IllegalStateException
- if the cache is not Status.STATUS_ALIVE
CacheException
- if no CacheWriter was registeredpublic Element putIfAbsent(Element element) throws NullPointerException
EhcacheDecoratorAdapter
putIfAbsent
in interface Ehcache
putIfAbsent
in class EhcacheDecoratorAdapter
element
- element to be added
NullPointerException
- if the element is null, or has a null keypublic Element putIfAbsent(Element element, boolean doNotNotifyCacheReplicators) throws NullPointerException
Ehcache
putIfAbsent
in interface Ehcache
putIfAbsent
in class EhcacheDecoratorAdapter
element
- element to be addeddoNotNotifyCacheReplicators
- whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a
further notification to doNotNotifyCacheReplicators cache peers
NullPointerException
- if the element is null, or has a null keypublic Element get(Serializable key) throws IllegalStateException, CacheException
EhcacheDecoratorAdapter.getQuiet(Object)
to peak into the Element to see its last access time with get
get
in interface Ehcache
get
in class EhcacheDecoratorAdapter
key
- a serializable value
IllegalStateException
- if the cache is not Status.STATUS_ALIVE
CacheException
EhcacheDecoratorAdapter.isExpired(net.sf.ehcache.Element)
public String liveness()
public void setTimeoutMillis(int timeoutMillis)
timeoutMillis
- the time in ms. Must be a positive number. 0 means wait forever.public int getTimeoutMillis()
public void registerCacheLoader(CacheLoader cacheLoader)
CacheLoader
with the cache. It will then be tied into the cache lifecycle.
If the CacheLoader is not initialised, initialise it.
registerCacheLoader
in interface Ehcache
registerCacheLoader
in class EhcacheDecoratorAdapter
cacheLoader
- A Cache Loader to registerpublic void unregisterCacheLoader(CacheLoader cacheLoader)
CacheLoader
with the cache. It will then be detached from the cache lifecycle.
unregisterCacheLoader
in interface Ehcache
unregisterCacheLoader
in class EhcacheDecoratorAdapter
cacheLoader
- A Cache Loader to unregisterpublic Element getWithLoader(Object key, CacheLoader loader, Object loaderArgument) throws CacheException
getWithLoader
in interface Ehcache
getWithLoader
in class EhcacheDecoratorAdapter
key
- key whose associated value is to be returned.loader
- the override loader to use. If null, the cache's default loader will be usedloaderArgument
- an argument to pass to the CacheLoader.
CacheException
- if this method is calledpublic Map getAllWithLoader(Collection keys, Object loaderArgument) throws CacheException
getAllWithLoader
in interface Ehcache
getAllWithLoader
in class EhcacheDecoratorAdapter
keys
- a collection of keys to be returned/loadedloaderArgument
- an argument to pass to the CacheLoader.
CacheException
- if this method is calledpublic void load(Object key) throws CacheException
load
in interface Ehcache
load
in class EhcacheDecoratorAdapter
key
- key whose associated value to be loaded using the associated cacheloader if this cache doesn't contain it.
CacheException
- if this method is calledpublic void loadAll(Collection keys, Object argument) throws CacheException
loadAll
in interface Ehcache
loadAll
in class EhcacheDecoratorAdapter
CacheException
- if this method is called
|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |