Package org.openhab.core.service
Interface WatchService
@NonNullByDefault
public interface WatchService
The
WatchService
defines the interface for a general watch service. It allows registering
listeners for subdirectories of the openHAB configuration directory. The reported path in the event is relative to
the registered path. Watch services are created by WatchServiceFactory.createWatchService(String, Path)
.
For files in the openHAB configuration folder a watch service with the name CONFIG_WATCHER_NAME
is registered. For convenience, an OSGi target filter for referencing this watch service is provided
CONFIG_WATCHER_FILTER
.- Author:
- Jan N. Klug - Initial contribution
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
static interface
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionGet the base directory for thisWatchService
default void
registerListener
(WatchService.WatchEventListener watchEventListener, Path path) Register a listener for thisWatchService
The given listener will be notified about all events related to files and directories (including subdirectories) in the givenPath
default void
registerListener
(WatchService.WatchEventListener watchEventListener, Path path, boolean withSubDirectories) Register a listener for thisWatchService
The given listener will be notified about all events related to files and directories in the givenPath
default void
registerListener
(WatchService.WatchEventListener watchEventListener, List<Path> paths) Register a listener for thisWatchService
The given listener will be notified about all events related to files and directories (including subdirectories) in the givenPath
void
registerListener
(WatchService.WatchEventListener watchEventListener, List<Path> paths, boolean withSubDirectories) Register a listener for thisWatchService
The given listener will be notified about all events related to files and directories in the given list ofPath
void
unregisterListener
(WatchService.WatchEventListener watchEventListener) Unregister a listener from thisWatchService
The listener will no longer be notified of watch events
-
Field Details
-
SERVICE_PID
- See Also:
-
SERVICE_PROPERTY_DIR
- See Also:
-
SERVICE_PROPERTY_NAME
- See Also:
-
CONFIG_WATCHER_NAME
- See Also:
-
CONFIG_WATCHER_FILTER
- See Also:
-
-
Method Details
-
registerListener
Register a listener for thisWatchService
The given listener will be notified about all events related to files and directories (including subdirectories) in the givenPath
Listeners must unregister themselves before they are disposed- Parameters:
watchEventListener
- the listener for this configurationpath
- aPath
that the listener is interested in, relative to the base path of the watch service
-
registerListener
Register a listener for thisWatchService
The given listener will be notified about all events related to files and directories (including subdirectories) in the givenPath
Listeners must unregister themselves before they are disposed- Parameters:
watchEventListener
- the listener for this configurationpaths
- a list ofPath
that the listener is interested in, relative to the base path of the watch service
-
registerListener
default void registerListener(WatchService.WatchEventListener watchEventListener, Path path, boolean withSubDirectories) Register a listener for thisWatchService
The given listener will be notified about all events related to files and directories in the givenPath
Listeners must unregister themselves before they are disposed- Parameters:
watchEventListener
- the listener for this configurationpath
- thePath
that the listener is interested in, relative to the base path of the watch servicewithSubDirectories
- whether subdirectories of the given path should also be watched
-
registerListener
void registerListener(WatchService.WatchEventListener watchEventListener, List<Path> paths, boolean withSubDirectories) Register a listener for thisWatchService
The given listener will be notified about all events related to files and directories in the given list ofPath
Listeners must unregister themselves before they are disposed- Parameters:
watchEventListener
- the listener for this configurationpaths
- a list ofPath
that the listener is interested in, relative to the base path of the watch servicewithSubDirectories
- whether subdirectories of the given paths should also be watched
-
unregisterListener
Unregister a listener from thisWatchService
The listener will no longer be notified of watch events- Parameters:
watchEventListener
- the listener to unregister
-
getWatchPath
Path getWatchPath()Get the base directory for thisWatchService
- Returns:
- the
Path
that is the base path for all reported events
-