|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
@ThreadSafe public interface Cache<K,V>
Interface for a Cache where data mappings are grouped and stored in a tree data
structure consisting of Node
s.
CacheFactory
and is started
using start()
, if not already started by the CacheFactory.
Once constructed, the Cache interface can be used to create or access Node
s, which contain data. Once references
to Node
s are obtained, data can be stored in them,
As a convenience (and mainly to provide a familiar API to the older JBoss Cache 1.x.x releases) methods are provided that
operate directly on nodes.
A simple example of usage:
// creates with default settings and starts the cache Cache cache = DefaultCacheFactory.getInstance().createCache(); Fqn personRecords = Fqn.fromString("/org/mycompany/personRecords"); Node rootNode = cache.getRoot(); Node personRecordsNode = rootNode.addChild(personRecords); // now add some person records. Fqn peterGriffin = Fqn.fromString("/peterGriffin"); Fqn stewieGriffin = Fqn.fromString("/stewieGriffin"); // the addChild() API uses relative Fqns Node peter = personRecordsNode.addChild(peterGriffin); Node stewie = personRecordsNode.addChild(stewieGriffin); peter.put("name", "Peter Griffin"); peter.put("ageGroup", "MidLifeCrisis"); peter.put("homicidal", Boolean.FALSE); stewie.put("name", "Stewie Griffin"); stewie.put("ageGroup", "Infant"); stewie.put("homicidal", Boolean.TRUE); peter.getFqn().toString(); // will print out /org/mycompany/personRecords/peterGriffin stewie.getFqn().toString(); // will print out /org/mycompany/personRecords/stewieGriffin peter.getFqn().getParent().equals(stewie.getFqn().getParent()); // will return trueFor more information, please read the JBoss Cache user guide and tutorial, available on the JBoss Cache documentation site, and look through the examples shipped with the JBoss Cache distribution.
Node
,
CacheFactory
Method Summary | |
---|---|
void |
addCacheListener(Fqn<?> region,
java.lang.Object listener)
Adds a @org.jboss.cache.notifications.annotation.CacheListener -annotated object to a given region. |
void |
addCacheListener(java.lang.Object listener)
Adds a @org.jboss.cache.notifications.annotation.CacheListener -annotated object to the entire cache. |
void |
create()
Lifecycle method that initializes configuration state, the root node, etc. |
void |
destroy()
Lifecycle method that destroys the cache and removes any interceptors/configuration elements. |
void |
evict(Fqn<?> fqn,
boolean recursive)
Eviction call that evicts the specified Node from memory. |
V |
get(Fqn<?> fqn,
K key)
Convenience method that allows for direct access to the data in a Node . |
java.util.Set<java.lang.Object> |
getCacheListeners()
Retrieves an immutable List of objects annotated as CacheListener s attached to the cache. |
java.util.Set<java.lang.Object> |
getCacheListeners(Fqn<?> region)
Retrieves an immutable List of objects annotated as CacheListener s attached to a specific region. |
CacheStatus |
getCacheStatus()
Gets where the cache currently is its lifecycle transitions. |
Configuration |
getConfiguration()
Retrieves the configuration of this cache. |
InvocationContext |
getInvocationContext()
|
org.jgroups.Address |
getLocalAddress()
Returns the local address of this cache in a cluster, or null
if running in local mode. |
java.util.List<org.jgroups.Address> |
getMembers()
Returns a list of members in the cluster, or null
if running in local mode. |
Region |
getRegion(Fqn<?> fqn,
boolean createIfAbsent)
Retrieves a Region for a given Fqn . |
Node<K,V> |
getRoot()
Returns the root node of this cache. |
java.lang.String |
getVersion()
Returns the version of the cache as a string. |
void |
move(Fqn<?> nodeToMove,
Fqn<?> newParent)
Moves a part of the cache to a different subtree. |
V |
put(Fqn<?> fqn,
K key,
V value)
Associates the specified value with the specified key for a Node in this cache. |
void |
put(Fqn<?> fqn,
java.util.Map<K,V> data)
Copies all of the mappings from the specified map to a Node . |
void |
putForExternalRead(Fqn<?> fqn,
K key,
V value)
Under special operating behavior, associates the value with the specified key for a node identified by the Fqn passed in. |
V |
remove(Fqn<?> fqn,
K key)
Removes the mapping for this key from a Node. |
void |
removeCacheListener(Fqn<?> region,
java.lang.Object listener)
Removes a @org.jboss.cache.notifications.annotation.CacheListener -annotated object from a given region. |
void |
removeCacheListener(java.lang.Object listener)
Removes a @org.jboss.cache.notifications.annotation.CacheListener -annotated object from the cache. |
boolean |
removeNode(Fqn<?> fqn)
Removes a Node indicated by absolute Fqn . |
boolean |
removeRegion(Fqn<?> fqn)
Removes a region denoted by the Fqn passed in. |
void |
setInvocationContext(InvocationContext ctx)
Sets the passed in InvocationContext as current. |
void |
start()
Lifecycle method that starts the cache loader, starts cache replication, starts the region manager, etc., and (if configured) warms the cache using a state transfer or cache loader preload. |
void |
stop()
Lifecycle method that stops the cache, including replication, clustering, cache loading, notifications, etc., and clears all cache in-memory state. |
Method Detail |
---|
Configuration getConfiguration()
Node<K,V> getRoot()
void addCacheListener(java.lang.Object listener)
@org.jboss.cache.notifications.annotation.CacheListener
-annotated object to the entire cache. The object passed in needs to be properly annotated with the
@org.jboss.cache.notifications.annotation.CacheListener
annotation otherwise an IncorrectCacheListenerException
will be thrown.
listener
- listener to addvoid addCacheListener(Fqn<?> region, java.lang.Object listener)
@org.jboss.cache.notifications.annotation.CacheListener
-annotated object to a given region. The object passed in needs to be properly annotated with the
@org.jboss.cache.notifications.annotation.CacheListener
annotation otherwise an IncorrectCacheListenerException
will be thrown.
region
- region to add listener tolistener
- listener to addvoid removeCacheListener(java.lang.Object listener)
@org.jboss.cache.notifications.annotation.CacheListener
-annotated object from the cache. The object passed in needs to be properly annotated with the
@org.jboss.cache.notifications.annotation.CacheListener
annotation otherwise an IncorrectCacheListenerException
will be thrown.
listener
- listener to removevoid removeCacheListener(Fqn<?> region, java.lang.Object listener)
@org.jboss.cache.notifications.annotation.CacheListener
-annotated object from a given region. The object passed in needs to be properly annotated with the
@org.jboss.cache.notifications.annotation.CacheListener
annotation otherwise an IncorrectCacheListenerException
will be thrown.
region
- region from which to remove listenerlistener
- listener to removejava.util.Set<java.lang.Object> getCacheListeners()
List
of objects annotated as CacheListener
s attached to the cache.
List
of objects annotated as CacheListener
s attached to the cache.java.util.Set<java.lang.Object> getCacheListeners(Fqn<?> region)
List
of objects annotated as CacheListener
s attached to a specific region.
List
of objects annotated as CacheListener
s attached to a specific region.V put(Fqn<?> fqn, K key, V value)
Node
in this cache.
If the Node
previously contained a mapping for this key, the old value is replaced by the specified value.
fqn
- absolute Fqn
to the Node
to be accessed.key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
null
if there was no mapping for key.
A null
return can also indicate that the Node previously associated null
with the specified key, if the implementation supports null values.void putForExternalRead(Fqn<?> fqn, K key, V value)
fqn
- absolute Fqn
to the Node
to be accessed.key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.void put(Fqn<?> fqn, java.util.Map<K,V> data)
Node
.
fqn
- absolute Fqn
to the Node
to copy the data todata
- mappings to copyV remove(Fqn<?> fqn, K key)
null
if the Node contained no mapping for this key.
fqn
- absolute Fqn
to the Node
to be accessed.key
- key whose mapping is to be removed from the Node
boolean removeNode(Fqn<?> fqn)
Node
indicated by absolute Fqn
.
fqn
- Node
to remove
V get(Fqn<?> fqn, K key)
Node
.
fqn
- absolute Fqn
to the Node
to be accessed.key
- key under which value is to be retrieved.
Node
denoted by specified Fqn.void evict(Fqn<?> fqn, boolean recursive)
Node
from memory.
fqn
- absolute Fqn
to the Node
to be evicted.recursive
- evicts children as wellRegion getRegion(Fqn<?> fqn, boolean createIfAbsent)
Region
for a given Fqn
. If the region does not exist,
and
fqn
- Fqn that is contained in a region.createIfAbsent
- If true, will create a new associated region if not found.
java.lang.UnsupportedOperationException
- if the region cannot be defined.Region
boolean removeRegion(Fqn<?> fqn)
fqn
- of the region to remove
void create() throws CacheException
CacheException
- if there are creation problemsvoid start() throws CacheException
CacheException
- if there are startup problemsvoid stop()
void destroy()
create()
and start()
.
CacheStatus getCacheStatus()
null
.InvocationContext getInvocationContext()
InvocationContext
void setInvocationContext(InvocationContext ctx)
InvocationContext
as current.
ctx
- invocation context to useorg.jgroups.Address getLocalAddress()
null
if running in local mode.
null
if running in local mode.java.util.List<org.jgroups.Address> getMembers()
null
if running in local mode.
List
of members in the cluster, or null
if running in local mode.void move(Fqn<?> nodeToMove, Fqn<?> newParent) throws NodeNotExistsException
/a/b/c /a/b/d /a/b/e Fqn f1 = Fqn.fromString("/a/b/c"); Fqn f2 = Fqn.fromString("/a/b/d"); cache.move(f1, f2);Will result in:
/a/b/d/c /a/b/eand now
Fqn f3 = Fqn.fromString("/a/b/e"); Fqn f4 = Fqn.fromString("/a"); cache.move(f3, f4);will result in:
/a/b/d/c /a/eNo-op if the node to be moved is the root node.
nodeToMove
- the Fqn of the node to move.newParent
- new location under which to attach the node being moved.
NodeNotExistsException
- may throw one of these if the target node does not exist or if a different thread has moved this node elsewhere already.java.lang.String getVersion()
Version.printVersion()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |