public class FileMonitor extends Object
Modifier and Type | Class and Description |
---|---|
static class |
FileMonitor.FileItem
One element in the directory
|
static class |
FileMonitor.FileMonitorInformation
Used by Waarp Business information
|
protected class |
FileMonitor.FileMonitorTimerInformationTask
Class to run Waarp Business information in fixed delay rather than after
each check
|
protected static class |
FileMonitor.FileMonitorTimerTask
Timer task
|
static class |
FileMonitor.Status |
Constructor and Description |
---|
FileMonitor(String name,
File statusFile,
File stopFile,
File directory,
FilesystemBasedDigest.DigestAlgo digest,
long elapseTime,
FileFilter filter,
boolean scanSubdir,
FileMonitorCommandRunnableFuture commandValidFile,
FileMonitorCommandRunnableFuture commandRemovedFile,
FileMonitorCommandRunnableFuture commandCheckIteration) |
Modifier and Type | Method and Description |
---|---|
void |
addDirectory(File directory)
Add a directory to scan
|
protected boolean |
checkFiles()
Check Files
|
protected boolean |
checkOneDir(boolean fileItemsChanged,
File directory) |
long |
getCurrentHistoryNb() |
long |
getElapseTime() |
long |
getElapseWaarpTime() |
String |
getStatus() |
boolean |
initialized() |
boolean |
isIgnoreAlreadyUsed() |
static void |
main(String[] args) |
File |
peek() |
File |
poll() |
protected void |
reloadStatus() |
void |
removeDirectory(File directory)
Add a directory to scan
|
protected void |
saveStatus() |
void |
setCheckDelay(long checkDelay) |
void |
setCommandCheckIteration(FileMonitorCommandRunnableFuture commandCheckIteration) |
void |
setCommandValidFileFactory(FileMonitorCommandFactory factory,
int fixedPool) |
void |
setElapseTime(long elapseTime) |
void |
setElapseWaarpTime(long elapseWaarpTime)
if set greater than 1000 ms, will be parallel, else will be sequential
after each check and ignoring this
timer
|
void |
setFilter(FileFilter filter) |
void |
setIgnoreAlreadyUsed(boolean ignoreAlreadyUsed) |
void |
setNextAsFullStatus()
Reset such that next status will be full (not partial)
|
protected void |
setNextDay() |
protected void |
setThreadName() |
void |
start() |
void |
stop() |
void |
waitForStopFile()
Wait until the Stop file is created
|
protected static volatile WaarpLogger logger
protected static final FilesystemBasedDigest.DigestAlgo defaultDigestAlgo
protected static final long MINIMAL_DELAY
protected static final long DEFAULT_DELAY
protected static final long DEFAULT_CHECK_DELAY
protected WaarpFuture future
protected WaarpFuture internalfuture
protected boolean stopped
protected final String name
protected final File statusFile
protected final File stopFile
protected final FilesystemBasedDigest.DigestAlgo digest
protected long elapseTime
protected long elapseWaarpTime
protected long checkDelay
protected io.netty.util.Timer timer
protected io.netty.util.Timer timerWaarp
protected final boolean scanSubDir
protected boolean ignoreAlreadyUsed
protected boolean initialized
protected File checkFile
protected final ConcurrentHashMap<String,FileMonitor.FileItem> fileItems
protected final ConcurrentHashMap<String,FileMonitor.FileItem> lastFileItems
protected FileFilter filter
protected final FileMonitorCommandRunnableFuture commandValidFile
protected FileMonitorCommandFactory commandValidFileFactory
protected ExecutorService executor
protected int fixedThreadPool
protected final FileMonitorCommandRunnableFuture commandRemovedFile
protected FileMonitorCommandRunnableFuture commandCheckIteration
protected final ConcurrentLinkedQueue<FileMonitor.FileItem> toUse
protected final ConcurrentLinkedQueue<Future<?>> results
protected final AtomicLong globalok
protected final AtomicLong globalerror
protected final AtomicLong todayok
protected final AtomicLong todayerror
protected Date nextDay
public FileMonitor(String name, File statusFile, File stopFile, File directory, FilesystemBasedDigest.DigestAlgo digest, long elapseTime, FileFilter filter, boolean scanSubdir, FileMonitorCommandRunnableFuture commandValidFile, FileMonitorCommandRunnableFuture commandRemovedFile, FileMonitorCommandRunnableFuture commandCheckIteration)
name
- name of this daemonstatusFile
- the file where the current status is saved
(current
files)stopFile
- the file when created (.exists()) will stop the
daemondirectory
- the directory where files will be monitoreddigest
- the digest to use (default if null is MD5)elapseTime
- the time to wait in ms for between 2 checks
(default
is 1000ms, minimum is
100ms)filter
- the filter to be applied on selected files (default
is
isFile())commandValidFile
- the commandValidFile to run (may be null,
which
means poll() commandValidFile
has to be used)commandRemovedFile
- the commandRemovedFile to run (may be
null)commandCheckIteration
- the commandCheckIteration to run
(may be
null), runs after each check
(elapseTime)protected void setNextDay()
public void setCommandCheckIteration(FileMonitorCommandRunnableFuture commandCheckIteration)
commandCheckIteration
- the commandCheckIteration to run
(may be
null), runs after each check
(elapseTime)public void setCommandValidFileFactory(FileMonitorCommandFactory factory, int fixedPool)
factory
- the factory to used instead of simple instance
(enables
parallelism)fixedPool
- if > 0, set the number of parallel threads
allowedpublic long getElapseWaarpTime()
public void setElapseWaarpTime(long elapseWaarpTime)
elapseWaarpTime
- the elapseWaarpTime to setpublic boolean isIgnoreAlreadyUsed()
public void setIgnoreAlreadyUsed(boolean ignoreAlreadyUsed)
ignoreAlreadyUsed
- if True, already used files will be ignored.
Else if False, if an already used file is modified, then it will be reused.public void setCheckDelay(long checkDelay)
checkDelay
- the delay before checking if action was
correctly takenpublic void addDirectory(File directory)
directory
- public void removeDirectory(File directory)
directory
- protected void setThreadName()
protected void reloadStatus()
public boolean initialized()
protected void saveStatus()
public long getCurrentHistoryNb()
public void setNextAsFullStatus()
public String getStatus()
public long getElapseTime()
public void setElapseTime(long elapseTime)
elapseTime
- the elapseTime to setpublic void setFilter(FileFilter filter)
filter
- the filter to setpublic void start()
public void stop()
public File peek()
public File poll()
public void waitForStopFile()
protected boolean checkFiles()
protected boolean checkOneDir(boolean fileItemsChanged, File directory)
fileItemsChanged
- directory
- public static void main(String[] args)
Copyright © 2009–2020 Waarp. All rights reserved.