- All Known Subinterfaces:
Graph
- All Known Implementing Classes:
AttributeOverwritingFilter,GraphBase,GraphFilter,GraphManager,HighlightFilter,LockableImpl,PersistenceManager,TopologyGraph
public interface Lockable
An instance of
Lockable is a resource on which
read- or write-locked tasks can be performed.
Several read-locked tasks may be executed concurrently, while
only a single write-locked task may be executed at the same
time. A write-locked task excludes the concurrent
execution of both read- and write-locked tasks, so a write lock
is an exclusive lock.
Locks are re-entrant: A task which is executed using a lock may execute further nested, locked tasks in the same thread.
Tasks which should be executed using a lock are specified by
implementations of LockProtectedRunnable.
The lock/unlock operations are performed implicitly before
and after invocation of the method run in
LockProtectedRunnable. However,
a task may invoke Lock.retain() on its
lock in order to suppress the unlock operation after the task
has completed: In this case, the lock may be kept for a while and
even passed to another thread until it is eventually passed
to one of the execute methods of Lockable.
- Author:
- Ole Kniemeyer
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classAn instance ofDeadLockExceptionis thrown byexecuteForcedly(LockProtectedRunnable, boolean)if the operation would result in a dead-lock condition. -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute(LockProtectedRunnable task, boolean write) Asynchronously executes atasksuch that it possesses a lock on thisLockable.voidexecute(LockProtectedRunnable task, Lock retained) Asynchronously executes ataskusing a lock which has been retained before within another task.voidexecuteForcedly(LockProtectedRunnable task, boolean write) Synchronously executes atasksuch that it possesses a lock on thisLockable.voidexecuteForcedly(LockProtectedRunnable task, Lock retained) Synchronously executes ataskusing a lock which has been retained before within another task.longReturns the waiting time of the pending task which is waiting longest, or-1if there is no pending task.intReturns the current number of tasks which are waiting for locked execution.booleanisLocked(boolean write) Determines if the current thread has a lock for thisLockable.
-
Method Details
-
execute
Asynchronously executes atasksuch that it possesses a lock on thisLockable. Note that the execution is asynchronous, so that the thread in which the task will actually be executed may differ from the current thread.- Parameters:
task- the task to executewrite- shall a write lock be obtained?
-
execute
Asynchronously executes ataskusing a lock which has been retained before within another task. Note that the execution is asynchronous, so that the thread in which the task will actually be executed may differ from the current thread.- Parameters:
task- the task to executeretained- the previously retained lock- See Also:
-
executeForcedly
void executeForcedly(LockProtectedRunnable task, boolean write) throws InterruptedException, Lockable.DeadLockException Synchronously executes atasksuch that it possesses a lock on thisLockable. The execution is performed in the current thread.- Parameters:
task- the task to executewrite- shall a write lock be obtained?- Throws:
InterruptedExceptionLockable.DeadLockException
-
executeForcedly
Synchronously executes ataskusing a lock which has been retained before within another task. The execution is performed in the current thread.- Parameters:
task- the task to executeretained- the previously retained lock- Throws:
InterruptedException- See Also:
-
isLocked
boolean isLocked(boolean write) Determines if the current thread has a lock for thisLockable.- Parameters:
write- check for write locks only (true) or for both read and write locks (false)- Returns:
trueif the current thread has a lock
-
getQueueLength
int getQueueLength()Returns the current number of tasks which are waiting for locked execution.- Returns:
- current number of waiting tasks
-
getMaxWaitingTime
long getMaxWaitingTime()Returns the waiting time of the pending task which is waiting longest, or-1if there is no pending task.- Returns:
- current maximum waiting time of pending tasks
-