Package org.openstreetmap.josm.io
Class FileWatcher
- java.lang.Object
-
- org.openstreetmap.josm.io.FileWatcher
-
public class FileWatcher extends java.lang.Object
Background thread that monitors certain files and perform relevant actions when they change.- Since:
- 7185
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FileWatcher.InstanceHolder
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description FileWatcher()
Constructs a newFileWatcher
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
watcher
private java.nio.file.WatchService watcher
-
thread
private java.lang.Thread thread
-
loaderMap
private static final java.util.Map<SourceType,java.util.function.Consumer<SourceEntry>> loaderMap
-
sourceMap
private final java.util.Map<java.nio.file.Path,SourceEntry> sourceMap
-
-
Constructor Detail
-
FileWatcher
public FileWatcher()
Constructs a newFileWatcher
.
-
-
Method Detail
-
getDefaultInstance
public static FileWatcher getDefaultInstance()
Returns the default instance.- Returns:
- the default instance
- Since:
- 14128
-
start
public final void start()
Starts the File Watcher thread.
-
registerSource
public void registerSource(SourceEntry src) throws java.io.IOException
Registers a source for local file changes, allowing dynamic reloading.- Parameters:
src
- The source to watch- Throws:
java.lang.IllegalArgumentException
- ifrule
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 occurs- Since:
- 12825
-
registerLoader
public 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.- Parameters:
type
- the source type for which the loader operatesloader
- the loader in charge of reloading any source of given type when it changes- Returns:
- the previous loader registered for this source type, if any
- Since:
- 12825
-
processEvents
private void processEvents()
Process all events for the key queued to the watcher.
-
-