public class Watcher extends Object implements Runnable
Handler as
parameter and orchestrate the redeployment method when a matching file is modified (created, updated or deleted).
Users have the possibility to execute a shell command during the redeployment. On a file change, the undeploy
Handler is called, followed by the execution of the user command. Then the deploy Handler
is invoked.
The watcher watches all files from the current directory and sub-directories.| Constructor and Description |
|---|
Watcher(File root,
List<String> includes,
Handler<Handler<Void>> deploy,
Handler<Handler<Void>> undeploy,
String onRedeployCommand,
long gracePeriod,
long scanPeriod)
Creates a new
Watcher. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Stops watching.
|
protected boolean |
match(File file)
Checks whether the given file matches one of the
includes patterns. |
void |
run()
The watching thread runnable method.
|
Watcher |
watch()
Starts watching.
|
public Watcher(File root, List<String> includes, Handler<Handler<Void>> deploy, Handler<Handler<Void>> undeploy, String onRedeployCommand, long gracePeriod, long scanPeriod)
Watcher.root - the root directoryincludes - the list of include patterns, should not be null or emptydeploy - the function called when deployment is requiredundeploy - the function called when un-deployment is requiredonRedeployCommand - an optional command executed after the un-deployment and before the deploymentgracePeriod - the amount of time in milliseconds to wait between two redeploy even
if there are changesscanPeriod - the time in millisecond between 2 file system scansprotected boolean match(File file)
includes patterns.file - the filetrue if the file matches at least one pattern, false otherwise.public Watcher watch()
public void close()
WatchService.Copyright © 2020. All rights reserved.