Class FileMonitor

java.lang.Object
com.pnfsoftware.jeb.util.io.FileMonitor

public class FileMonitor extends Object
File monitors can be used to create and retrieve lock on a file for exclusive operations. Locks are implemented as small files alongside the file to be locked.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Check frequency in ms, that is, the frequency at which a lock-file write-timestamp is verified.
    static final long
    Touch frequency in ms, that is, the frequency at which a lock-file write-timestamp is updated.
  • Method Summary

    Modifier and Type
    Method
    Description
    create(File file)
    Create a monitor object for the provided file.
    create(File folder, String filename, boolean singlefile)
    Create a monitor object for the provided file or group of files.
    get(File file)
    Retrieve the existing monitor for the provided file.
    get(File folder, String filename, boolean singlefile)
    Retrieve the existing monitor for the provided file or group of files.
    boolean
     
    void
    Create and refresh a valid lock file (per this monitor setting).
    void
    unlock(boolean unregister)
     

    Methods inherited from class java.lang.Object

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

    • TOUCH_MS

      public static final long TOUCH_MS
      Touch frequency in ms, that is, the frequency at which a lock-file write-timestamp is updated.
      See Also:
    • CHECK_MS

      public static final long CHECK_MS
      Check frequency in ms, that is, the frequency at which a lock-file write-timestamp is verified.
      See Also:
  • Method Details

    • get

      public static FileMonitor get(File file) throws IOException
      Retrieve the existing monitor for the provided file.
      Parameters:
      file -
      Returns:
      Throws:
      IOException
    • get

      public static FileMonitor get(File folder, String filename, boolean singlefile) throws IOException
      Retrieve the existing monitor for the provided file or group of files.
      Parameters:
      folder -
      filename -
      singlefile -
      Returns:
      Throws:
      IOException
    • create

      public static FileMonitor create(File file) throws IOException
      Create a monitor object for the provided file. (Note that this method does not create any file.)
      Parameters:
      file -
      Returns:
      Throws:
      IOException
    • create

      public static FileMonitor create(File folder, String filename, boolean singlefile) throws IOException
      Create a monitor object for the provided file or group of files. (Note that this method does not create any file.)
      Parameters:
      folder -
      filename -
      singlefile -
      Returns:
      Throws:
      IOException
    • isLocked

      public boolean isLocked()
      Returns:
      true if a valid lock file (per this monitor settings) exists and is recent enough to be valid
    • lock

      public void lock()
      Create and refresh a valid lock file (per this monitor setting). This call should be mirrored by a call to #unlock() when monitoring is to stop.
    • unlock

      public void unlock(boolean unregister) throws InterruptedException
      Parameters:
      unregister -
      Throws:
      InterruptedException