org.infinispan.tree
Class TreeCacheImpl<K,V>

java.lang.Object
  extended by org.infinispan.batch.AutoBatchSupport
      extended by org.infinispan.tree.TreeStructureSupport
          extended by org.infinispan.tree.TreeCacheImpl<K,V>
All Implemented Interfaces:
Lifecycle, TreeCache<K,V>

public class TreeCacheImpl<K,V>
extends TreeStructureSupport
implements TreeCache<K,V>

Since:
4.0
Author:
Manik Surtani (manik AT jboss DOT org)

Field Summary
 
Fields inherited from class org.infinispan.tree.TreeStructureSupport
cache, icc
 
Fields inherited from class org.infinispan.batch.AutoBatchSupport
batchContainer
 
Constructor Summary
TreeCacheImpl(Cache<?,?> cache)
           
 
Method Summary
 void clearData(Fqn fqn)
          Removes the keys and properties from a named node.
 void clearData(Fqn fqn, Flag... flags)
           
 void clearData(String fqn)
          Convenience method that takes in a String represenation of the Fqn.
 void clearData(String fqn, Flag... flags)
           
 boolean exists(Fqn fqn, Flag... flags)
           
 boolean exists(String f)
          Tests if an Fqn exists.
 boolean exists(String fqn, Flag... flags)
           
 V get(Fqn fqn, K key)
          Convenience method that allows for direct access to the data in a Node.
 V get(Fqn fqn, K key, Flag... flags)
           
 V get(String fqn, K key)
          Convenience method that takes a string representation of an Fqn.
 V get(String fqn, K key, Flag... flags)
           
 Cache<?,?> getCache()
           
 Map<K,V> getData(Fqn fqn)
          Retrieves a defensively copied data map of the underlying node.
 Map<K,V> getData(Fqn fqn, Flag... flags)
           
 Set<K> getKeys(Fqn fqn)
          Returns a set of attribute keys for the Fqn.
 Set<K> getKeys(Fqn fqn, Flag... flags)
           
 Set<K> getKeys(String fqn)
          Convenience method that takes in a String represenation of the Fqn.
 Set<K> getKeys(String fqn, Flag... flags)
           
 Node<K,V> getNode(Fqn fqn)
          A convenience method to retrieve a node directly from the cache.
 Node<K,V> getNode(Fqn fqn, Flag... flags)
           
 Node<K,V> getNode(String fqn)
          Convenience method that takes a string representation of an Fqn.
 Node<K,V> getNode(String fqn, Flag... flags)
           
 Node<K,V> getRoot()
          Returns the root node of this cache.
 Node<K,V> getRoot(Flag... flags)
           
 void move(Fqn nodeToMoveFqn, Fqn newParentFqn)
          Moves a part of the cache to a different subtree.
 void move(Fqn nodeToMove, Fqn newParent, Flag... flags)
           
 void move(String nodeToMove, String newParent)
          Convenience method that takes in string representations of Fqns.
 void move(String nodeToMove, String newParent, Flag... flags)
           
 V put(Fqn fqn, K key, V value)
          Associates the specified value with the specified key for a Node in this cache.
 V put(Fqn fqn, K key, V value, Flag... flags)
           
 void put(Fqn fqn, Map<? extends K,? extends V> data)
          Copies all of the mappings from the specified map to a Node.
 void put(Fqn fqn, Map<? extends K,? extends V> data, Flag... flags)
           
 V put(String fqn, K key, V value)
          Convenience method that takes a string representation of an Fqn.
 V put(String fqn, K key, V value, Flag... flags)
           
 void put(String fqn, Map<? extends K,? extends V> data)
          Convenience method that takes a string representation of an Fqn.
 void put(String fqn, Map<? extends K,? extends V> data, Flag... flags)
           
 V remove(Fqn fqn, K key)
          Removes the mapping for this key from a Node.
 V remove(Fqn fqn, K key, Flag... flags)
           
 V remove(String fqn, K key)
          Convenience method that takes a string representation of an Fqn.
 V remove(String fqn, K key, Flag... flags)
           
 boolean removeNode(Fqn fqn)
          Removes a Node indicated by absolute Fqn.
 boolean removeNode(Fqn fqn, Flag... flags)
           
 boolean removeNode(String fqn)
          Convenience method that takes a string representation of an Fqn.
 boolean removeNode(String fqn, Flag... flags)
           
 void start()
           
 void stop()
           
 String toString()
           
 
Methods inherited from class org.infinispan.tree.TreeStructureSupport
exists, getAtomicMap, isLocked, printTree
 
Methods inherited from class org.infinispan.batch.AutoBatchSupport
assertBatchingSupported, endAtomic, startAtomic
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.infinispan.tree.TreeCache
exists
 

Constructor Detail

TreeCacheImpl

public TreeCacheImpl(Cache<?,?> cache)
Method Detail

getRoot

public Node<K,V> getRoot()
Description copied from interface: TreeCache
Returns the root node of this cache.

Specified by:
getRoot in interface TreeCache<K,V>
Returns:
the root node

getRoot

public Node<K,V> getRoot(Flag... flags)
Specified by:
getRoot in interface TreeCache<K,V>

put

public V put(String fqn,
             K key,
             V value)
Description copied from interface: TreeCache
Convenience method that takes a string representation of an Fqn. Otherwise identical to TreeCache.put(Fqn, Object, Object)

Specified by:
put in interface TreeCache<K,V>
Parameters:
fqn - String representation of the Fqn
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or 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.

put

public V put(String fqn,
             K key,
             V value,
             Flag... flags)
Specified by:
put in interface TreeCache<K,V>

put

public void put(Fqn fqn,
                Map<? extends K,? extends V> data)
Description copied from interface: TreeCache
Copies all of the mappings from the specified map to a Node.

Specified by:
put in interface TreeCache<K,V>
Parameters:
fqn - absolute Fqn to the Node to copy the data to
data - mappings to copy

put

public void put(Fqn fqn,
                Map<? extends K,? extends V> data,
                Flag... flags)
Specified by:
put in interface TreeCache<K,V>

put

public void put(String fqn,
                Map<? extends K,? extends V> data)
Description copied from interface: TreeCache
Convenience method that takes a string representation of an Fqn. Otherwise identical to TreeCache.put(Fqn, java.util.Map)

Specified by:
put in interface TreeCache<K,V>
Parameters:
fqn - String representation of the Fqn
data - data map to insert

put

public void put(String fqn,
                Map<? extends K,? extends V> data,
                Flag... flags)
Specified by:
put in interface TreeCache<K,V>

remove

public V remove(Fqn fqn,
                K key)
Description copied from interface: TreeCache
Removes the mapping for this key from a Node. Returns the value to which the Node previously associated the key, or null if the Node contained no mapping for this key.

Specified by:
remove in interface TreeCache<K,V>
Parameters:
fqn - absolute Fqn to the Node to be accessed.
key - key whose mapping is to be removed from the Node
Returns:
previous value associated with specified Node's key

remove

public V remove(Fqn fqn,
                K key,
                Flag... flags)
Specified by:
remove in interface TreeCache<K,V>

remove

public V remove(String fqn,
                K key)
Description copied from interface: TreeCache
Convenience method that takes a string representation of an Fqn. Otherwise identical to TreeCache.remove(Fqn, Object)

Specified by:
remove in interface TreeCache<K,V>
Parameters:
fqn - string representation of the Fqn to retrieve
key - key to remove
Returns:
old value removed, or null if the fqn does not exist

remove

public V remove(String fqn,
                K key,
                Flag... flags)
Specified by:
remove in interface TreeCache<K,V>

removeNode

public boolean removeNode(Fqn fqn)
Description copied from interface: TreeCache
Removes a Node indicated by absolute Fqn.

Specified by:
removeNode in interface TreeCache<K,V>
Parameters:
fqn - Node to remove
Returns:
true if the node was removed, false if the node was not found

removeNode

public boolean removeNode(Fqn fqn,
                          Flag... flags)
Specified by:
removeNode in interface TreeCache<K,V>

removeNode

public boolean removeNode(String fqn)
Description copied from interface: TreeCache
Convenience method that takes a string representation of an Fqn. Otherwise identical to TreeCache.removeNode(Fqn)

Specified by:
removeNode in interface TreeCache<K,V>
Parameters:
fqn - string representation of the Fqn to retrieve
Returns:
true if the node was found and removed, false otherwise

removeNode

public boolean removeNode(String fqn,
                          Flag... flags)
Specified by:
removeNode in interface TreeCache<K,V>

getNode

public Node<K,V> getNode(Fqn fqn)
Description copied from interface: TreeCache
A convenience method to retrieve a node directly from the cache. Equivalent to calling cache.getRoot().getChild(fqn).

Specified by:
getNode in interface TreeCache<K,V>
Parameters:
fqn - fqn of the node to retrieve
Returns:
a Node object, or a null if the node does not exist.

getNode

public Node<K,V> getNode(Fqn fqn,
                         Flag... flags)
Specified by:
getNode in interface TreeCache<K,V>

getNode

public Node<K,V> getNode(String fqn)
Description copied from interface: TreeCache
Convenience method that takes a string representation of an Fqn. Otherwise identical to TreeCache.getNode(Fqn)

Specified by:
getNode in interface TreeCache<K,V>
Parameters:
fqn - string representation of the Fqn to retrieve
Returns:
node, or null if the node does not exist

getNode

public Node<K,V> getNode(String fqn,
                         Flag... flags)
Specified by:
getNode in interface TreeCache<K,V>

get

public V get(Fqn fqn,
             K key)
Description copied from interface: TreeCache
Convenience method that allows for direct access to the data in a Node.

Specified by:
get in interface TreeCache<K,V>
Parameters:
fqn - absolute Fqn to the Node to be accessed.
key - key under which value is to be retrieved.
Returns:
returns data held under specified key in Node denoted by specified Fqn.

get

public V get(Fqn fqn,
             K key,
             Flag... flags)
Specified by:
get in interface TreeCache<K,V>

exists

public boolean exists(String f)
Description copied from interface: TreeCache
Tests if an Fqn exists. Convenience method for TreeCache.exists(Fqn)

Specified by:
exists in interface TreeCache<K,V>
Parameters:
f - string representation of an Fqn
Returns:
true if the fqn exists, false otherwise

exists

public boolean exists(String fqn,
                      Flag... flags)
Specified by:
exists in interface TreeCache<K,V>

exists

public boolean exists(Fqn fqn,
                      Flag... flags)
Specified by:
exists in interface TreeCache<K,V>

get

public V get(String fqn,
             K key)
Description copied from interface: TreeCache
Convenience method that takes a string representation of an Fqn. Otherwise identical to TreeCache.get(Fqn, Object)

Specified by:
get in interface TreeCache<K,V>
Parameters:
fqn - string representation of the Fqn to retrieve
key - key to fetch
Returns:
value, or null if the fqn does not exist.

get

public V get(String fqn,
             K key,
             Flag... flags)
Specified by:
get in interface TreeCache<K,V>

move

public void move(Fqn nodeToMoveFqn,
                 Fqn newParentFqn)
          throws NodeNotExistsException
Description copied from interface: TreeCache
Moves a part of the cache to a different subtree.

E.g.:

assume a cache structure such as:

  /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/e

and 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/e
 
No-op if the node to be moved is the root node.

Note: As of 3.0.0 and when using MVCC locking, more specific behaviour is defined as follows:

Specified by:
move in interface TreeCache<K,V>
Parameters:
nodeToMoveFqn - the Fqn of the node to move.
newParentFqn - new location under which to attach the node being moved.
Throws:
NodeNotExistsException - may throw one of these if the target node does not exist or if a different thread has moved this node elsewhere already.

move

public void move(Fqn nodeToMove,
                 Fqn newParent,
                 Flag... flags)
          throws NodeNotExistsException
Specified by:
move in interface TreeCache<K,V>
Throws:
NodeNotExistsException

move

public void move(String nodeToMove,
                 String newParent)
          throws NodeNotExistsException
Description copied from interface: TreeCache
Convenience method that takes in string representations of Fqns. Otherwise identical to TreeCache.move(Fqn, Fqn)

Specified by:
move in interface TreeCache<K,V>
Throws:
NodeNotExistsException

move

public void move(String nodeToMove,
                 String newParent,
                 Flag... flags)
          throws NodeNotExistsException
Specified by:
move in interface TreeCache<K,V>
Throws:
NodeNotExistsException

getData

public Map<K,V> getData(Fqn fqn)
Description copied from interface: TreeCache
Retrieves a defensively copied data map of the underlying node. A convenience method to retrieving a node and getting data from the node directly.

Specified by:
getData in interface TreeCache<K,V>
Returns:
map of data, or an empty map

getData

public Map<K,V> getData(Fqn fqn,
                        Flag... flags)
Specified by:
getData in interface TreeCache<K,V>

getKeys

public Set<K> getKeys(String fqn)
Description copied from interface: TreeCache
Convenience method that takes in a String represenation of the Fqn. Otherwise identical to TreeCache.getKeys(Fqn).

Specified by:
getKeys in interface TreeCache<K,V>

getKeys

public Set<K> getKeys(String fqn,
                      Flag... flags)
Specified by:
getKeys in interface TreeCache<K,V>

getKeys

public Set<K> getKeys(Fqn fqn)
Description copied from interface: TreeCache
Returns a set of attribute keys for the Fqn. Returns null if the node is not found, otherwise a Set. The set is a copy of the actual keys for this node.

A convenience method to retrieving a node and getting keys from the node directly.

Specified by:
getKeys in interface TreeCache<K,V>
Parameters:
fqn - name of the node

getKeys

public Set<K> getKeys(Fqn fqn,
                      Flag... flags)
Specified by:
getKeys in interface TreeCache<K,V>

clearData

public void clearData(String fqn)
Description copied from interface: TreeCache
Convenience method that takes in a String represenation of the Fqn. Otherwise identical to TreeCache.clearData(Fqn).

Specified by:
clearData in interface TreeCache<K,V>

clearData

public void clearData(String fqn,
                      Flag... flags)
Specified by:
clearData in interface TreeCache<K,V>

clearData

public void clearData(Fqn fqn)
Description copied from interface: TreeCache
Removes the keys and properties from a named node.

A convenience method to retrieving a node and getting keys from the node directly.

Specified by:
clearData in interface TreeCache<K,V>
Parameters:
fqn - name of the node

clearData

public void clearData(Fqn fqn,
                      Flag... flags)
Specified by:
clearData in interface TreeCache<K,V>

put

public V put(Fqn fqn,
             K key,
             V value)
Description copied from interface: TreeCache
Associates the specified value with the specified key for a Node in this cache. If the Node previously contained a mapping for this key, the old value is replaced by the specified value.

Specified by:
put in interface TreeCache<K,V>
Parameters:
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.
Returns:
previous value associated with specified key, or 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.

put

public V put(Fqn fqn,
             K key,
             V value,
             Flag... flags)
Specified by:
put in interface TreeCache<K,V>

getCache

public Cache<?,?> getCache()
Specified by:
getCache in interface TreeCache<K,V>
Returns:
a reference to the underlying cache instance

start

public void start()
           throws CacheException
Specified by:
start in interface Lifecycle
Throws:
CacheException

stop

public void stop()
Specified by:
stop in interface Lifecycle

toString

public String toString()
Overrides:
toString in class Object

Google Analytics

Copyright © 2010 JBoss, a division of Red Hat. All Rights Reserved.