org.jboss.cache.lock
Class NodeBasedLockManager

java.lang.Object
  extended by org.jboss.cache.lock.NodeBasedLockManager
All Implemented Interfaces:
LockManager
Direct Known Subclasses:
PessimisticNodeBasedLockManager

public class NodeBasedLockManager
extends Object
implements LockManager

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

Field Summary
protected  Configuration configuration
           
protected  DataContainerImpl dataContainer
           
protected  long lockAcquisitionTimeout
           
protected  NodeSPI rootNode
           
 
Constructor Summary
NodeBasedLockManager()
           
 
Method Summary
 Object getLockOwner(InvocationContext ctx)
          Determines the owner to be used when obtaining locks, given an invocation context.
 Collection<Object> getReadOwners(Fqn f)
          Retrieves the read lock owners, if any, for the current Fqn.
 Collection<Object> getReadOwners(NodeSPI node)
          Retrieves the read lock owners, if any, for the current Fqn.
 Object getWriteOwner(Fqn f)
          Retrieves the write lock owner, if any, for the current Fqn.
 Object getWriteOwner(NodeSPI node)
          Retrieves the write lock owner, if any, for the current Fqn.
 void inject(Configuration configuration, DataContainerImpl dataContainer)
           
 boolean isLocked(NodeSPI n)
          Returns true if the node is locked (either for reading or writing) by anyone, and false otherwise.
 boolean isLocked(NodeSPI n, LockType type)
          Returns true if the node is locked (either for reading or writing) by anyone, and false otherwise.
 boolean lock(Fqn fqn, LockType lockType, Object owner)
          Acquires a lock of type lockType, for a given owner, on a specific Node in the cache, denoted by fqn.
 boolean lock(Fqn fqn, LockType lockType, Object owner, long timeout)
          Acquires a lock of type lockType, for a given owner, on a specific Node in the cache, denoted by fqn.
 boolean lock(NodeSPI node, LockType lockType, Object owner)
          As LockManager.lock(org.jboss.cache.Fqn, LockType, Object) except that a NodeSPI is passed in instead of an Fqn.
 boolean lock(NodeSPI node, LockType lockType, Object owner, long timeout)
          As LockManager.lock(org.jboss.cache.Fqn, LockType, Object, long) except that a NodeSPI is passed in instead of an Fqn.
 boolean lockAll(NodeSPI node, LockType lockType, Object owner)
          Locks the node and all child nodes, acquiring lock of type specified for the owner specified.
 boolean lockAll(NodeSPI node, LockType lockType, Object owner, long timeout)
          Locks the node and all child nodes, acquiring lock of type specified for the owner specified.
 boolean lockAll(NodeSPI node, LockType lockType, Object owner, long timeout, boolean excludeInternalFqns)
          Locks the node and all child nodes, acquiring lock of type specified for the owner specified.
 boolean lockAllAndRecord(Fqn fqn, LockType lockType, InvocationContext ctx)
          Locks the node and all child nodes, acquiring lock of type specified for the owner specified.
 boolean lockAllAndRecord(NodeSPI node, LockType lockType, InvocationContext ctx)
          Locks the node and all child nodes, acquiring lock of type specified for the owner specified.
 boolean lockAndRecord(Fqn fqn, LockType lockType, InvocationContext ctx)
          Acquires a lock of type lockType, on a specific Node in the cache, denoted by fqn.
 boolean lockAndRecord(NodeSPI node, LockType lockType, InvocationContext ctx)
          Acquires a lock of type lockType, on a specific Node in the cache, denoted by fqn.
 boolean ownsLock(Fqn fqn, LockType lockType, Object owner)
          Tests whether a given owner owns a lock of lockType on a particular Fqn.
 boolean ownsLock(Fqn fqn, Object owner)
          Tests whether a given owner owns any sort of lock on a particular Fqn.
 boolean ownsLock(NodeSPI node, Object owner)
          Tests whether a given owner owns any sort of lock on a particular Fqn.
 String printLockInfo(NodeSPI node)
          Prints lock information about a node (and it's children) to a String.
 void setRootNode()
           
 void unlock(Fqn fqn, Object owner)
          Releases the lock passed in, held by the specified owner
 void unlock(InvocationContext ctx)
          Releases locks present in an invocation context and transaction entry, if one is available.
 void unlock(NodeSPI node, Object owner)
          Releases the lock passed in, held by the specified owner
 void unlockAll(NodeSPI node)
          Releases locks on a given node and all children for all owners.
 void unlockAll(NodeSPI node, Object owner)
          Releases locks on a given node and all children for a given owner.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configuration

protected Configuration configuration

lockAcquisitionTimeout

protected long lockAcquisitionTimeout

dataContainer

protected DataContainerImpl dataContainer

rootNode

protected NodeSPI rootNode
Constructor Detail

NodeBasedLockManager

public NodeBasedLockManager()
Method Detail

inject

public void inject(Configuration configuration,
                   DataContainerImpl dataContainer)

setRootNode

public void setRootNode()

getLockOwner

public Object getLockOwner(InvocationContext ctx)
Description copied from interface: LockManager
Determines the owner to be used when obtaining locks, given an invocation context. This is typically a GlobalTransaction if one is present in the context, or Thread.currentThread() if one is not present.

Specified by:
getLockOwner in interface LockManager
Parameters:
ctx - invocation context
Returns:
owner to be used for acquiring locks.

lock

public boolean lock(Fqn fqn,
                    LockType lockType,
                    Object owner)
Description copied from interface: LockManager
Acquires a lock of type lockType, for a given owner, on a specific Node in the cache, denoted by fqn. This method will try for Configuration.getLockAcquisitionTimeout() milliseconds and give up if it is unable to acquire the required lock.

Specified by:
lock in interface LockManager
Parameters:
fqn - Fqn to lock
lockType - type of lock to acquire
owner - owner to acquire the lock for
Returns:
true if the lock was acquired, false otherwise.

lock

public boolean lock(Fqn fqn,
                    LockType lockType,
                    Object owner,
                    long timeout)
Description copied from interface: LockManager
Acquires a lock of type lockType, for a given owner, on a specific Node in the cache, denoted by fqn. This method will try for timeout milliseconds and give up if it is unable to acquire the required lock.

Specified by:
lock in interface LockManager
Parameters:
fqn - Fqn to lock
lockType - type of lock to acquire
owner - owner to acquire the lock for
timeout - maximum length of time to wait for (in millis)
Returns:
true if the lock was acquired, false otherwise.

lock

public boolean lock(NodeSPI node,
                    LockType lockType,
                    Object owner)
Description copied from interface: LockManager
As LockManager.lock(org.jboss.cache.Fqn, LockType, Object) except that a NodeSPI is passed in instead of an Fqn.

Specified by:
lock in interface LockManager
Parameters:
node - node to lock
lockType - type of lock to acquire
owner - owner to acquire the lock for
Returns:
true if the lock was acquired, false otherwise.

lock

public boolean lock(NodeSPI node,
                    LockType lockType,
                    Object owner,
                    long timeout)
Description copied from interface: LockManager
As LockManager.lock(org.jboss.cache.Fqn, LockType, Object, long) except that a NodeSPI is passed in instead of an Fqn.

Specified by:
lock in interface LockManager
Parameters:
node - node to lock
lockType - type of lock to acquire
owner - owner to acquire the lock for
timeout - maximum length of time to wait for (in millis)
Returns:
true if the lock was acquired, false otherwise.

lockAndRecord

public boolean lockAndRecord(Fqn fqn,
                             LockType lockType,
                             InvocationContext ctx)
Description copied from interface: LockManager
Acquires a lock of type lockType, on a specific Node in the cache, denoted by fqn. This method will try for a period of time and give up if it is unable to acquire the required lock. The period of time is specified in Option.getLockAcquisitionTimeout() and, if this is unset, the default timeout set in Configuration.getLockAcquisitionTimeout() is used.

In addition, any locks acquired are added to the context using InvocationContext.addInvocationLockAcquired(NodeLock) if you are not running in a transaction, or using TransactionEntry.addLock(NodeLock) if you are.

The owner for the lock is determined by passing the invocation context to LockManager.getLockOwner(org.jboss.cache.InvocationContext).

Specified by:
lockAndRecord in interface LockManager
Parameters:
fqn - Fqn to lock
lockType - type of lock to acquire
ctx - invocation context associated with this invocation
Returns:
true if the lock was acquired, false otherwise.

lockAndRecord

public boolean lockAndRecord(NodeSPI node,
                             LockType lockType,
                             InvocationContext ctx)
Description copied from interface: LockManager
Acquires a lock of type lockType, on a specific Node in the cache, denoted by fqn. This method will try for a period of time and give up if it is unable to acquire the required lock. The period of time is specified in Option.getLockAcquisitionTimeout() and, if this is unset, the default timeout set in Configuration.getLockAcquisitionTimeout() is used.

In addition, any locks acquired are added to the context using InvocationContext.addInvocationLockAcquired(NodeLock) if you are not running in a transaction, or using TransactionEntry.addLock(NodeLock) if you are.

The owner for the lock is determined by passing the invocation context to LockManager.getLockOwner(org.jboss.cache.InvocationContext).

Specified by:
lockAndRecord in interface LockManager
Parameters:
node - Fqn to lock
lockType - type of lock to acquire
ctx - invocation context associated with this invocation
Returns:
true if the lock was acquired, false otherwise.

unlock

public void unlock(InvocationContext ctx)
Description copied from interface: LockManager
Releases locks present in an invocation context and transaction entry, if one is available.

Locks are released in reverse order of which they are acquired and registered.

Lock owner is determined by passing the invocation context to LockManager.getLockOwner(org.jboss.cache.InvocationContext)

Specified by:
unlock in interface LockManager
Parameters:
ctx - invocation context to inspect

unlock

public void unlock(Fqn fqn,
                   Object owner)
Description copied from interface: LockManager
Releases the lock passed in, held by the specified owner

Specified by:
unlock in interface LockManager
Parameters:
fqn - Fqn of the node to unlock
owner - lock owner

unlock

public void unlock(NodeSPI node,
                   Object owner)
Description copied from interface: LockManager
Releases the lock passed in, held by the specified owner

Specified by:
unlock in interface LockManager
Parameters:
node - Node to unlock
owner - lock owner

lockAll

public boolean lockAll(NodeSPI node,
                       LockType lockType,
                       Object owner)
Description copied from interface: LockManager
Locks the node and all child nodes, acquiring lock of type specified for the owner specified. If only some locks are acquired, all locks are released and the method returns false.

This method will try for Configuration.getLockAcquisitionTimeout() milliseconds and give up if it is unable to acquire the required lock.

Specified by:
lockAll in interface LockManager
Parameters:
node - Node to lock
lockType - type of lock to acquire
owner - owner to acquire the lock for
Returns:
true if the lock was acquired, false otherwise.

lockAll

public boolean lockAll(NodeSPI node,
                       LockType lockType,
                       Object owner,
                       long timeout)
Description copied from interface: LockManager
Locks the node and all child nodes, acquiring lock of type specified for the owner specified. If only some locks are acquired, all locks are released and the method returns false. Internal Fqns are included as well.

Specified by:
lockAll in interface LockManager
Parameters:
node - Node to lock
lockType - type of lock to acquire
owner - owner to acquire the lock for
timeout - maximum length of time to wait for (in millis)
Returns:
true if all locks were acquired, false otherwise.

lockAll

public boolean lockAll(NodeSPI node,
                       LockType lockType,
                       Object owner,
                       long timeout,
                       boolean excludeInternalFqns)
Description copied from interface: LockManager
Locks the node and all child nodes, acquiring lock of type specified for the owner specified. If only some locks are acquired, all locks are released and the method returns false.

Specified by:
lockAll in interface LockManager
Parameters:
node - Node to lock
lockType - type of lock to acquire
owner - owner to acquire the lock for
timeout - maximum length of time to wait for (in millis)
excludeInternalFqns - if true, any Fqns that are internal are excluded.
Returns:
true if all locks were acquired, false otherwise.

lockAllAndRecord

public boolean lockAllAndRecord(Fqn fqn,
                                LockType lockType,
                                InvocationContext ctx)
Description copied from interface: LockManager
Locks the node and all child nodes, acquiring lock of type specified for the owner specified. If only some locks are acquired, all locks are released and the method returns false.

In addition, any locks acquired are added to the context using InvocationContext.addInvocationLockAcquired(NodeLock) if you are not running in a transaction, or using TransactionEntry.addLock(NodeLock) if you are.

The owner for the lock is determined by passing the invocation context to LockManager.getLockOwner(org.jboss.cache.InvocationContext).

Specified by:
lockAllAndRecord in interface LockManager
Parameters:
fqn - Node to lock
lockType - type of lock to acquire
ctx - invocation context associated with this invocation
Returns:
true if all locks were acquired, false otherwise.

lockAllAndRecord

public boolean lockAllAndRecord(NodeSPI node,
                                LockType lockType,
                                InvocationContext ctx)
Description copied from interface: LockManager
Locks the node and all child nodes, acquiring lock of type specified for the owner specified. If only some locks are acquired, all locks are released and the method returns false.

In addition, any locks acquired are added to the context using InvocationContext.addInvocationLockAcquired(NodeLock) if you are not running in a transaction, or using TransactionEntry.addLock(NodeLock) if you are.

The owner for the lock is determined by passing the invocation context to LockManager.getLockOwner(org.jboss.cache.InvocationContext).

Specified by:
lockAllAndRecord in interface LockManager
Parameters:
node - Node to lock
lockType - type of lock to acquire
ctx - invocation context associated with this invocation
Returns:
true if all locks were acquired, false otherwise.

unlockAll

public void unlockAll(NodeSPI node,
                      Object owner)
Description copied from interface: LockManager
Releases locks on a given node and all children for a given owner.

Specified by:
unlockAll in interface LockManager
Parameters:
node - node to unlock
owner - lock owner

unlockAll

public void unlockAll(NodeSPI node)
Description copied from interface: LockManager
Releases locks on a given node and all children for all owners. Use with care.

Specified by:
unlockAll in interface LockManager
Parameters:
node - node to unlock

ownsLock

public boolean ownsLock(Fqn fqn,
                        LockType lockType,
                        Object owner)
Description copied from interface: LockManager
Tests whether a given owner owns a lock of lockType on a particular Fqn.

Specified by:
ownsLock in interface LockManager
Parameters:
fqn - fqn to test
lockType - type of lock to test for
owner - owner
Returns:
true if the owner does own the specified lock type on the specified node, false otherwise.

ownsLock

public boolean ownsLock(Fqn fqn,
                        Object owner)
Description copied from interface: LockManager
Tests whether a given owner owns any sort of lock on a particular Fqn.

Specified by:
ownsLock in interface LockManager
Parameters:
fqn - fqn to test
owner - owner
Returns:
true if the owner does own the specified lock type on the specified node, false otherwise.

ownsLock

public boolean ownsLock(NodeSPI node,
                        Object owner)
Description copied from interface: LockManager
Tests whether a given owner owns any sort of lock on a particular Fqn.

Specified by:
ownsLock in interface LockManager
Parameters:
node - to test
owner - owner
Returns:
true if the owner does own the specified lock type on the specified node, false otherwise.

isLocked

public boolean isLocked(NodeSPI n)
Description copied from interface: LockManager
Returns true if the node is locked (either for reading or writing) by anyone, and false otherwise.

Specified by:
isLocked in interface LockManager
Parameters:
n - node to inspect
Returns:
true of locked; false if not.

isLocked

public boolean isLocked(NodeSPI n,
                        LockType type)
Description copied from interface: LockManager
Returns true if the node is locked (either for reading or writing) by anyone, and false otherwise.

Specified by:
isLocked in interface LockManager
Parameters:
n - node to inspect
type - lockType to test for
Returns:
true of locked; false if not.

getWriteOwner

public Object getWriteOwner(Fqn f)
Description copied from interface: LockManager
Retrieves the write lock owner, if any, for the current Fqn.

Specified by:
getWriteOwner in interface LockManager
Parameters:
f - Fqn to inspect
Returns:
the owner of the lock, or null if not locked.

getReadOwners

public Collection<Object> getReadOwners(Fqn f)
Description copied from interface: LockManager
Retrieves the read lock owners, if any, for the current Fqn.

Specified by:
getReadOwners in interface LockManager
Parameters:
f - Fqn to inspect
Returns:
a collection of read lock owners, or an empty collection if not locked.

getWriteOwner

public Object getWriteOwner(NodeSPI node)
Description copied from interface: LockManager
Retrieves the write lock owner, if any, for the current Fqn.

Specified by:
getWriteOwner in interface LockManager
Parameters:
node - the node to inspect
Returns:
the owner of the lock, or null if not locked.

getReadOwners

public Collection<Object> getReadOwners(NodeSPI node)
Description copied from interface: LockManager
Retrieves the read lock owners, if any, for the current Fqn.

Specified by:
getReadOwners in interface LockManager
Parameters:
node - the node to inspect
Returns:
a collection of read lock owners, or an empty collection if not locked.

printLockInfo

public String printLockInfo(NodeSPI node)
Description copied from interface: LockManager
Prints lock information about a node (and it's children) to a String.

Specified by:
printLockInfo in interface LockManager
Parameters:
node - node to inspect


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