org.terracotta.locking
Class TerracottaLock

java.lang.Object
  extended by org.terracotta.locking.TerracottaLock
All Implemented Interfaces:
Comparable, Lock, ClusteredLock

public class TerracottaLock
extends Object
implements ClusteredLock, Comparable


Constructor Summary
TerracottaLock(Object monitor, LockType type)
          Constructs a lock instance around the given clustered object.
 
Method Summary
 int compareTo(Object o)
           
 int compareTo(TerracottaLock o)
           
 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()
           
 void lock(LockType lockType)
          Acquires this lock using a specific lock type.
 void lockInterruptibly()
           
 void lockInterruptibly(LockType lockType)
          Acquires this lock using a specific lock type unless the current thread is interrupted.
 Condition newCondition()
          Condition objects are not supported by this implementation.
 boolean tryLock()
           
 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.
 boolean tryLock(long timeout, TimeUnit unit)
           
 void unlock()
           
 void unlock(LockType lockType)
          Releases a lock hold of the specified type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TerracottaLock

public TerracottaLock(Object monitor,
                      LockType type)
Constructs a lock instance around the given clustered object.

This implementation fully supports the interrupting of lock acquisition.

Parameters:
monitor - clustered object on which locks will be taken
type - default lock hold type for this lock
Throws:
NullPointerException - if the supplied object is null
IllegalArgumentException - if the supplied object is not clustered
Method Detail

lock

public void lock()
Specified by:
lock in interface Lock

tryLock

public boolean tryLock()
Specified by:
tryLock in interface Lock

tryLock

public boolean tryLock(long timeout,
                       TimeUnit unit)
                throws InterruptedException
Specified by:
tryLock in interface Lock
Throws:
InterruptedException

unlock

public void unlock()
Specified by:
unlock in interface Lock
Specified by:
unlock in interface ClusteredLock

isHeldByCurrentThread

public boolean isHeldByCurrentThread()
Description copied from interface: ClusteredLock
Indicates whether the current thread is holding this lock with the default lock type.

Specified by:
isHeldByCurrentThread in interface ClusteredLock
Returns:
true if the current thread is holding this lock; or false otherwise

lock

public void lock(LockType lockType)
Description copied from interface: ClusteredLock
Acquires this lock using a specific lock type.

Specified by:
lock in interface ClusteredLock
Parameters:
lockType - the type of lock hold that will be acquired
See Also:
Lock.lock()

tryLock

public boolean tryLock(LockType lockType)
Description copied from interface: ClusteredLock
Acquires this lock using a specific lock type only if the lock is available at the time of invocation.

Specified by:
tryLock in interface ClusteredLock
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

public boolean tryLock(LockType lockType,
                       long timeout,
                       TimeUnit unit)
                throws InterruptedException
Description copied from interface: ClusteredLock
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.

Specified by:
tryLock in interface ClusteredLock
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

public void unlock(LockType lockType)
Description copied from interface: ClusteredLock
Releases a lock hold of the specified type.

Specified by:
unlock in interface ClusteredLock
Parameters:
lockType - the type of lock hold that will be released
See Also:
ClusteredLock.unlock()

isHeldByCurrentThread

public boolean isHeldByCurrentThread(LockType lockType)
Description copied from interface: ClusteredLock
Indicates whether the current thread is holding this lock with the specific lock type.

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

compareTo

public int compareTo(TerracottaLock o)

lockInterruptibly

public void lockInterruptibly()
                       throws InterruptedException
Specified by:
lockInterruptibly in interface Lock
Throws:
InterruptedException

lockInterruptibly

public void lockInterruptibly(LockType lockType)
                       throws InterruptedException
Description copied from interface: ClusteredLock
Acquires this lock using a specific lock type unless the current thread is interrupted.

Specified by:
lockInterruptibly in interface ClusteredLock
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()

newCondition

public Condition newCondition()
                       throws UnsupportedOperationException
Condition objects are not supported by this implementation.

Specified by:
newCondition in interface Lock
Returns:
never
Throws:
UnsupportedOperationException - always

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable


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