Package org.infinispan.tree.impl
Class NodeImpl<K,V>
- java.lang.Object
-
- org.infinispan.batch.AutoBatchSupport
-
- org.infinispan.tree.impl.TreeStructureSupport
-
- org.infinispan.tree.impl.NodeImpl<K,V>
-
- All Implemented Interfaces:
Node<K,V>
public class NodeImpl<K,V> extends TreeStructureSupport implements Node<K,V>
Implementation backed by anAtomicMap- Since:
- 4.0
- Author:
- Manik Surtani (manik AT jboss DOT org)
-
-
Field Summary
-
Fields inherited from class org.infinispan.tree.impl.TreeStructureSupport
cache
-
Fields inherited from class org.infinispan.batch.AutoBatchSupport
batchContainer
-
-
Constructor Summary
Constructors Constructor Description NodeImpl(Fqn fqn, AdvancedCache<?,?> cache, BatchContainer batchContainer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Node<K,V>addChild(Fqn f)Adds a child node with the givenFqnunder the current node.Node<K,V>addChild(Fqn f, Flag... flags)voidclearData()Removes all mappings from the node's data map.voidclearData(Flag... flags)intdataSize()intdataSize(Flag... flags)booleanequals(Object o)Vget(K key)Returns the value to which this node maps the specified key.Vget(K key, Flag... flags)Node<K,V>getChild(Object name)Node<K,V>getChild(Object name, Flag... flags)Node<K,V>getChild(Fqn f)Returns the child nodeNode<K,V>getChild(Fqn f, Flag... flags)Set<Node<K,V>>getChildren()Returns an immutable set of children nodes.Set<Node<K,V>>getChildren(Flag... flags)Set<Object>getChildrenNames()Returns an immutable set of children node names.Set<Object>getChildrenNames(Flag... flags)Map<K,V>getData()Returns a map containing the data in thisNode.Map<K,V>getData(Flag... flags)FqngetFqn()Set<K>getKeys()Set<K>getKeys(Flag... flags)Node<K,V>getParent()Returns the parent node.Node<K,V>getParent(Flag... flags)booleanhasChild(Object o)Returns true if the child node denoted by the Object name passed in exists.booleanhasChild(Object o, Flag... flags)booleanhasChild(Fqn f)Returns true if the child node denoted by the relativeFqnpassed in exists.booleanhasChild(Fqn f, Flag... flags)inthashCode()booleanisValid()Tests if a node reference is still valid.Vput(K key, V value)Associates the specified value with the specified key for this node.Vput(K key, V value, Flag... flags)voidputAll(Map<? extends K,? extends V> map)Copies all of the mappings from the specified map to this node's map.voidputAll(Map<? extends K,? extends V> map, Flag... flags)VputIfAbsent(K key, V value)If the specified key is not already associated with a value, associate it with the given value, and returns the Object (if any) that occupied the space, or null.VputIfAbsent(K key, V value, Flag... flags)Vremove(K key)Removes the mapping for this key from this node if it is present.Vremove(K key, Flag... flags)booleanremoveChild(Object childName)Removes a child node specified by the given name.booleanremoveChild(Object childName, Flag... flags)booleanremoveChild(AdvancedCache<?,?> cache, Fqn f)booleanremoveChild(Fqn f)Removes a child node specified by the given relativeFqn.booleanremoveChild(Fqn f, Flag... flags)voidremoveChildren()voidremoveChildren(Flag... flags)Vreplace(K key, V value)Replace entry for key only if currently mapped to some value.Vreplace(K key, V value, Flag... flags)booleanreplace(K key, V oldValue, V newValue)Replace entry for key only if currently mapped to given value.booleanreplace(K key, V oldValue, V newValue, Flag... flags)voidreplaceAll(Map<? extends K,? extends V> map)Similar toNode.putAll(java.util.Map)except that it removes any entries that exists in the data map first.voidreplaceAll(Map<? extends K,? extends V> map, Flag... flags)StringtoString()-
Methods inherited from class org.infinispan.tree.impl.TreeStructureSupport
createNodeInCache, exists, exists, getAtomicMap, getAtomicMap, isLocked, printTree
-
Methods inherited from class org.infinispan.batch.AutoBatchSupport
assertBatchingSupported, endAtomic, failAtomic, startAtomic
-
-
-
-
Constructor Detail
-
NodeImpl
public NodeImpl(Fqn fqn, AdvancedCache<?,?> cache, BatchContainer batchContainer)
-
-
Method Detail
-
getParent
public Node<K,V> getParent()
Description copied from interface:NodeReturns the parent node. If this is the root node, this method returnsthis.
-
getChildren
public Set<Node<K,V>> getChildren()
Description copied from interface:NodeReturns an immutable set of children nodes.
-
getChildren
public Set<Node<K,V>> getChildren(Flag... flags)
- Specified by:
getChildrenin interfaceNode<K,V>
-
getChildrenNames
public Set<Object> getChildrenNames()
Description copied from interface:NodeReturns an immutable set of children node names.
-
getChildrenNames
public Set<Object> getChildrenNames(Flag... flags)
- Specified by:
getChildrenNamesin interfaceNode<K,V>
-
getData
public Map<K,V> getData()
Description copied from interface:NodeReturns a map containing the data in thisNode.
-
addChild
public Node<K,V> addChild(Fqn f)
Description copied from interface:NodeAdds a child node with the givenFqnunder the current node. Returns the newly created node. If the child exists returns the child node anyway. Guaranteed to return a non-null node. TheFqnpassed in is relative to the current node. The new child node will have an absolute fqn calculated as follows:new Fqn(getFqn(), f)
. SeeFqnfor the operation of this constructor.
-
removeChild
public boolean removeChild(Fqn f)
Description copied from interface:NodeRemoves a child node specified by the given relativeFqn. If you wish to remove children based on absoluteFqns, use theTreeCacheinterface instead.- Specified by:
removeChildin interfaceNode<K,V>- Parameters:
f-Fqnof the child node, relative to the current node.- Returns:
- true if the node was found and removed, false otherwise
-
removeChild
public boolean removeChild(Fqn f, Flag... flags)
- Specified by:
removeChildin interfaceNode<K,V>
-
removeChild
public boolean removeChild(AdvancedCache<?,?> cache, Fqn f)
-
removeChild
public boolean removeChild(Object childName)
Description copied from interface:NodeRemoves a child node specified by the given name.- Specified by:
removeChildin interfaceNode<K,V>- Parameters:
childName- name of the child node, directly under the current node.- Returns:
- true if the node was found and removed, false otherwise
-
removeChild
public boolean removeChild(Object childName, Flag... flags)
- Specified by:
removeChildin interfaceNode<K,V>
-
getChild
public Node<K,V> getChild(Fqn f)
Description copied from interface:NodeReturns the child node
-
put
public V put(K key, V value)
Description copied from interface:NodeAssociates the specified value with the specified key for this node. If this node previously contained a mapping for this key, the old value is replaced by the specified value.
-
putIfAbsent
public V putIfAbsent(K key, V value)
Description copied from interface:NodeIf the specified key is not already associated with a value, associate it with the given value, and returns the Object (if any) that occupied the space, or null. Equivalent to callingif (!node.getKeys().contains(key)) return node.put(key, value); else return node.get(key);except that this is atomic.- Specified by:
putIfAbsentin interfaceNode<K,V>- Parameters:
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.
-
putIfAbsent
public V putIfAbsent(K key, V value, Flag... flags)
- Specified by:
putIfAbsentin interfaceNode<K,V>
-
replace
public V replace(K key, V value)
Description copied from interface:NodeReplace entry for key only if currently mapped to some value. Acts asif ((node.getKeys().contains(key)) { return node.put(key, value); } else return null;except that this is atomic.
-
replace
public boolean replace(K key, V oldValue, V newValue)
Description copied from interface:NodeReplace entry for key only if currently mapped to given value. Acts asif (node.get(key).equals(oldValue)) { node.put(key, newValue); return true; } else return false;except that this is atomic.
-
putAll
public void putAll(Map<? extends K,? extends V> map)
Description copied from interface:NodeCopies all of the mappings from the specified map to this node's map. If any data exists, existing keys are overwritten with the keys in the new map. The behavior is equivalent to:Node node; for (Map.Entry me : map.entrySet()) node.put(me.getKey(), me.getValue());
-
replaceAll
public void replaceAll(Map<? extends K,? extends V> map)
Description copied from interface:NodeSimilar toNode.putAll(java.util.Map)except that it removes any entries that exists in the data map first. Note that this happens atomically, under a single lock. This is the analogous to doing aNode.clearData()followed by aNode.putAll(java.util.Map)in the same transaction.- Specified by:
replaceAllin interfaceNode<K,V>- Parameters:
map- map to copy from
-
replaceAll
public void replaceAll(Map<? extends K,? extends V> map, Flag... flags)
- Specified by:
replaceAllin interfaceNode<K,V>
-
get
public V get(K key)
Description copied from interface:NodeReturns the value to which this node maps the specified key. Returnsnullif the node contains no mapping for this key.
-
remove
public V remove(K key)
Description copied from interface:NodeRemoves the mapping for this key from this node if it is present. Returns the value to which the node previously associated the key, ornullif the node contained no mapping for this key
-
clearData
public void clearData()
Description copied from interface:NodeRemoves all mappings from the node's data map.
-
dataSize
public int dataSize()
-
hasChild
public boolean hasChild(Fqn f)
Description copied from interface:NodeReturns true if the child node denoted by the relativeFqnpassed in exists.
-
hasChild
public boolean hasChild(Object o)
Description copied from interface:NodeReturns true if the child node denoted by the Object name passed in exists.
-
isValid
public boolean isValid()
Description copied from interface:NodeTests if a node reference is still valid. A node reference may become invalid if it has been removed, invalidated or moved, either locally or remotely. If a node is invalid, it should be fetched again from the cache or a valid parent node. Operations on invalid nodes will throw aNodeNotValidException.
-
removeChildren
public void removeChildren()
- Specified by:
removeChildrenin interfaceNode<K,V>
-
removeChildren
public void removeChildren(Flag... flags)
- Specified by:
removeChildrenin interfaceNode<K,V>
-
-