Class FileBasedLockStrategy

    • Field Detail

      • timeout

        private long timeout
      • currentLockHolders

        private static final java.util.concurrent.ConcurrentMap<java.io.File,​java.util.concurrent.ConcurrentMap<java.lang.Thread,​java.lang.Integer>> currentLockHolders
        Lock counter list must be static: locks are implicitly shared to the entire process, so the list too much be.
    • Constructor Detail

      • FileBasedLockStrategy

        protected FileBasedLockStrategy()
      • FileBasedLockStrategy

        protected FileBasedLockStrategy​(boolean debugLocking)
    • Method Detail

      • acquireLock

        protected boolean acquireLock​(java.io.File file)
                               throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • releaseLock

        protected void releaseLock​(java.io.File file)
      • debugLocking

        private static void debugLocking​(java.lang.String msg)
      • hasLock

        private int hasLock​(java.io.File file,
                            java.lang.Thread forThread)
        Determine the state of the lockfile. Must be called from within a synchronized block. Three possibilities exist: - The lock is held by the current thread (>0) - The lock is held by one or more different threads (-1) - The lock is not held at all (0).
        Parameters:
        file - file to lock
        forThread - thread for which lock status is being queried
      • incrementLock

        private int incrementLock​(java.io.File file,
                                  java.lang.Thread forThread)
        Record that this thread holds the lock. Asserts that the lock has been previously grabbed by this thread. Must be called from a synchronized block in which the lock was grabbed.
        Parameters:
        file - file which has been locked
        forThread - thread for which locking occurred
        Returns:
        number of times this thread has grabbed the lock
      • decrementLock

        private int decrementLock​(java.io.File file,
                                  java.lang.Thread forThread)
        Decrease depth of this thread's lock. Must be called within a synchronized block. If this returns 0, the caller is responsible for releasing the lock within that same block.
        Parameters:
        file - file for which lock depth is being decreased
        forThread - thread for which lock depth is being decreased
        Returns:
        remaining depth of this lock
      • getCurrentLockHolderNames

        protected java.lang.String getCurrentLockHolderNames​(java.io.File file)
        Return a string naming the threads which currently hold this lock.
        Parameters:
        file - File
        Returns:
        String