org.infinispan.util.concurrent.locks
Interface LockManager

All Known Implementing Classes:
DeadlockDetectingLockManager, LockManagerImpl

public interface LockManager

An interface to deal with all aspects of acquiring and releasing locks for cache entries.

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

Method Summary
 Object getOwner(Object key)
          Retrieves the write lock owner, if any, for the specified cache entry.
 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 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
 

Method Detail

lockAndRecord

boolean lockAndRecord(Object key,
                      InvocationContext ctx)
                      throws InterruptedException
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().

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

unlock

void unlock(Object key)
Releases the lock passed in, held by the specified owner

Parameters:
owner - lock owner

unlock

void unlock(InvocationContext ctx)
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.

Parameters:
ctx - invocation context to inspect

ownsLock

boolean ownsLock(Object key,
                 Object owner)
Tests whether a given owner owns a lock of lockType on a particular cache entry.

Parameters:
owner - owner
Returns:
true if the owner does own the specified lock type on the specified cache entry, false otherwise.

isLocked

boolean isLocked(Object key)
Returns true if the cache entry is locked (either for reading or writing) by anyone, and false otherwise.

Returns:
true of locked; false if not.

getOwner

Object getOwner(Object key)
Retrieves the write lock owner, if any, for the specified cache entry.

Returns:
the owner of the lock, or null if not locked.

printLockInfo

String printLockInfo()
Prints lock information for all locks.

Returns:
lock information

possiblyLocked

boolean possiblyLocked(CacheEntry entry)
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.

Parameters:
entry - entry to inspect
Returns:
true if the entry *might* be locked, false if the entry definitely is *not* locked.

releaseLocks

void releaseLocks(InvocationContext ctx)
Cleanups the locks within the given context.


Google Analytics

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