|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.wso2.carbon.caching.impl.CacheImpl<K,V>
public class CacheImpl<K,V>
TODO: class description
TODO: Cache statistics
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface javax.cache.Cache |
|---|
Cache.Entry<K,V>, Cache.EntryProcessor<K,V>, Cache.MutableEntry<K,V> |
| Constructor Summary | |
|---|---|
CacheImpl(String cacheName,
CacheManager cacheManager)
|
|
| Method Summary | ||
|---|---|---|
boolean |
containsKey(K key)
Returns true if this cache contains a mapping for the specified key. |
|
boolean |
equals(Object o)
|
|
void |
evict(K key)
|
|
void |
expire(K key)
|
|
V |
get(K key)
Gets an entry from the cache. |
|
Collection<CacheEntry<K,V>> |
getAll()
|
|
Map<K,V> |
getAll(Set<? extends K> keys)
The getAll method will return, from the cache, a Map of the objects
associated with the Collection of keys in argument "keys". |
|
V |
getAndPut(K key,
V value)
Associates the specified value with the specified key in this cache, returning an existing value if one existed. |
|
V |
getAndRemove(K key)
Atomically removes the entry for a key only if currently mapped to a given value. |
|
V |
getAndReplace(K key,
V value)
Atomically replaces the entry for a key only if currently mapped to some value. |
|
CacheManager |
getCacheManager()
Gets the CacheManager managing this cache. |
|
CacheConfiguration<K,V> |
getConfiguration()
Returns a CacheConfiguration. |
|
CacheMXBean |
getMBean()
Get the MBean for this cache. |
|
String |
getName()
Return the name of the cache. |
|
CacheStatistics |
getStatistics()
Returns the CacheStatistics MXBean associated with the cache. |
|
Status |
getStatus()
Returns the cache status. |
|
int |
hashCode()
|
|
Object |
invokeEntryProcessor(K key,
Cache.EntryProcessor<K,V> entryProcessor)
Passes the cache entry associated with K to be passed to the entry processor. |
|
Iterator<Cache.Entry<K,V>> |
iterator()
The ordering of the entries is undefined |
|
Iterator<K> |
keys()
|
|
Future<V> |
load(K key)
The load method provides a means to "pre-load" the cache. |
|
Future<Map<K,? extends V>> |
loadAll(Set<? extends K> keys)
The loadAll method provides a means to "pre-load" objects into the cache. |
|
void |
put(K key,
V value)
Associates the specified value with the specified key in this cache If the cache previously contained a mapping for the key, the old value is replaced by the specified value. |
|
void |
putAll(Map<? extends K,? extends V> map)
Copies all of the mappings from the specified map to this cache. |
|
boolean |
putIfAbsent(K key,
V value)
Atomically associates the specified key with the given value if it is not already associated with a value. |
|
boolean |
registerCacheEntryListener(CacheEntryListener<? super K,? super V> cacheEntryListener)
Adds a listener to the notification service. |
|
boolean |
remove(K key,
V oldValue)
Atomically removes the mapping for a key only if currently mapped to the given value. |
|
boolean |
remove(Object key)
Removes the mapping for a key from this cache if it is present. |
|
void |
removeAll()
Removes all of the mappings from this cache. |
|
void |
removeAll(Set<? extends K> keys)
Removes entries for the specified keys. |
|
boolean |
replace(K key,
V value)
Atomically replaces the entry for a key only if currently mapped to some value. |
|
boolean |
replace(K key,
V oldValue,
V newValue)
Atomically replaces the entry for a key only if currently mapped to a given value. |
|
void |
setCacheConfiguration(CacheConfigurationImpl cacheConfiguration)
|
|
void |
setCapacity(long capacity)
|
|
void |
setEvictionAlgorithm(EvictionAlgorithm evictionAlgorithm)
|
|
void |
start()
Notifies providers to start themselves. |
|
void |
stop()
Providers may be doing all sorts of exotic things and need to be able to clean up on stop. |
|
void |
syncCaches()
Deprecated. This method is highly inefficient. Do not use. |
|
boolean |
unregisterCacheEntryListener(CacheEntryListener<?,?> cacheEntryListener)
Removes a call back listener. |
|
|
unwrap(Class<T> cls)
Return an object of the specified type to allow access to the provider-specific API. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CacheImpl(String cacheName,
CacheManager cacheManager)
| Method Detail |
|---|
public V get(K key)
CacheCacheLoader is called which will attempt
to load the entry.
Access Time.CacheLoader if enabled and key not present in cache
get in interface Cache<K,V>key - the key whose associated value is to be returned
Map.get(Object)public Map<K,V> getAll(Set<? extends K> keys)
CacheMap of the objects
associated with the Collection of keys in argument "keys".
If the cache is configured read-through, and a get would return null because an entry
is missing from the cache, the Cache's CacheLoader is called which will attempt
to load the entry. This is done for each key in the collection for which this is the case.
If an entry cannot be loaded for a given key, the key will not be present in the returned Map.
getAll in interface Cache<K,V>keys - The keys whose associated values are to be returned.
public void syncCaches()
public Collection<CacheEntry<K,V>> getAll()
public boolean containsKey(K key)
Cache
containsKey in interface Cache<K,V>key - key whose presence in this cache is to be tested.
Map.containsKey(Object)public Future<V> load(K key)
CacheCacheLoader for the given key.
If the object already exists in the cache, no action is taken and null is returned.
If no loader is associated with the cache no object will be loaded into the cache and null is returned.
If a problem is encountered during the retrieving or loading of the object, an exception
must be propagated on Future.get() as a ExecutionException
load in interface Cache<K,V>key - the key
public Future<Map<K,? extends V>> loadAll(Set<? extends K> keys)
CacheFuture.get() as a ExecutionException
loadAll in interface Cache<K,V>keys - the keys
public CacheStatistics getStatistics()
CacheCacheStatistics MXBean associated with the cache.
May return null if the cache does not support statistics gathering.
getStatistics in interface Cache<K,V>
public void put(K key,
V value)
Cachec.containsKey(k) would return
true.)
In contrast to the corresponding Map operation, does not return
the previous value.
put in interface Cache<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keyMap.put(Object, Object),
Cache.getAndPut(Object, Object),
Cache.getAndReplace(Object, Object)
public V getAndPut(K key,
V value)
Cachec.containsKey(k) would return
true.)
The the previous value is returned, or null if there was no value associated
with the key previously.
getAndPut in interface Cache<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified key
Map.put(Object, Object),
Cache.put(Object, Object),
Cache.getAndReplace(Object, Object)public void putAll(Map<? extends K,? extends V> map)
Cacheput(k, v) on this cache once
for each mapping from key k to value v in the
specified map.
The order in which the individual puts will occur is undefined.
The behavior of this operation is undefined if the specified cache or map is modified while the
operation is in progress.
putAll in interface Cache<K,V>map - mappings to be stored in this cacheMap.putAll(java.util.Map)
public boolean putIfAbsent(K key,
V value)
Cache
if (!cache.containsKey(key)) {}
cache.put(key, value);
return true;
} else {
return false;
}
except that the action is performed atomically.
In contrast to the corresponding ConcurrentMap operation, does not return
the previous value.
putIfAbsent in interface Cache<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified key
ConcurrentMap.putIfAbsent(Object, Object)public boolean remove(Object key)
Cache(key==null ? k==null : key.equals(k)), that mapping
is removed. (The cache can contain at most one such mapping.)
Returns true if this cache previously associated the key, or false if the cache contained no mapping for the key.
The cache will not contain a mapping for the specified key once the call returns.
remove in interface Cache<K,V>key - key whose mapping is to be removed from the cache
Map.remove(Object)
public boolean remove(K key,
V oldValue)
Cache
if (cache.containsKey(key) && cache.get(key).equals(oldValue)) {
cache.remove(key);
return true;
} else {
return false;
}
except that the action is performed atomically.
remove in interface Cache<K,V>key - key whose mapping is to be removed from the cacheoldValue - value expected to be associated with the specified key
Map.remove(Object)public V getAndRemove(K key)
Cache
if (cache.containsKey(key)) {
V oldValue = cache.get(key);
cache.remove(key);
return oldValue;
} else {
return null;
}
except that the action is performed atomically.
getAndRemove in interface Cache<K,V>key - key with which the specified value is associated
Map.remove(Object)
public boolean replace(K key,
V oldValue,
V newValue)
Cache
if (cache.containsKey(key) && cache.get(key).equals(oldValue)) {
cache.put(key, newValue);
return true;
} else {
return false;
}
except that the action is performed atomically.
replace in interface Cache<K,V>key - key with which the specified value is associatedoldValue - value expected to be associated with the specified keynewValue - value to be associated with the specified key
ConcurrentMap.replace(Object, Object, Object)
public boolean replace(K key,
V value)
Cache
if (cache.containsKey(key)) {
cache.put(key, value);
return true;
} else {
return false;
}
except that the action is performed atomically.
In contrast to the corresponding ConcurrentMap operation, does not return
the previous value.
replace in interface Cache<K,V>key - key with which the specified value is associatedvalue - value to be associated with the specified key
Cache.getAndReplace(Object, Object),
ConcurrentMap.replace(Object, Object)
public V getAndReplace(K key,
V value)
Cache
if (cache.containsKey(key)) {
V value = cache.get(key, value);
cache.put(key, value);
return value;
} else {
return null;
}
except that the action is performed atomically.
getAndReplace in interface Cache<K,V>key - key with which the specified value is associatedvalue - value to be associated with the specified key
ConcurrentMap.replace(Object, Object)public void removeAll(Set<? extends K> keys)
Cache
removeAll in interface Cache<K,V>keys - the keys to removepublic void removeAll()
Cache
removeAll in interface Cache<K,V>#clear()public CacheConfiguration<K,V> getConfiguration()
CacheStatus.STARTED an implementation must respect the following:
Status.STARTED (CacheConfiguration.setStatisticsEnabled(boolean))InvalidConfigurationException must be thrown on
an attempt to mutate the configuration.
getConfiguration in interface Cache<K,V>CacheConfiguration of this cachepublic boolean registerCacheEntryListener(CacheEntryListener<? super K,? super V> cacheEntryListener)
Cache
registerCacheEntryListener in interface Cache<K,V>cacheEntryListener - The listener to add. Listeners fire synchronously in the execution path, and after the
causing event. if a listener throws an exception it will be wrapped in a CacheException
and propagated back to the caller.
public boolean unregisterCacheEntryListener(CacheEntryListener<?,?> cacheEntryListener)
Cache
unregisterCacheEntryListener in interface Cache<K,V>cacheEntryListener - the listener to remove
public Object invokeEntryProcessor(K key,
Cache.EntryProcessor<K,V> entryProcessor)
Cache
invokeEntryProcessor in interface Cache<K,V>key - the key to the entryentryProcessor - the processor which will process the entry
Cache.EntryProcessorpublic String getName()
Cache
getName in interface Cache<K,V>public CacheManager getCacheManager()
Cache
getCacheManager in interface Cache<K,V>public <T> T unwrap(Class<T> cls)
CacheIllegalArgumentException is thrown.
unwrap in interface Cache<K,V>cls - he class of the object to be returned. This is normally either the underlying implementation class or an interface that it implements.
public Iterator<K> keys()
keys in interface Cache<K,V>public Iterator<Cache.Entry<K,V>> iterator()
Cache
iterator in interface Iterable<Cache.Entry<K,V>>iterator in interface Cache<K,V>public CacheMXBean getMBean()
Cache
getMBean in interface Cache<K,V>public void start()
CacheLifecycleCacheLifecycle.getStatus() must return Status.STARTED.
start in interface CacheLifecyclepublic void stop()
CacheLifecycleIllegalStateException will be
Resources will change status to Status.STOPPED when this method completes.
Stop must free any JVM resources used.
stop in interface CacheLifecyclepublic Status getStatus()
CacheLifecycle
getStatus in interface CacheLifecycleStatuspublic void expire(K key)
public void evict(K key)
public void setCacheConfiguration(CacheConfigurationImpl cacheConfiguration)
public void setCapacity(long capacity)
public void setEvictionAlgorithm(EvictionAlgorithm evictionAlgorithm)
public boolean equals(Object o)
equals in class Objectpublic int hashCode()
hashCode in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||