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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
"locks" a file by creating it if it doesn't exist, relying on theFile.createNewFile()
atomicity.static interface
static class
Locks a file using theFileLock
mechanism. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ConcurrentMap<File,
ConcurrentMap<Thread, Integer>> Lock counter list must be static: locks are implicitly shared to the entire process, so the list too much be.private static final long
private FileBasedLockStrategy.FileLocker
The locker to use to make file lock attempts.private static final int
private long
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
protected
FileBasedLockStrategy
(boolean debugLocking) protected
FileBasedLockStrategy
(FileBasedLockStrategy.FileLocker locker, boolean debugLocking) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
acquireLock
(File file) private static void
debugLocking
(String msg) private int
decrementLock
(File file, Thread forThread) Decrease depth of this thread's lock.protected String
Return a string naming the threads which currently hold this lock.private int
Determine the state of the lockfile.private int
incrementLock
(File file, Thread forThread) Record that this thread holds the lock.protected void
releaseLock
(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 Details
-
SLEEP_TIME
private static final int SLEEP_TIME- See Also:
-
DEFAULT_TIMEOUT
private static final long DEFAULT_TIMEOUT- See Also:
-
locker
The locker to use to make file lock attempts. -
timeout
private long timeout -
currentLockHolders
Lock counter list must be static: locks are implicitly shared to the entire process, so the list too much be.
-
-
Constructor Details
-
FileBasedLockStrategy
protected FileBasedLockStrategy() -
FileBasedLockStrategy
protected FileBasedLockStrategy(boolean debugLocking) -
FileBasedLockStrategy
-
-
Method Details
-
acquireLock
- Throws:
InterruptedException
-
releaseLock
-
debugLocking
-
hasLock
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
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
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
Return a string naming the threads which currently hold this lock.- Parameters:
file
- File- Returns:
- String
-