org.terracotta.collections
Interface FinegrainedLock

All Known Implementing Classes:
FinegrainedLockDso, FinegrainedLockNoDso

public interface FinegrainedLock

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

IMPORTANT: an instance of FinegrainedLock) is not supposed to be cached or stored in any field or data structure since the state of the underlying data structure can have changed in the meantime. Each time a locking operation is performed a new instance of {@code FinegrainedLock} needs to be obtained.


Method Summary
 boolean isHeldByCurrentThread()
          Indicates whether the current thread is holding a lock that corresponds to this granularity and default lock type.
 boolean isHeldByCurrentThread(LockType lockType)
          Indicates whether the current thread is holding a lock that corresponds to this granularity and specified lock type.
 void lock()
          Lock the underlying data structure for this lock's granularity using the default lock type.
 void lock(LockType lockType)
          Lock the underlying data structure for this lock's granularity with a specified lock type.
 boolean tryLock()
          Lock the underlying data structure for this lock's granularity using the default lock type only if the lock is not held by another thread at the time of invocation.
 boolean tryLock(LockType lockType)
          Lock the underlying data structure for this lock's granularity with a specified lock type only if the lock is not held by another thread at the time of invocation.
 boolean tryLock(LockType lockType, long timeout, TimeUnit unit)
          Lock the underlying data structure for this lock's granularity with a specified lock type only if the lock is not held by another thread within a given time.
 boolean tryLock(long timeout, TimeUnit unit)
          Lock the underlying data structure for this lock's granularity using the default lock type only if the lock is not held by another thread within a given time.
 void unlock()
          Unlocks the underlying data structure for this lock's granularity using the default lock type.
 void unlock(LockType lockType)
          Unlocks the underlying data structure for this lock's granularity using the specified lock type.
 

Method Detail

lock

void lock()
Lock the underlying data structure for this lock's granularity using the default lock type.


lock

void lock(LockType lockType)
Lock the underlying data structure for this lock's granularity with a specified lock type.

Parameters:
lockType - the type of lock that needs to be locked

tryLock

boolean tryLock()
Lock the underlying data structure for this lock's granularity using the default lock type only if the lock is not held by another thread at the time of invocation.

Returns:
true if the lock was successfully acquired; or {@code false) otherwise

tryLock

boolean tryLock(LockType lockType)
Lock the underlying data structure for this lock's granularity with a specified lock type only if the lock is not held by another thread at the time of invocation.

Parameters:
lockType - the type of lock that needs to be locked
Returns:
true if the lock was successfully acquired; or {@code false) otherwise

tryLock

boolean tryLock(long timeout,
                TimeUnit unit)
                throws InterruptedException
Lock the underlying data structure for this lock's granularity using the default lock type only if the lock is not held by another thread within a given time.

Parameters:
timeout - the time to wait
unit - the time unit of the timeout argument
Returns:
true if the lock was successfully acquired; or {@code false) otherwise
Throws:
InterruptedException

tryLock

boolean tryLock(LockType lockType,
                long timeout,
                TimeUnit unit)
                throws InterruptedException
Lock the underlying data structure for this lock's granularity with a specified lock type only if the lock is not held by another thread within a given time.

Parameters:
lockType - the type of lock that needs to be locked
timeout - the time to wait
unit - the time unit of the timeout argument
Returns:
true if the lock was successfully acquired; or {@code false) otherwise
Throws:
InterruptedException

unlock

void unlock()
Unlocks the underlying data structure for this lock's granularity using the default lock type.


unlock

void unlock(LockType lockType)
Unlocks the underlying data structure for this lock's granularity using the specified lock type.

Parameters:
lockType - the type of lock that needs to be unlocked

isHeldByCurrentThread

boolean isHeldByCurrentThread()
Indicates whether the current thread is holding a lock that corresponds to this granularity and default lock type.

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

isHeldByCurrentThread

boolean isHeldByCurrentThread(LockType lockType)
Indicates whether the current thread is holding a lock that corresponds to this granularity and specified lock type.

Parameters:
lockType - the type of lock that needs to be checked
Returns:
true if the current thread is holding the lock; or false otherwise


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