org.terracotta.locking
Interface ClusteredLock

All Superinterfaces:
Lock
All Known Implementing Classes:
TerracottaLock

public interface ClusteredLock
extends Lock

Provides primitive lock operations for the granularity that was used to create an instance of this lock. At the creation of a ClusteredLock instance a default lock type is also stored, which is corresponds to the default lock type of the underlying data structure.


Method Summary
 boolean isHeldByCurrentThread()
          Indicates whether the current thread is holding this lock with the default lock type.
 boolean isHeldByCurrentThread(LockType lockType)
          Indicates whether the current thread is holding this lock with the specific lock type.
 void lock(LockType lockType)
          Acquires this lock using a specific lock type.
 void lockInterruptibly(LockType lockType)
          Acquires this lock using a specific lock type unless the current thread is interrupted.
 boolean tryLock(LockType lockType)
          Acquires this lock using a specific lock type only if the lock is available at the time of invocation.
 boolean tryLock(LockType lockType, long timeout, TimeUnit unit)
          Acquires this lock using a specific lock type only if it is available within the given time and the current thread has not been interrupted.
 void unlock()
           
 void unlock(LockType lockType)
          Releases a lock hold of the specified type.
 
Methods inherited from interface java.util.concurrent.locks.Lock
lock, lockInterruptibly, newCondition, tryLock, tryLock
 

Method Detail

lock

void lock(LockType lockType)
Acquires this lock using a specific lock type.

Parameters:
lockType - the type of lock hold that will be acquired
See Also:
Lock.lock()

tryLock

boolean tryLock(LockType lockType)
Acquires this lock using a specific lock type only if the lock is available at the time of invocation.

Parameters:
lockType - the type of lock hold that may be acquired
Returns:
true if the lock was successfully acquired; or false otherwise
See Also:
Lock.tryLock()

tryLock

boolean tryLock(LockType lockType,
                long timeout,
                TimeUnit unit)
                throws InterruptedException
Acquires this lock using a specific lock type only if it is available within the given time and the current thread has not been interrupted.

Parameters:
lockType - the type of lock hold that may be acquired
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
true if the lock was successfully acquired; or false otherwise
Throws:
InterruptedException - if the current thread is interrupted during lock acquisition
See Also:
Lock.tryLock(long, TimeUnit)

unlock

void unlock()
Specified by:
unlock in interface Lock
Throws:
IllegalMonitorStateException - on attempting to unlock a lock that is not held

unlock

void unlock(LockType lockType)
Releases a lock hold of the specified type.

Parameters:
lockType - the type of lock hold that will be released
See Also:
unlock()

isHeldByCurrentThread

boolean isHeldByCurrentThread()
Indicates whether the current thread is holding this lock with the default lock type.

Returns:
true if the current thread is holding this lock; or false otherwise

isHeldByCurrentThread

boolean isHeldByCurrentThread(LockType lockType)
Indicates whether the current thread is holding this lock with the specific lock type.

Parameters:
lockType - the type of lock hold to be queried
Returns:
true if the current thread is holding this lock; or false otherwise

lockInterruptibly

void lockInterruptibly(LockType lockType)
                       throws InterruptedException
Acquires this lock using a specific lock type unless the current thread is interrupted.

Parameters:
lockType - the type of lock that will be acquired
Throws:
InterruptedException - if the current thread is interrupted while acquiring the lock
See Also:
Lock.lockInterruptibly()


Copyright © 2015 Terracotta, Inc.. All Rights Reserved.