java.lang.Object
de.grogra.util.LockableImpl
- All Implemented Interfaces:
Lockable
- Direct Known Subclasses:
PersistenceManager
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.grogra.util.Lockable
Lockable.DeadLockException
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
void
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.protected void
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.protected void
invokeRun
(LockProtectedRunnable task, boolean sync, Lock lock) protected boolean
isAllowedThread
(boolean write) boolean
isLocked
(boolean write) Determines if the current thread has a lock for thisLockable
.void
protected void
de.grogra.util.LockableImpl.LockImpl
lock
(boolean hadLock, boolean forWrite)
-
Constructor Details
-
LockableImpl
public LockableImpl()
-
-
Method Details
-
killLock
-
lock
public de.grogra.util.LockableImpl.LockImpl lock(boolean hadLock, boolean forWrite) -
execute
Description copied from interface:Lockable
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. -
execute
Description copied from interface:Lockable
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. -
executeForcedly
public void executeForcedly(LockProtectedRunnable task, boolean write) throws InterruptedException, Lockable.DeadLockException Description copied from interface:Lockable
Synchronously executes atask
such that it possesses a lock on thisLockable
. The execution is performed in the current thread.- Specified by:
executeForcedly
in interfaceLockable
- Parameters:
task
- the task to executewrite
- shall a write lock be obtained?- Throws:
InterruptedException
Lockable.DeadLockException
-
executeForcedly
Description copied from interface:Lockable
Synchronously executes atask
using a lock which has been retained before within another task. The execution is performed in the current thread.- Specified by:
executeForcedly
in interfaceLockable
- Parameters:
task
- the task to executeretained
- the previously retained lock- Throws:
InterruptedException
- See Also:
-
isLocked
public boolean isLocked(boolean write) Description copied from interface:Lockable
Determines if the current thread has a lock for thisLockable
. -
getQueueLength
public int getQueueLength()Description copied from interface:Lockable
Returns the current number of tasks which are waiting for locked execution.- Specified by:
getQueueLength
in interfaceLockable
- Returns:
- current number of waiting tasks
-
getMaxWaitingTime
public long getMaxWaitingTime()Description copied from interface:Lockable
Returns the waiting time of the pending task which is waiting longest, or-1
if there is no pending task.- Specified by:
getMaxWaitingTime
in interfaceLockable
- Returns:
- current maximum waiting time of pending tasks
-
isAllowedThread
protected boolean isAllowedThread(boolean write) -
executeInAllowedThread
-
invokeRun
-
enterWriteLock
protected void enterWriteLock() -
leaveWriteLock
protected void leaveWriteLock()
-