public class

FileMonitor

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

Class Overview

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.

Summary

Constants
long CHECK_MS Check frequency in ms, that is, the frequency at which a lock-file write-timestamp is verified.
long TOUCH_MS Touch frequency in ms, that is, the frequency at which a lock-file write-timestamp is updated.
Public Methods
static FileMonitor create(File file)
Create a monitor object for the provided file.
static FileMonitor create(File folder, String filename, boolean singlefile)
Create a monitor object for the provided file or group of files.
static FileMonitor get(File file)
Retrieve the existing monitor for the provided file.@return
static FileMonitor get(File folder, String filename, boolean singlefile)
Retrieve the existing monitor for the provided file or group of files.@return
boolean isLocked()
void lock()
Create and refresh a valid lock file (per this monitor setting).
void unlock(boolean unregister)
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final long CHECK_MS

Check frequency in ms, that is, the frequency at which a lock-file write-timestamp is verified.

Constant Value: 3000 (0x0000000000000bb8)

public static final long TOUCH_MS

Touch frequency in ms, that is, the frequency at which a lock-file write-timestamp is updated.

Constant Value: 1000 (0x00000000000003e8)

Public Methods

public static FileMonitor create (File file)

Create a monitor object for the provided file. (Note that this method does not create any file.)@return

Throws
IOException

public static FileMonitor create (File folder, String filename, boolean singlefile)

Create a monitor object for the provided file or group of files. (Note that this method does not create any file.)@return

Throws
IOException

public static FileMonitor get (File file)

Retrieve the existing monitor for the provided file.@return

Throws
IOException

public static FileMonitor get (File folder, String filename, boolean singlefile)

Retrieve the existing monitor for the provided file or group of files.@return

Throws
IOException

public boolean isLocked ()

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

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.

public void unlock (boolean unregister)

Throws
InterruptedException