java.lang.Object
io.helidon.config.FileSystemWatcher
- All Implemented Interfaces:
ChangeWatcher<Path>
This change watcher is backed by
WatchService
to fire a polling event with every change on monitored Path
.
When a parent directory of the path
is not available, or becomes unavailable later, a new attempt to register
WatchService
is scheduled again and again until the directory finally exists and the registration is successful.
This ChangeWatcher
might be initialized with a custom executor
or the Executors.newSingleThreadScheduledExecutor()
is used if none is explicitly configured.
This watcher notifies with appropriate change event in the following cases:
- The watched directory is gone
- The watched directory appears
- A file in the watched directory is deleted, created or modified
A single file system watcher may be used to watch multiple targets. In such a case, if stop()
is invoked, it stops
watching all of these targets.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.helidon.config.spi.ChangeWatcher
ChangeWatcher.ChangeEvent<T>
-
Method Summary
Modifier and TypeMethodDescriptionstatic FileSystemWatcher.Builder
builder()
Fluent API builder forFileSystemWatcher
.static FileSystemWatcher
create()
Create a new file watcher with default configuration.void
initWatchServiceModifiers
(WatchEvent.Modifier... modifiers) Add modifiers to be used when registering theWatchService
.void
start
(Path target, Consumer<ChangeWatcher.ChangeEvent<Path>> listener) Start watching a target for changes.void
stop()
Stop watching all targets for changes.type()
Target supported by this change watcher.
-
Method Details
-
builder
Fluent API builder forFileSystemWatcher
.- Returns:
- a new builder instance
-
create
Create a new file watcher with default configuration.- Returns:
- a new file watcher
-
start
Description copied from interface:ChangeWatcher
Start watching a target for changes. If a change happens, notify the listener.- Specified by:
start
in interfaceChangeWatcher<Path>
- Parameters:
target
- target of this watcher, such asPath
listener
- listener that handles reloading of the resource being watched
-
stop
public void stop()Description copied from interface:ChangeWatcher
Stop watching all targets for changes.- Specified by:
stop
in interfaceChangeWatcher<Path>
-
type
Description copied from interface:ChangeWatcher
Target supported by this change watcher.- Specified by:
type
in interfaceChangeWatcher<Path>
- Returns:
- type supported
-
initWatchServiceModifiers
Add modifiers to be used when registering theWatchService
. SeePath.register
.- Parameters:
modifiers
- the modifiers to add
-