org.infinispan.util.concurrent.locks
Class LockManagerImpl

java.lang.Object
  extended by org.infinispan.util.concurrent.locks.LockManagerImpl
All Implemented Interfaces:
LockManager
Direct Known Subclasses:
DeadlockDetectingLockManager

public class LockManagerImpl
extends Object
implements LockManager

Handles locks for the MVCC based LockingInterceptor

Since:
4.0
Author:
Manik Surtani (manik@jboss.org)

Field Summary
protected  Configuration configuration
           
protected  LockContainer lockContainer
           
protected static boolean trace
           
 
Constructor Summary
LockManagerImpl()
           
 
Method Summary
 int getConcurrencyLevel()
           
protected  long getLockAcquisitionTimeout(InvocationContext ctx)
           
 int getNumberOfLocksAvailable()
           
 int getNumberOfLocksHeld()
          Retrieves the number of locks currently held.
 Object getOwner(Object key)
          Retrieves the write lock owner, if any, for the specified cache entry.
 void injectDependencies(Configuration configuration, TransactionManager transactionManager, InvocationContextContainer invocationContextContainer)
           
 boolean isLocked(Object key)
          Returns true if the cache entry is locked (either for reading or writing) by anyone, and false otherwise.
 boolean lockAndRecord(Object key, InvocationContext ctx)
          Acquires a lock of type lockType, on a specific entry in the cache.
 boolean ownsLock(Object key, Object owner)
          Tests whether a given owner owns a lock of lockType on a particular cache entry.
 boolean possiblyLocked(CacheEntry entry)
          Inspects the entry for signs that it is possibly locked, and hence would need to be unlocked.
 String printLockInfo()
          Prints lock information for all locks.
 void releaseLocks(InvocationContext ctx)
          Cleanups the locks within the given context.
 void startLockManager()
           
 void unlock(InvocationContext ctx)
          Releases locks present in an invocation context and transaction entry, if one is available.
 void unlock(Object key)
          Releases the lock passed in, held by the specified 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

lockContainer

protected LockContainer lockContainer

trace

protected static final boolean trace
Constructor Detail

LockManagerImpl

public LockManagerImpl()
Method Detail

injectDependencies

public void injectDependencies(Configuration configuration,
                               TransactionManager transactionManager,
                               InvocationContextContainer invocationContextContainer)

startLockManager

public void startLockManager()

lockAndRecord

public boolean lockAndRecord(Object key,
                             InvocationContext ctx)
                      throws InterruptedException
Description copied from interface: LockManager
Acquires a lock of type lockType, on a specific entry in the cache. 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 Configuration.getLockAcquisitionTimeout().

Specified by:
lockAndRecord in interface LockManager
Parameters:
key - key to lock
ctx - invocation context associated with this invocation
Returns:
true if the lock was acquired, false otherwise.
Throws:
InterruptedException - if interrupted

getLockAcquisitionTimeout

protected long getLockAcquisitionTimeout(InvocationContext ctx)

unlock

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

Specified by:
unlock in interface LockManager

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.

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

ownsLock

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

Specified by:
ownsLock in interface LockManager
owner - owner
Returns:
true if the owner does own the specified lock type on the specified cache entry, false otherwise.

isLocked

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

Specified by:
isLocked in interface LockManager
Returns:
true of locked; false if not.

getOwner

public Object getOwner(Object key)
Description copied from interface: LockManager
Retrieves the write lock owner, if any, for the specified cache entry.

Specified by:
getOwner in interface LockManager
Returns:
the owner of the lock, or null if not locked.

printLockInfo

public String printLockInfo()
Description copied from interface: LockManager
Prints lock information for all locks.

Specified by:
printLockInfo in interface LockManager
Returns:
lock information

possiblyLocked

public final boolean possiblyLocked(CacheEntry entry)
Description copied from interface: LockManager
Inspects the entry for signs that it is possibly locked, and hence would need to be unlocked. Note that this is not deterministic, and is pessimistic in that even if an entry is not locked but *might* be locked, this will return true.

As such, this should only be used to determine whether *unlocking* is necessary, not whether locking is necessary. Unlocking an entry that has not been locked has no effect, so this is just an optimisation.

Specified by:
possiblyLocked in interface LockManager
Parameters:
entry - entry to inspect
Returns:
true if the entry *might* be locked, false if the entry definitely is *not* locked.

releaseLocks

public void releaseLocks(InvocationContext ctx)
Description copied from interface: LockManager
Cleanups the locks within the given context.

Specified by:
releaseLocks in interface LockManager

getConcurrencyLevel

public int getConcurrencyLevel()

getNumberOfLocksHeld

public int getNumberOfLocksHeld()
Description copied from interface: LockManager
Retrieves the number of locks currently held.

Specified by:
getNumberOfLocksHeld in interface LockManager
Returns:
an integer

getNumberOfLocksAvailable

public int getNumberOfLocksAvailable()

Google Analytics

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