org.infinispan.util.concurrent.locks
Class OwnableReentrantLock
java.lang.Object
java.util.concurrent.locks.AbstractOwnableSynchronizer
java.util.concurrent.locks.AbstractQueuedSynchronizer
org.infinispan.util.concurrent.locks.OwnableReentrantLock
- All Implemented Interfaces:
- Serializable, Lock
@ThreadSafe
public class OwnableReentrantLock
- extends AbstractQueuedSynchronizer
- implements Lock
A lock that supports reentrancy based on owner (and not on current thread). For this to work, the lock needs to be
constructed with a reference to the InvocationContextContainer
, so it is able to determine whether the
caller's "owner" reference is the current thread or a GlobalTransaction
instance.
This makes this lock implementation very closely tied to Infinispan internals, but it provides for a very clean,
efficient and moreover familiar interface to work with, since it implements Lock
.
For the sake of performance, this lock only supports nonfair queueing.
- Since:
- 4.0
- Author:
- Manik Surtani (manik@jboss.org)
- See Also:
- Serialized Form
Methods inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer |
acquire, acquireInterruptibly, acquireShared, acquireSharedInterruptibly, compareAndSetState, getExclusiveQueuedThreads, getFirstQueuedThread, getQueuedThreads, getQueueLength, getSharedQueuedThreads, getState, getWaitingThreads, getWaitQueueLength, hasContended, hasQueuedThreads, hasWaiters, isQueued, owns, release, releaseShared, setState, tryAcquireNanos, tryAcquireShared, tryAcquireSharedNanos, tryReleaseShared |
OwnableReentrantLock
public OwnableReentrantLock(InvocationContextContainer icc)
- Creates a new lock instance.
- Parameters:
icc
- InvocationContextContainer instance to consult for the invocation context of the
call.
currentRequestor
protected final Object currentRequestor()
- Returns:
- a GlobalTransaction instance if the current call is participating in a transaction, or the current thread
otherwise.
lock
public void lock()
- Specified by:
lock
in interface Lock
lockInterruptibly
public void lockInterruptibly()
throws InterruptedException
- Specified by:
lockInterruptibly
in interface Lock
- Throws:
InterruptedException
tryLock
public boolean tryLock()
- Specified by:
tryLock
in interface Lock
tryLock
public boolean tryLock(long time,
TimeUnit unit)
throws InterruptedException
- Specified by:
tryLock
in interface Lock
- Throws:
InterruptedException
unlock
public void unlock()
- Specified by:
unlock
in interface Lock
newCondition
public AbstractQueuedSynchronizer.ConditionObject newCondition()
- Specified by:
newCondition
in interface Lock
tryAcquire
protected final boolean tryAcquire(int acquires)
- Overrides:
tryAcquire
in class AbstractQueuedSynchronizer
tryRelease
protected final boolean tryRelease(int releases)
- Overrides:
tryRelease
in class AbstractQueuedSynchronizer
isHeldExclusively
protected final boolean isHeldExclusively()
- Overrides:
isHeldExclusively
in class AbstractQueuedSynchronizer
getOwner
public final Object getOwner()
- Returns:
- the owner of the lock, or null if it is currently unlocked.
getHoldCount
public final int getHoldCount()
- Returns:
- the hold count of the current lock, or 0 if it is not locked.
isLocked
public final boolean isLocked()
- Returns:
- true if the lock is locked, false otherwise
toString
public String toString()
- Returns a string identifying this lock, as well as its lock state. The state, in brackets, includes either the
String "Unlocked" or the String "Locked by" followed by the String representation of the lock
owner.
- Overrides:
toString
in class AbstractQueuedSynchronizer
- Returns:
- a string identifying this lock, as well as its lock state.
Copyright © 2010 JBoss, a division of Red Hat. All Rights Reserved.