Class WriteLock
java.lang.Object
org.owasp.dependencycheck.utils.WriteLock
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionstatic final intMax attempts to obtain a lock.static final intHow long to sleep waiting for the lock. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new Write Lock object with the configured settings.Constructs a new Write Lock object with the configured settings.Constructs a new Write Lock object with the configured settings. -
Method Summary
-
Field Details
-
SLEEP_DURATION
public static final int SLEEP_DURATIONHow long to sleep waiting for the lock.- See Also:
-
MAX_SLEEP_COUNT
public static final int MAX_SLEEP_COUNTMax attempts to obtain a lock.- See Also:
-
-
Constructor Details
-
WriteLock
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
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, 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 Details
-
lock
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:
closein interfaceAutoCloseable
-