public class FileWatcher extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
FileWatcher.InstanceHolder |
| Modifier and Type | Field and Description |
|---|---|
private static java.util.Map<SourceType,java.util.function.Consumer<SourceEntry>> |
loaderMap |
private java.util.Map<java.nio.file.Path,SourceEntry> |
sourceMap |
private java.lang.Thread |
thread |
private java.nio.file.WatchService |
watcher |
| Constructor and Description |
|---|
FileWatcher()
Constructs a new
FileWatcher. |
| Modifier and Type | Method and Description |
|---|---|
static FileWatcher |
getDefaultInstance()
Returns the default instance.
|
private void |
processEvents()
Process all events for the key queued to the watcher.
|
static java.util.function.Consumer<SourceEntry> |
registerLoader(SourceType type,
java.util.function.Consumer<SourceEntry> loader)
Registers a source loader, allowing dynamic reloading when an entry changes.
|
void |
registerSource(SourceEntry src)
Registers a source for local file changes, allowing dynamic reloading.
|
void |
start()
Starts the File Watcher thread.
|
private java.nio.file.WatchService watcher
private java.lang.Thread thread
private static final java.util.Map<SourceType,java.util.function.Consumer<SourceEntry>> loaderMap
private final java.util.Map<java.nio.file.Path,SourceEntry> sourceMap
public FileWatcher()
FileWatcher.public static FileWatcher getDefaultInstance()
public final void start()
public void registerSource(SourceEntry src) throws java.io.IOException
src - The source to watchjava.lang.IllegalArgumentException - if rule is null or if it does not provide a local filejava.lang.IllegalStateException - if the watcher service failed to startjava.io.IOException - if an I/O error occurspublic static java.util.function.Consumer<SourceEntry> registerLoader(SourceType type, java.util.function.Consumer<SourceEntry> loader)
type - the source type for which the loader operatesloader - the loader in charge of reloading any source of given type when it changesprivate void processEvents()