org.jboss.cache
Class DataContainerImpl

java.lang.Object
  extended by org.jboss.cache.DataContainerImpl
All Implemented Interfaces:
DataContainer

public class DataContainerImpl
extends Object
implements DataContainer

A container for the root node in the cache, which also provides helpers for efficiently accessing nodes, walking trees, etc.

Since:
2.2
Author:
Mircea.Markus@jboss.com

Constructor Summary
DataContainerImpl()
           
 
Method Summary
 List<NodeData> buildNodeData(List<NodeData> list, NodeSPI node)
          Prepares a list of NodeData objects for a specified node and all its children.
 Object[] createNodes(Fqn fqn)
          Traverses the tree to the given Fqn, creating nodes if needed.
 void createRootNode()
           
 boolean evict(Fqn fqn)
           Following scenarios define how eviction works.
 void evict(Fqn fqn, boolean recursive)
          Evicts the given node.
 boolean exists(Fqn fqn)
          Tests if an Fqn exists and is valid and not deleted.
 Set<Fqn> getInternalFqns()
          Returns a Set of Fqns of the topmost node of internal regions that should not included in standard state transfers.
 List<Fqn> getNodesForEviction(Fqn fqn, boolean recursive)
          Generates a list of nodes for eviction.
 int getNumberOfAttributes()
          Returns an approximation of the total number of attributes in the cache.
 int getNumberOfAttributes(Fqn fqn)
          Returns an approximation of the total number of attributes in this sub cache.
 int getNumberOfLocksHeld()
          Returns the number of read or write locks held across the entire cache.
 int getNumberOfNodes()
          Returns an approximation of the total number of nodes in the cache.
 NodeSPI getRoot()
          Retrieves the root node.
 boolean hasChildren(Fqn fqn)
          Returns true if the Fqn exists, is valid and is not deleted, and the node has children.
 void injectDependencies(Configuration configuration, NodeFactory nodeFactory, LockManager lockManager, BuddyFqnTransformer transformer)
           
 NodeSPI peek(Fqn fqn)
          Finds a node given a fully qualified name, directly off the interceptor chain.
 NodeSPI peek(Fqn<?> fqn, boolean includeDeletedNodes)
          Same as calling peek(fqn, includeDeletedNodes, false).
 NodeSPI peek(Fqn<?> fqn, boolean includeDeletedNodes, boolean includeInvalidNodes)
          Peeks for a specified node.
 NodeSPI peekStrict(GlobalTransaction gtx, Fqn fqn, boolean includeInvalid)
          Similar to DataContainer.peekVersioned(Fqn, org.jboss.cache.optimistic.DataVersion) except that it throws a NodeNotExistsException if the node cannot be found.
 NodeSPI peekVersioned(Fqn fqn, DataVersion version)
          Finds a node given a fully qualified name and DataVersion.
 NodeSPI peekVersioned(Fqn fqn, DataVersion version, boolean includeInvalidNodes)
          Searches for a specific node, with a specific data version and, optionally, invalid nodes as well, but not deleted nodes.
 String printDetails()
          Prints information about the contents of the nodes in the cache's current in-memory state.
 String printLockInfo()
          Returns lock information.
 void registerInternalFqn(Fqn fqn)
          Adds the specified Fqn to the list of Fqns to be considered "internal".
protected  void removeData(Fqn fqn)
           
 boolean removeFromDataStructure(Fqn f, boolean skipMarkerCheck)
          Removes the actual node from the tree data structure.
 void setBuddyFqnTransformer(BuddyFqnTransformer buddyFqnTransformer)
           
 void setDependencies(Configuration configuration, NodeFactory nodeFactory, LockManager lockManager)
           
 void setRoot(NodeSPI root)
          Sets the root node reference to the node passed in.
 void stop()
           
 String toString()
           
 String toString(boolean details)
          Returns a debug string with optional details of contents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataContainerImpl

public DataContainerImpl()
Method Detail

injectDependencies

public void injectDependencies(Configuration configuration,
                               NodeFactory nodeFactory,
                               LockManager lockManager,
                               BuddyFqnTransformer transformer)

setDependencies

public void setDependencies(Configuration configuration,
                            NodeFactory nodeFactory,
                            LockManager lockManager)

createRootNode

public void createRootNode()

stop

public void stop()

getRoot

public NodeSPI getRoot()
Description copied from interface: DataContainer
Retrieves the root node.

Specified by:
getRoot in interface DataContainer
Returns:
the root node

setRoot

public void setRoot(NodeSPI root)
Sets the root node reference to the node passed in.

Parameters:
root - node

registerInternalFqn

public void registerInternalFqn(Fqn fqn)
Description copied from interface: DataContainer
Adds the specified Fqn to the list of Fqns to be considered "internal".

Specified by:
registerInternalFqn in interface DataContainer
Parameters:
fqn - fqn to add to list

peek

public NodeSPI peek(Fqn fqn)
Finds a node given a fully qualified name, directly off the interceptor chain. In the event of an exception, returns null. Does not include invalid or deleted nodes.

Specified by:
peek in interface DataContainer
Parameters:
fqn - Fully qualified name for the corresponding node.
Returns:
Node referenced by the given Fqn, or null if the node cannot be found or if there is an exception.

peekStrict

public NodeSPI peekStrict(GlobalTransaction gtx,
                          Fqn fqn,
                          boolean includeInvalid)
Description copied from interface: DataContainer
Similar to DataContainer.peekVersioned(Fqn, org.jboss.cache.optimistic.DataVersion) except that it throws a NodeNotExistsException if the node cannot be found.

Specified by:
peekStrict in interface DataContainer
Parameters:
gtx - global transaction
fqn - fqn to find
includeInvalid - if true, invalid nodes are considered as well.
Returns:
the node

peekVersioned

public NodeSPI peekVersioned(Fqn fqn,
                             DataVersion version)
Description copied from interface: DataContainer
Finds a node given a fully qualified name and DataVersion. Does not include invalid or deleted nodes. If the data version passed in is null, then data version checking is skipped. Data version checking is also skipped if optimistic locking is not used.

Specified by:
peekVersioned in interface DataContainer
Parameters:
fqn - fqn to find
version - version of the node to find
Returns:
a node, if found, or null if not.

peekVersioned

public NodeSPI peekVersioned(Fqn fqn,
                             DataVersion version,
                             boolean includeInvalidNodes)
Description copied from interface: DataContainer
Searches for a specific node, with a specific data version and, optionally, invalid nodes as well, but not deleted nodes. If the data version passed in is null, then data version checking is skipped. Data version checking is also skipped if optimistic locking is not used.

Specified by:
peekVersioned in interface DataContainer
Parameters:
fqn - Fqn to find
version - version of the node to find
includeInvalidNodes - if true, invalid nodes are considered
Returns:
the node, if found, or null otherwise.

peek

public NodeSPI peek(Fqn<?> fqn,
                    boolean includeDeletedNodes)
Description copied from interface: DataContainer
Same as calling peek(fqn, includeDeletedNodes, false).

Specified by:
peek in interface DataContainer
Parameters:
fqn - Fqn to find
includeDeletedNodes - if true, deleted nodes are considered
Returns:
the node, if found, or null otherwise.

peek

public NodeSPI peek(Fqn<?> fqn,
                    boolean includeDeletedNodes,
                    boolean includeInvalidNodes)
Description copied from interface: DataContainer
Peeks for a specified node. This involves a direct walk of the tree, starting at the root, until the required node is found. If the node is not found, a null is returned.

Specified by:
peek in interface DataContainer
Parameters:
fqn - Fqn of the node to find
includeDeletedNodes - if true, deleted nodes are also considered
includeInvalidNodes - if true, invalid nodes are also considered
Returns:
the node, if found, or null otherwise.

exists

public boolean exists(Fqn fqn)
Description copied from interface: DataContainer
Tests if an Fqn exists and is valid and not deleted.

Specified by:
exists in interface DataContainer
Parameters:
fqn - the fqn representing the node to test
Returns:
true if the node exists, false otherwise.

hasChildren

public boolean hasChildren(Fqn fqn)
Description copied from interface: DataContainer
Returns true if the Fqn exists, is valid and is not deleted, and the node has children.

Specified by:
hasChildren in interface DataContainer
Parameters:
fqn - the fqn to test
Returns:
true if the Fqn exists, is valid and is not deleted, and the node has children.

buildNodeData

public List<NodeData> buildNodeData(List<NodeData> list,
                                    NodeSPI node)
Description copied from interface: DataContainer
Prepares a list of NodeData objects for a specified node and all its children.

Specified by:
buildNodeData in interface DataContainer
Parameters:
list - List of NodeData objects, which will be added to.
node - node to recursively add to the list
Returns:
the same list passed in

getNodesForEviction

public List<Fqn> getNodesForEviction(Fqn fqn,
                                     boolean recursive)
Description copied from interface: DataContainer
Generates a list of nodes for eviction. This filters out nodes that cannot be evicted, such as those which are marked as resident. See Node.setResident(boolean).

Specified by:
getNodesForEviction in interface DataContainer
Parameters:
fqn - the node to consider for eviction
recursive - if recursive, child nodes are also considered
Returns:
a list of Fqns that can be considered for eviction

toString

public String toString()
Overrides:
toString in class Object

getInternalFqns

public Set<Fqn> getInternalFqns()
Description copied from interface: DataContainer
Returns a Set of Fqns of the topmost node of internal regions that should not included in standard state transfers. Will include BuddyManager.BUDDY_BACKUP_SUBTREE if buddy replication is enabled.

Specified by:
getInternalFqns in interface DataContainer
Returns:
an unmodifiable Set. Will not return null.

toString

public String toString(boolean details)
Returns a debug string with optional details of contents.

Parameters:
details - if true, details are printed
Returns:
detailed contents of the container

getNumberOfLocksHeld

public int getNumberOfLocksHeld()
Description copied from interface: DataContainer
Returns the number of read or write locks held across the entire cache.

Specified by:
getNumberOfLocksHeld in interface DataContainer

getNumberOfNodes

public int getNumberOfNodes()
Description copied from interface: DataContainer
Returns an approximation of the total number of nodes in the cache. Since this method doesn't acquire any locks, the number might be incorrect, or the method might even throw a ConcurrentModificationException

Specified by:
getNumberOfNodes in interface DataContainer

printDetails

public String printDetails()
Prints information about the contents of the nodes in the cache's current in-memory state. Does not load any previously evicted nodes from a cache loader, so evicted nodes will not be included.

Returns:
details

printLockInfo

public String printLockInfo()
Returns lock information.

Returns:
lock info

getNumberOfAttributes

public int getNumberOfAttributes(Fqn fqn)
Description copied from interface: DataContainer
Returns an approximation of the total number of attributes in this sub cache.

Specified by:
getNumberOfAttributes in interface DataContainer

getNumberOfAttributes

public int getNumberOfAttributes()
Returns an approximation of the total number of attributes in the cache. Since this method doesn't acquire any locks, the number might be incorrect, or the method might even throw a ConcurrentModificationException

Specified by:
getNumberOfAttributes in interface DataContainer
Returns:
number of attribs

removeFromDataStructure

public boolean removeFromDataStructure(Fqn f,
                                       boolean skipMarkerCheck)
Description copied from interface: DataContainer
Removes the actual node from the tree data structure.

Specified by:
removeFromDataStructure in interface DataContainer
Parameters:
f - the Fqn of the node to remove
skipMarkerCheck - if true, skips checking the boolean NodeSPI.isDeleted() flag and deletes the node anyway.
Returns:
Returns true if the node was found and removed, false if not.

evict

public void evict(Fqn fqn,
                  boolean recursive)
Description copied from interface: DataContainer
Evicts the given node. If recursive is set to true then all child nodes are recusively evicted.

Specified by:
evict in interface DataContainer

evict

public boolean evict(Fqn fqn)
Description copied from interface: DataContainer
 Following scenarios define how eviction works.
 1. If the given node is a leaf then it is entirely removed from the data structure. The node is marked as invalid.
 2. If the given node is a leaf then only the data map is cleared.
 3. If the given node is the root node then the cildren nodes are evicted. For each child node 1. or 2. applies
 

Specified by:
evict in interface DataContainer
Returns:
true if the FQN is leaf and was removed; false if is an intermediate FQN and only contained data is droped.

removeData

protected void removeData(Fqn fqn)

createNodes

public Object[] createNodes(Fqn fqn)
Description copied from interface: DataContainer
Traverses the tree to the given Fqn, creating nodes if needed. Returns a list of nodes created, as well as a reference to the last node.

E.g., Object[] results = createNode(myFqn); results[0] // this is a List<NodeSPI> of nodes created in getting to the target node. results[1] // is a NodeSPI reference to the target node, regardless of whether it was created or just found.

Specified by:
createNodes in interface DataContainer
Parameters:
fqn - fqn to find
Returns:
see above.

setBuddyFqnTransformer

public void setBuddyFqnTransformer(BuddyFqnTransformer buddyFqnTransformer)


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