- 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
Modifier and TypeInterfaceDescriptionstatic class
An instance ofDeadLockException
is thrown byexecuteForcedly(LockProtectedRunnable, boolean)
if the operation would result in a dead-lock condition. -
Method Summary
Modifier and TypeMethodDescriptionvoid
execute
(LockProtectedRunnable task, boolean write) Asynchronously executes atask
such that it possesses a lock on thisLockable
.void
execute
(LockProtectedRunnable task, Lock retained) Asynchronously executes atask
using a lock which has been retained before within another task.void
executeForcedly
(LockProtectedRunnable task, boolean write) Synchronously executes atask
such that it possesses a lock on thisLockable
.void
executeForcedly
(LockProtectedRunnable task, Lock retained) Synchronously executes atask
using a lock which has been retained before within another task.long
Returns the waiting time of the pending task which is waiting longest, or-1
if there is no pending task.int
Returns the current number of tasks which are waiting for locked execution.boolean
isLocked
(boolean write) Determines if the current thread has a lock for thisLockable
.
-
Method Details
-
execute
Asynchronously executes atask
such 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 atask
using 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 atask
such 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:
InterruptedException
Lockable.DeadLockException
-
executeForcedly
Synchronously executes atask
using 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:
true
if 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-1
if there is no pending task.- Returns:
- current maximum waiting time of pending tasks
-