Class WriteLock

java.lang.Object
org.owasp.dependencycheck.utils.WriteLock
All Implemented Interfaces:
AutoCloseable

@NotThreadSafe public class WriteLock extends Object implements 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 final int
    Max attempts to obtain a lock.
    static final int
    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, String lockFileName)
    Constructs a new Write Lock object with the configured settings.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Releases the lock on the resource.
    final void
    Obtains a lock on the resource.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SLEEP_DURATION

      public static final int SLEEP_DURATION
      How long to sleep waiting for the lock.
      See Also:
    • MAX_SLEEP_COUNT

      public static final int MAX_SLEEP_COUNT
      Max attempts to obtain a lock.
      See Also:
  • Constructor Details

    • 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 settings
      isLockable - 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 settings
      isLockable - 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

      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 interface AutoCloseable