org.infinispan.util.concurrent.locks.containers
Interface LockContainer<L extends Lock>

All Known Implementing Classes:
AbstractLockContainer, AbstractPerEntryLockContainer, AbstractStripedLockContainer, OwnableReentrantPerEntryLockContainer, OwnableReentrantStripedLockContainer, ReentrantPerEntryLockContainer, ReentrantStripedLockContainer

public interface LockContainer<L extends Lock>

A container for locks

Since:
4.0
Author:
Manik Surtani, Mircea.Markus@jboss.com

Method Summary
 L acquireLock(Object lockOwner, Object key, long timeout, TimeUnit unit)
          Attempts to acquire a lock for the given object within certain time boundaries defined by the timeout and time unit parameters.
 L getLock(Object key)
           
 int getLockId(Object key)
          Returns the 'id' of the lock that will be used to guard access to a given key in the cache.
 int getNumLocksHeld()
           
 boolean isLocked(Object key)
           
 boolean ownsLock(Object key, Object owner)
          Tests if a give owner owns a lock on a specified object.
 void releaseLock(Object lockOwner, Object key)
          Release lock on the given key.
 int size()
           
 

Method Detail

ownsLock

boolean ownsLock(Object key,
                 Object owner)
Tests if a give owner owns a lock on a specified object.

Parameters:
key - object to check
owner - owner to test
Returns:
true if owner owns lock, false otherwise

isLocked

boolean isLocked(Object key)
Parameters:
key - object
Returns:
true if an object is locked, false otherwise

getLock

L getLock(Object key)
Parameters:
key - object
Returns:
the lock for a specific object

getNumLocksHeld

int getNumLocksHeld()
Returns:
number of locks held

size

int size()
Returns:
the size of the shared lock pool

acquireLock

L acquireLock(Object lockOwner,
              Object key,
              long timeout,
              TimeUnit unit)
                           throws InterruptedException
Attempts to acquire a lock for the given object within certain time boundaries defined by the timeout and time unit parameters.

Parameters:
key - Object to acquire lock on
timeout - Time after which the lock acquisition will fail
unit - Time unit of the given timeout
Returns:
If lock was acquired it returns the corresponding Lock object. If lock was not acquired, it returns null
Throws:
InterruptedException - If the lock acquisition was interrupted

releaseLock

void releaseLock(Object lockOwner,
                 Object key)
Release lock on the given key.

Parameters:
key - Object on which lock is to be removed

getLockId

int getLockId(Object key)
Returns the 'id' of the lock that will be used to guard access to a given key in the cache. Particularly useful if Lock Striping is used and locks may guard more than one key. This mechanism can be used to check whether keys may end up sharing the same lock.

If lock-striping is not used, the identity hash code of the lock created for this specific key is returned. While this may not be of much value, it is done to maintain API compatibility of this method regardless of underlying locking scheme.

Parameters:
key - key to test for
Returns:
the ID of the lock.

-->

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