Package org.apache.ivy.plugins.lock
Class FileBasedLockStrategy
- java.lang.Object
-
- org.apache.ivy.plugins.lock.AbstractLockStrategy
-
- org.apache.ivy.plugins.lock.FileBasedLockStrategy
-
- All Implemented Interfaces:
LockStrategy
- Direct Known Subclasses:
ArtifactLockStrategy
public abstract class FileBasedLockStrategy extends AbstractLockStrategy
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileBasedLockStrategy.CreateFileLocker
"locks" a file by creating it if it doesn't exist, relying on theFile.createNewFile()
atomicity.static interface
FileBasedLockStrategy.FileLocker
static class
FileBasedLockStrategy.NIOFileLocker
Locks a file using theFileLock
mechanism.
-
Field Summary
Fields Modifier and Type Field Description private static 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.private static long
DEFAULT_TIMEOUT
private FileBasedLockStrategy.FileLocker
locker
The locker to use to make file lock attempts.private static int
SLEEP_TIME
private long
timeout
-
Constructor Summary
Constructors Modifier Constructor Description protected
FileBasedLockStrategy()
protected
FileBasedLockStrategy(boolean debugLocking)
protected
FileBasedLockStrategy(FileBasedLockStrategy.FileLocker locker, boolean debugLocking)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
acquireLock(java.io.File file)
private static void
debugLocking(java.lang.String msg)
private int
decrementLock(java.io.File file, java.lang.Thread forThread)
Decrease depth of this thread's lock.protected java.lang.String
getCurrentLockHolderNames(java.io.File file)
Return a string naming the threads which currently hold this lock.private int
hasLock(java.io.File file, java.lang.Thread forThread)
Determine the state of the lockfile.private int
incrementLock(java.io.File file, java.lang.Thread forThread)
Record that this thread holds the lock.protected void
releaseLock(java.io.File file)
-
Methods inherited from class org.apache.ivy.plugins.lock.AbstractLockStrategy
getName, isDebugLocking, setName, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.ivy.plugins.lock.LockStrategy
lockArtifact, unlockArtifact
-
-
-
-
Field Detail
-
SLEEP_TIME
private static final int SLEEP_TIME
- See Also:
- Constant Field Values
-
DEFAULT_TIMEOUT
private static final long DEFAULT_TIMEOUT
- See Also:
- Constant Field Values
-
locker
private FileBasedLockStrategy.FileLocker locker
The locker to use to make file lock attempts.
-
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)
-
FileBasedLockStrategy
protected FileBasedLockStrategy(FileBasedLockStrategy.FileLocker locker, 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 lockforThread
- 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 lockedforThread
- 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 decreasedforThread
- 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
-
-