de.grogra.util
Interface Lock


public interface Lock

A Lock on a Lockable resource is either a read lock or an exclusive write lock. It is acquired indirectly by one of the execute methods in Lockable.

Author:
Ole Kniemeyer

Method Summary
 void executeWithoutWriteLock(java.lang.Runnable callback)
          Executes callback while temporarily reducing this write lock to a read lock.
 Lockable getLockable()
          Returns the resource on which this lock is held.
 boolean isWriteLock()
          Returns the type of lock.
 void retain()
          A lock may be retained by invocation of this method within the LockProtectedRunnable.run(boolean, Lock) method of a task.
 

Method Detail

executeWithoutWriteLock

void executeWithoutWriteLock(java.lang.Runnable callback)
                             throws java.lang.InterruptedException
Executes callback while temporarily reducing this write lock to a read lock. This gives threads waiting for a read lock the chance to execute.

Throws:
java.lang.IllegalStateException - if this lock is not a write lock
java.lang.InterruptedException - if this thread is interrupted while reacquiring the write lock. In this case the lock stays a read lock

getLockable

Lockable getLockable()
Returns the resource on which this lock is held.

Returns:
resource locked by this lock

isWriteLock

boolean isWriteLock()
Returns the type of lock.

Returns:
is this lock a read or write lock?

retain

void retain()
A lock may be retained by invocation of this method within the LockProtectedRunnable.run(boolean, Lock) method of a task. In this case, the lock is not released after the task has been finished: The lock remains active and has to be passed to one of the execute methods in Lockable which take a lock as parameter, only then the lock will be released.