|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jboss.cache.AbstractNode<K,V> org.jboss.cache.optimistic.WorkspaceNodeImpl<K,V>
public class WorkspaceNodeImpl<K,V>
Wraps an ordinary Node
and adds versioning and other meta data to it.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.jboss.cache.AbstractNode |
---|
AbstractNode.NodeFlags |
Field Summary |
---|
Fields inherited from class org.jboss.cache.AbstractNode |
---|
children, flags, fqn |
Constructor Summary | |
---|---|
WorkspaceNodeImpl(NodeSPI<K,V> node,
TransactionWorkspace workspace)
Constructs with a node and workspace. |
Method Summary | |
---|---|
Node<K,V> |
addChild(Fqn f)
Adds a child node with the given Fqn under the current node. |
void |
addChild(WorkspaceNode<K,V> child)
Adds a given WorkspaceNode to the current node's child map |
void |
clearData()
Removes all mappings from the node's data map. |
NodeSPI<K,V> |
createChild(Object child_name,
NodeSPI<K,V> parent,
CacheSPI<K,V> cache,
DataVersion version)
Creates a child node. |
int |
dataSize()
|
V |
get(K key)
Returns the value to which this node maps the specified key. |
protected CacheSPI<K,V> |
getCache()
|
NodeSPI<K,V> |
getChild(Fqn f)
Returns the child node |
NodeSPI<K,V> |
getChild(Object childName)
Overrides Node.getChild(Object) to return a NodeSPI rather than a Node |
Set<Node<K,V>> |
getChildren()
Returns an immutable set of children nodes. |
protected Set<Fqn> |
getChildrenAddedSet()
|
Set<Object> |
getChildrenNames()
Returns an immutable set of children node names. |
protected Set<Fqn> |
getChildrenRemovedSet()
|
Map<K,V> |
getData()
Returns a map containing the data in this Node . |
Fqn |
getFqn()
Returns the Fqn which represents the location of this Node in the cache structure. |
Set<K> |
getKeys()
Returns a Set containing the data in this Node . |
List<Set<Fqn>> |
getMergedChildren()
Returns 2 Sets - a set of children added (first set) and a set of children removed. |
Map<K,V> |
getMergedData()
Attempts to merge data changed during the current transaction with the data in the underlying tree. |
NodeSPI<K,V> |
getNode()
Retrieves a reference to the underlying NodeSPI instance. |
NodeSPI<K,V> |
getNodeSPI()
|
Node<K,V> |
getParent()
Returns the parent node. |
TransactionWorkspace |
getTransactionWorkspace()
Retrieves a TransactionWorkspace instance associated with the current transaction, which the current WorkspaceNode instance lives in. |
DataVersion |
getVersion()
Retrieves the data version of the in-memory node. |
boolean |
hasChild(Fqn f)
Returns true if the child node denoted by the relative Fqn passed in exists. |
boolean |
hasChild(Object o)
Returns true if the child node denoted by the Object name passed in exists. |
protected void |
initFlags()
|
boolean |
isChildrenLoaded()
|
boolean |
isChildrenModified()
|
boolean |
isCreated()
|
boolean |
isDirty()
A convenience method that returns whether a node is dirty, i.e., it has been created, deleted or modified. |
boolean |
isLockForChildInsertRemove()
Tests whether this node is configured to be exclusively locked when inserting or removing children. |
boolean |
isModified()
Returns true if this node is modified. |
boolean |
isResurrected()
|
boolean |
isValid()
Tests if a node reference is still valid. |
boolean |
isVersioningImplicit()
Tests whether versioning for the WorkspaceNode instance in the current transaction is implicit (i.e., using DefaultDataVersion
rather than a custom DataVersion passed in using Option.setDataVersion(DataVersion) ) |
void |
markAsCreated()
Marks the instance as having been created in the current transaction. |
void |
markAsDeleted(boolean marker,
boolean recursive)
Same as WorkspaceNode.markAsDeleted(boolean) except that the option to recurse into children is provided. |
void |
markAsResurrected(boolean resurrected)
Marks a node as resurrected, i.e., deleted and created again within the same transaction |
V |
put(K key,
V value)
Associates the specified value with the specified key for this node. |
void |
putAll(Map<K,V> data)
Copies all of the mappings from the specified map to this node's map. |
V |
putIfAbsent(K k,
V v)
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. |
void |
releaseObjectReferences(boolean recursive)
Method that releases object references of cached objects held in the cache by serializing them to byte buffers. |
V |
remove(K key)
Removes the mapping for this key from this node if it is present. |
boolean |
removeChild(Fqn f)
Removes a child node specified by the given relative Fqn . |
boolean |
removeChild(Object childName)
Removes a child node specified by the given name. |
V |
replace(K key,
V value)
Replace entry for key only if currently mapped to some value. |
boolean |
replace(K key,
V oldValue,
V newValue)
Replace entry for key only if currently mapped to given value. |
void |
replaceAll(Map<K,V> data)
Similar to Node.putAll(java.util.Map) except that it removes any entries that exists in
the data map first. |
void |
setLockForChildInsertRemove(boolean lockForChildInsertRemove)
Configures the behaviour of how this node is locked when adding/removing children. |
void |
setVersion(DataVersion version)
Sets the data version of this workspace node. |
void |
setVersioningImplicit(boolean versioningImplicit)
Sets whether versioning for the WorkspaceNode instance in the current transaction is implicit (i.e., using DefaultDataVersion
rather than a custom DataVersion passed in using Option.setDataVersion(DataVersion) ) |
String |
toString()
|
Methods inherited from class org.jboss.cache.AbstractNode |
---|
equals, hashCode, isDeleted, isFlagSet, isResident, markAsDeleted, setFlag, setFlag, setResident, unsetFlag |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.jboss.cache.optimistic.WorkspaceNode |
---|
isDeleted, markAsDeleted |
Methods inherited from interface org.jboss.cache.Node |
---|
isResident, setResident |
Constructor Detail |
---|
public WorkspaceNodeImpl(NodeSPI<K,V> node, TransactionWorkspace workspace)
Method Detail |
---|
protected void initFlags()
protected Set<Fqn> getChildrenAddedSet()
protected Set<Fqn> getChildrenRemovedSet()
public boolean isChildrenModified()
isChildrenModified
in interface WorkspaceNode<K,V>
public boolean isChildrenLoaded()
isChildrenLoaded
in interface WorkspaceNode<K,V>
public boolean isResurrected()
isResurrected
in interface WorkspaceNode<K,V>
public void markAsResurrected(boolean resurrected)
WorkspaceNode
markAsResurrected
in interface WorkspaceNode<K,V>
public void markAsDeleted(boolean marker, boolean recursive)
WorkspaceNode
WorkspaceNode.markAsDeleted(boolean)
except that the option to recurse into children is provided.
markAsDeleted
in interface WorkspaceNode<K,V>
markAsDeleted
in class AbstractNode<K,V>
marker
- true if the node has been deleted, false if not.recursive
- if true, child nodes (and their children) are marked as well.public boolean isModified()
isModified
in interface WorkspaceNode<K,V>
public boolean isDirty()
isDirty
in interface WorkspaceNode<K,V>
public Fqn getFqn()
Node
Fqn
which represents the location of this Node
in the cache structure. The Fqn
returned is absolute.
getFqn
in interface Node<K,V>
Fqn
which represents the location of this Node
in the cache structure. The Fqn
returned is absolute.public void putAll(Map<K,V> data)
Node
Node node; for (Map.Entry me : map.entrySet()) node.put(me.getKey(), me.getValue());
putAll
in interface Node<K,V>
data
- map to copy frompublic void replaceAll(Map<K,V> data)
Node
Node.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 a Node.clearData()
followed by a Node.putAll(java.util.Map)
in the same transaction.
replaceAll
in interface Node<K,V>
data
- map to copy frompublic V put(K key, V value)
Node
put
in interface Node<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
public V remove(K key)
Node
null
if the node contained no mapping for this key
remove
in interface Node<K,V>
key
- key whose mapping is to be removed
null
if there was no mapping for keypublic V get(K key)
Node
null
if the node contains no mapping for this key.
get
in interface Node<K,V>
key
- key of the data to return
null
if the map contains no mapping for this keypublic Set<K> getKeys()
Node
Set
containing the data in this Node
.
getKeys
in interface Node<K,V>
Set
containing the data in this Node
. If there is no data, an empty Set
is returned. The Set
returned is always immutable.public Set<Object> getChildrenNames()
Node
getChildrenNames
in interface Node<K,V>
Set
of child node names. Empty Set
if there aren't any children.public Node<K,V> getParent()
Node
null
.
getParent
in interface Node<K,V>
public NodeSPI<K,V> createChild(Object child_name, NodeSPI<K,V> parent, CacheSPI<K,V> cache, DataVersion version)
WorkspaceNode
createChild
in interface WorkspaceNode<K,V>
child_name
- Object name of the child to createparent
- A reference to the parent nodecache
- CacheSPI instance to create this node inversion
- DataVersion to apply to the child. If null, DefaultDataVersion.ZERO
will be used.
public boolean isVersioningImplicit()
WorkspaceNode
DefaultDataVersion
rather than a custom DataVersion
passed in using Option.setDataVersion(DataVersion)
)
isVersioningImplicit
in interface WorkspaceNode<K,V>
public void setVersioningImplicit(boolean versioningImplicit)
WorkspaceNode
DefaultDataVersion
rather than a custom DataVersion
passed in using Option.setDataVersion(DataVersion)
)
setVersioningImplicit
in interface WorkspaceNode<K,V>
versioningImplicit
- set to true if versioning is implicit, false otherwise.public NodeSPI<K,V> getChild(Object childName)
WorkspaceNode
Node.getChild(Object)
to return a NodeSPI
rather than a Node
getChild
in interface Node<K,V>
getChild
in interface WorkspaceNode<K,V>
childName
- name of the child
public NodeSPI<K,V> getNode()
WorkspaceNode
NodeSPI
instance.
getNode
in interface WorkspaceNode<K,V>
public DataVersion getVersion()
WorkspaceNode
getVersion
in interface WorkspaceNode<K,V>
public void setVersion(DataVersion version)
WorkspaceNode
setVersion
in interface WorkspaceNode<K,V>
version
- a DataVersion
implementation.public List<Set<Fqn>> getMergedChildren()
WorkspaceNode
getMergedChildren
in interface WorkspaceNode<K,V>
public Map<K,V> getMergedData()
WorkspaceNode
getMergedData
in interface WorkspaceNode<K,V>
public TransactionWorkspace getTransactionWorkspace()
WorkspaceNode
getTransactionWorkspace
in interface WorkspaceNode<K,V>
public boolean isCreated()
isCreated
in interface WorkspaceNode<K,V>
public void markAsCreated()
WorkspaceNode
markAsCreated
in interface WorkspaceNode<K,V>
public Map<K,V> getData()
Node
Node
.
getData
in interface Node<K,V>
Map
containing the data in this Node
. If there is no data, an empty Map
is returned. The Map
returned is always immutable.public String toString()
toString
in class Object
public Node<K,V> addChild(Fqn f)
Node
Fqn
under the current node. Returns the newly created node.
If the child exists returns the child node anyway. Guaranteed to return a non-null node.
The Fqn
passed in is relative to the current node. The new child node will have an absolute fqn
calculated as follows: new Fqn(getFqn(), f). See
Fqn
for the operation of this constructor.
addChild
in interface Node<K,V>
f
- Fqn
of the child node, relative to the current node.
public void addChild(WorkspaceNode<K,V> child)
WorkspaceNode
addChild
in interface WorkspaceNode<K,V>
public void clearData()
Node
clearData
in interface Node<K,V>
public int dataSize()
dataSize
in interface Node<K,V>
public boolean hasChild(Object o)
Node
hasChild
in interface Node<K,V>
o
- name of the child, relative to the current node
public boolean isValid()
Node
NodeNotValidException
.
isValid
in interface Node<K,V>
public boolean isLockForChildInsertRemove()
Node
Configuration.isLockParentForChildInsertRemove()
This can also be configured on a per-node basis using Node.setLockForChildInsertRemove(boolean)
isLockForChildInsertRemove
in interface Node<K,V>
public void setLockForChildInsertRemove(boolean lockForChildInsertRemove)
Node
setLockForChildInsertRemove
in interface Node<K,V>
lockForChildInsertRemove
- if true, exclusive locks will be obtained when children are added/removed. If
false, a shared "read lock" will be obtained instead.public void releaseObjectReferences(boolean recursive)
Node
releaseObjectReferences
in interface Node<K,V>
recursive
- if true, child nodes will have their object references released as well.public NodeSPI<K,V> getChild(Fqn f)
Node
getChild
in interface Node<K,V>
getChild
in interface WorkspaceNode<K,V>
f
- Fqn
of the child node
public Set<Node<K,V>> getChildren()
Node
getChildren
in interface Node<K,V>
Set
of child nodes. Empty Set
if there aren't any children.public boolean hasChild(Fqn f)
Node
Fqn
passed in exists.
hasChild
in interface Node<K,V>
f
- Fqn
relative to the current node of the child you are testing the existence of.
Fqn
passed in exists.public NodeSPI<K,V> getNodeSPI()
public V putIfAbsent(K k, V v)
Node
if (!node.getKeys().contains(key)) return node.put(key, value); else return node.get(key);except that this is atomic.
putIfAbsent
in interface Node<K,V>
k
- key with which the specified value is to be associated.v
- value to be associated with the specified key.
public V replace(K key, V value)
Node
if ((node.getKeys().contains(key)) { return node.put(key, value); } else return null;except that this is atomic.
replace
in interface Node<K,V>
key
- key with which the specified value is associated.value
- value to be associated with the specified key.
public boolean replace(K key, V oldValue, V newValue)
Node
if (node.get(key).equals(oldValue)) { node.put(key, newValue); return true; } else return false;except that this is atomic.
replace
in interface Node<K,V>
key
- key with which the specified value is associated.oldValue
- value expected to be associated with the specified key.newValue
- value to be associated with the specified key.
public boolean removeChild(Fqn f)
Node
Fqn
.
If you wish to remove children based on absolute Fqn
s, use the Cache
interface instead.
removeChild
in interface Node<K,V>
f
- Fqn
of the child node, relative to the current node.
public boolean removeChild(Object childName)
Node
removeChild
in interface Node<K,V>
childName
- name of the child node, directly under the current node.
protected CacheSPI<K,V> getCache()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |