org.neo4j.kernel.impl.transaction
Class LockManager

java.lang.Object
  extended by org.neo4j.kernel.impl.transaction.LockManager
Direct Known Subclasses:
SlaveLockManager

public class LockManager
extends Object

The LockManager can lock resources for reading or writing. By doing this one may achieve different transaction isolation levels. A resource can for now be any object (but null).

When acquiring a lock you have to release it. Failure to do so will result in the resource being blocked to all other transactions. Put all locks in a try - finally block.

Multiple locks on the same resource held by the same transaction requires the transaction to invoke the release lock method multiple times. If a tx has invoked getReadLock on the same resource x times in a row it must invoke releaseReadLock x times to release all the locks.

LockManager just maps locks to resources and they do all the hard work together with a resource allocation graph.


Constructor Summary
LockManager(TransactionManager tm)
           
 
Method Summary
 void dumpAllLocks()
          Utility method for debugging.
 void dumpLocksOnResource(Object resource)
          Utility method for debugging.
 void dumpRagStack()
          Utility method for debugging.
 long getDetectedDeadlockCount()
           
 void getReadLock(Object resource)
          Tries to acquire read lock on resource for the current transaction.
 void getWriteLock(Object resource)
          Tries to acquire write lock on resource for the current transaction.
 void releaseReadLock(Object resource, Transaction tx)
          Releases a read lock held by the current transaction on resource.
 void releaseWriteLock(Object resource, Transaction tx)
          Releases a read lock held by the current transaction on resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LockManager

public LockManager(TransactionManager tm)
Method Detail

getDetectedDeadlockCount

public long getDetectedDeadlockCount()

getReadLock

public void getReadLock(Object resource)
                 throws DeadlockDetectedException,
                        IllegalResourceException
Tries to acquire read lock on resource for the current transaction. If read lock can't be acquired the transaction will wait for the lransaction until it can acquire it. If waiting leads to dead lock a DeadlockDetectedException will be thrown.

Parameters:
resource - The resource
Throws:
DeadlockDetectedException - If a deadlock is detected
IllegalResourceException

getWriteLock

public void getWriteLock(Object resource)
                  throws DeadlockDetectedException,
                         IllegalResourceException
Tries to acquire write lock on resource for the current transaction. If write lock can't be acquired the transaction will wait for the lock until it can acquire it. If waiting leads to dead lock a DeadlockDetectedException will be thrown.

Parameters:
resource - The resource
Throws:
DeadlockDetectedException - If a deadlock is detected
IllegalResourceException

releaseReadLock

public void releaseReadLock(Object resource,
                            Transaction tx)
                     throws LockNotFoundException,
                            IllegalResourceException
Releases a read lock held by the current transaction on resource. If current transaction don't have read lock a LockNotFoundException will be thrown.

Parameters:
resource - The resource
Throws:
IllegalResourceException
LockNotFoundException

releaseWriteLock

public void releaseWriteLock(Object resource,
                             Transaction tx)
                      throws LockNotFoundException,
                             IllegalResourceException
Releases a read lock held by the current transaction on resource. If current transaction don't have read lock a LockNotFoundException will be thrown.

Parameters:
resource - The resource
Throws:
IllegalResourceException
LockNotFoundException

dumpLocksOnResource

public void dumpLocksOnResource(Object resource)
Utility method for debugging. Dumps info to console of txs having locks on resources.

Parameters:
resource -

dumpRagStack

public void dumpRagStack()
Utility method for debugging. Dumps the resource allocation graph to console.


dumpAllLocks

public void dumpAllLocks()
Utility method for debugging. Dumps info about each lock to console.



Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.