Package org.openstreetmap.josm.io
Class FileWatcher
- java.lang.Object
-
- org.openstreetmap.josm.io.FileWatcher
-
public class FileWatcher extends 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 Map<SourceType,Consumer<SourceEntry>>
loaderMap
private Map<Path,SourceEntry>
sourceMap
private Thread
thread
private 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 Consumer<SourceEntry>
registerLoader(SourceType type, 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 WatchService watcher
-
loaderMap
private static final Map<SourceType,Consumer<SourceEntry>> loaderMap
-
sourceMap
private final Map<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 IOException
Registers a source for local file changes, allowing dynamic reloading.- Parameters:
src
- The source to watch- Throws:
IllegalArgumentException
- ifrule
is null or if it does not provide a local fileIllegalStateException
- if the watcher service failed to startIOException
- if an I/O error occurs- Since:
- 12825
-
registerLoader
public static Consumer<SourceEntry> registerLoader(SourceType type, 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.
-
-