org.jboss.cache.mvcc
Class MVCCNodeHelper

java.lang.Object
  extended by org.jboss.cache.mvcc.MVCCNodeHelper

public class MVCCNodeHelper
extends Object

Utility functions to manipulate wrapping InternalNodes as ReadCommittedNode or RepeatableReadNodes. Would also entail locking, if necessary.

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

Constructor Summary
MVCCNodeHelper()
           
 
Method Summary
 void injectDependencies(DataContainer dataContainer, NodeFactory nodeFactory, LockManager lockManager, Configuration configuration)
           
 void start()
           
 NodeSPI wrapNodeForReading(InvocationContext ctx, Fqn fqn, boolean putInContext)
          Similar to wrapNodesForReading(org.jboss.cache.InvocationContext, java.util.Collection) except that this version takes a single Fqn parameter to wrap a single node.
 ReadCommittedNode wrapNodeForWriting(InvocationContext context, Fqn fqn, boolean lockForWriting, boolean createIfAbsent, boolean includeInvalidNodes, boolean forRemoval, boolean force)
          First checks in contexts for the existence of the node.
 NodeSPI wrapNodeForWriting(InvocationContext context, InternalNode node, InternalNode parent)
          The same as wrapNodeForWriting(org.jboss.cache.InvocationContext, org.jboss.cache.Fqn, boolean, boolean, boolean, boolean, boolean) except that it takes in an InternalNode instead of a Fqn.
 void wrapNodesForReading(InvocationContext ctx, Collection<Fqn> fqns)
          Attempts to provide the context with a set of wrapped nodes based on the Collection of fqns passed in.
 List<Fqn> wrapNodesRecursivelyForRemoval(InvocationContext ctx, Fqn fqn)
          Wraps a node and all its subnodes and adds them to the context, acquiring write locks for them all.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MVCCNodeHelper

public MVCCNodeHelper()
Method Detail

injectDependencies

public void injectDependencies(DataContainer dataContainer,
                               NodeFactory nodeFactory,
                               LockManager lockManager,
                               Configuration configuration)

start

public void start()

wrapNodesForReading

public void wrapNodesForReading(InvocationContext ctx,
                                Collection<Fqn> fqns)
                         throws InterruptedException
Attempts to provide the context with a set of wrapped nodes based on the Collection of fqns passed in. If the nodes already exist in the context then the node is not wrapped again.

InternalNodes are wrapped using NodeFactory.createWrappedNode(org.jboss.cache.InternalNode, org.jboss.cache.InternalNode) and as such, null internal nodes are treated according to isolation level used. See NodeFactory.createWrappedNode(org.jboss.cache.InternalNode, org.jboss.cache.InternalNode) for details on this behaviour.

Note that if the context has the Option.isForceWriteLock() option set, then write locks are acquired and the node is copied.

Parameters:
ctx - current invocation context
fqns - collection of Fqns. Should not be null.
Throws:
InterruptedException - if write locks are forced and the lock manager is interrupted.

wrapNodeForReading

public NodeSPI wrapNodeForReading(InvocationContext ctx,
                                  Fqn fqn,
                                  boolean putInContext)
                           throws InterruptedException
Similar to wrapNodesForReading(org.jboss.cache.InvocationContext, java.util.Collection) except that this version takes a single Fqn parameter to wrap a single node.

Parameters:
ctx - current invocation context
fqn - fqn to fetch and wrap
putInContext -
Returns:
read committed node, or null if one is not found.
Throws:
InterruptedException - if write locks are forced and the lock manager is interrupted.

wrapNodeForWriting

public ReadCommittedNode wrapNodeForWriting(InvocationContext context,
                                            Fqn fqn,
                                            boolean lockForWriting,
                                            boolean createIfAbsent,
                                            boolean includeInvalidNodes,
                                            boolean forRemoval,
                                            boolean force)
                                     throws InterruptedException
First checks in contexts for the existence of the node. If it does exist, it will return it, acquiring a lock if necessary. Otherwise, it will peek in the dataContainer, wrap the node, lock if necessary, and add it to the context. If it doesn't even exist in the dataContainer and createIfAbsent is true, it will create a new node and add it to the data structure. It will lock the node, and potentially the parent as well, if necessary. If the parent is locked, it too will be added to the context if it wasn't there already.

Parameters:
context - invocation context
fqn - to retrieve
lockForWriting - if true, a lock will be acquired.
createIfAbsent - if true, will be created if absent.
includeInvalidNodes - if true, invalid nodes are included.
forRemoval - if true, the parent may also be locked if locking parents for removal is necessary.
force - if true, will force the write lock even if the node is null.
Returns:
a wrapped node, or null.
Throws:
InterruptedException - if interrupted

wrapNodeForWriting

public NodeSPI wrapNodeForWriting(InvocationContext context,
                                  InternalNode node,
                                  InternalNode parent)
                           throws InterruptedException
The same as wrapNodeForWriting(org.jboss.cache.InvocationContext, org.jboss.cache.Fqn, boolean, boolean, boolean, boolean, boolean) except that it takes in an InternalNode instead of a Fqn. Saves on a lookup.

Also assumes that the node exists, and hence will not be created.

Parameters:
context - invocation context
node - node to wrap
Returns:
a wrapped node, or null.
Throws:
InterruptedException - if interrupted

wrapNodesRecursivelyForRemoval

public List<Fqn> wrapNodesRecursivelyForRemoval(InvocationContext ctx,
                                                Fqn fqn)
                                         throws InterruptedException
Wraps a node and all its subnodes and adds them to the context, acquiring write locks for them all.

Parameters:
ctx - context
fqn - fqn to wrap
Returns:
a list of Fqns of locks acquired in this call.
Throws:
InterruptedException - if the lock manager is interrupted.


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