Module utilities

Class LockableImpl

java.lang.Object
de.grogra.util.LockableImpl
All Implemented Interfaces:
Lockable
Direct Known Subclasses:
PersistenceManager

public class LockableImpl extends Object implements Lockable
  • Constructor Details

    • LockableImpl

      public LockableImpl()
  • Method Details

    • killLock

      public void killLock(Lock x)
    • lock

      public de.grogra.util.LockableImpl.LockImpl lock(boolean hadLock, boolean forWrite)
    • execute

      public void execute(LockProtectedRunnable task, boolean write)
      Description copied from interface: Lockable
      Asynchronously executes a task such that it possesses a lock on this Lockable. Note that the execution is asynchronous, so that the thread in which the task will actually be executed may differ from the current thread.
      Specified by:
      execute in interface Lockable
      Parameters:
      task - the task to execute
      write - shall a write lock be obtained?
    • execute

      public void execute(LockProtectedRunnable task, Lock retained)
      Description copied from interface: Lockable
      Asynchronously executes a task 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.
      Specified by:
      execute in interface Lockable
      Parameters:
      task - the task to execute
      retained - the previously retained lock
      See Also:
    • executeForcedly

      public void executeForcedly(LockProtectedRunnable task, boolean write) throws InterruptedException, Lockable.DeadLockException
      Description copied from interface: Lockable
      Synchronously executes a task such that it possesses a lock on this Lockable. The execution is performed in the current thread.
      Specified by:
      executeForcedly in interface Lockable
      Parameters:
      task - the task to execute
      write - shall a write lock be obtained?
      Throws:
      InterruptedException
      Lockable.DeadLockException
    • executeForcedly

      public void executeForcedly(LockProtectedRunnable task, Lock retained) throws InterruptedException
      Description copied from interface: Lockable
      Synchronously executes a task using a lock which has been retained before within another task. The execution is performed in the current thread.
      Specified by:
      executeForcedly in interface Lockable
      Parameters:
      task - the task to execute
      retained - 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 this Lockable.
      Specified by:
      isLocked in interface Lockable
      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

      public int getQueueLength()
      Description copied from interface: Lockable
      Returns the current number of tasks which are waiting for locked execution.
      Specified by:
      getQueueLength in interface Lockable
      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 interface Lockable
      Returns:
      current maximum waiting time of pending tasks
    • isAllowedThread

      protected boolean isAllowedThread(boolean write)
    • executeInAllowedThread

      protected void executeInAllowedThread(Runnable r)
    • invokeRun

      protected void invokeRun(LockProtectedRunnable task, boolean sync, Lock lock)
    • enterWriteLock

      protected void enterWriteLock()
    • leaveWriteLock

      protected void leaveWriteLock()