Package com.pnfsoftware.jeb.util.io
Class FileMonitor
java.lang.Object
com.pnfsoftware.jeb.util.io.FileMonitor
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic FileMonitor
Create a monitor object for the provided file.static FileMonitor
Create a monitor object for the provided file or group of files.static FileMonitor
Retrieve the existing monitor for the provided file.static FileMonitor
Retrieve the existing monitor for the provided file or group of files.boolean
isLocked()
void
lock()
Create and refresh a valid lock file (per this monitor setting).void
unlock
(boolean unregister)
-
Field Details
-
TOUCH_MS
public static final long TOUCH_MSTouch 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_MSCheck frequency in ms, that is, the frequency at which a lock-file write-timestamp is verified.- See Also:
-
-
Method Details
-
get
Retrieve the existing monitor for the provided file.- Parameters:
file
-- Returns:
- Throws:
IOException
-
get
Retrieve the existing monitor for the provided file or group of files.- Parameters:
folder
-filename
-singlefile
-- Returns:
- Throws:
IOException
-
create
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
- Parameters:
unregister
-- Throws:
InterruptedException
-