Package org.owasp.dependencycheck.utils
Class WriteLock
- java.lang.Object
-
- org.owasp.dependencycheck.utils.WriteLock
-
- All Implemented Interfaces:
java.lang.AutoCloseable
@NotThreadSafe public class WriteLock extends java.lang.Object implements java.lang.AutoCloseable
A lock file implementation; creates a custom lock file so that only a single instance of dependency-check can update the a given resource.- Author:
- Jeremy Long
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_SLEEP_COUNT
Max attempts to obtain a lock.static int
SLEEP_DURATION
How long to sleep waiting for the lock.
-
Constructor Summary
Constructors Constructor Description WriteLock(Settings settings)
Constructs a new Write Lock object with the configured settings.WriteLock(Settings settings, boolean isLockable)
Constructs a new Write Lock object with the configured settings.WriteLock(Settings settings, boolean isLockable, java.lang.String lockFileName)
Constructs a new Write Lock object with the configured settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Releases the lock on the resource.void
lock()
Obtains a lock on the resource.
-
-
-
Field Detail
-
SLEEP_DURATION
public static final int SLEEP_DURATION
How long to sleep waiting for the lock.- See Also:
- Constant Field Values
-
MAX_SLEEP_COUNT
public static final int MAX_SLEEP_COUNT
Max attempts to obtain a lock.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
WriteLock
public WriteLock(Settings settings) throws WriteLockException
Constructs a new Write Lock object with the configured settings.- Parameters:
settings
- the configured settings- Throws:
WriteLockException
- thrown if a lock could not be obtained
-
WriteLock
public WriteLock(Settings settings, boolean isLockable) throws WriteLockException
Constructs a new Write Lock object with the configured settings.- Parameters:
settings
- the configured settingsisLockable
- a flag indicating if a lock can be obtained for the resource; if false the lock does nothing. This is useful in the case of ODC where we need to lock for updates against H2 but we do not need to lock updates for other databases.- Throws:
WriteLockException
- thrown if a lock could not be obtained
-
WriteLock
public WriteLock(Settings settings, boolean isLockable, java.lang.String lockFileName) throws WriteLockException
Constructs a new Write Lock object with the configured settings.- Parameters:
settings
- the configured settingsisLockable
- a flag indicating if a lock can be obtained for the resource; if false the lock does nothing. This is useful in the case of ODC where we need to lock for updates against H2 but we do not need to lock updates for other databases.lockFileName
- the name of the lock file; note the lock file will be in the ODC data directory.- Throws:
WriteLockException
- thrown if a lock could not be obtained
-
-
Method Detail
-
lock
public final void lock() throws WriteLockException
Obtains a lock on the resource.- Throws:
WriteLockException
- thrown if a lock could not be obtained
-
close
public void close()
Releases the lock on the resource.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-