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
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumstatic interface -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionGet the base directory for thisWatchServicedefault voidregisterListener(WatchService.WatchEventListener watchEventListener, Path path) Register a listener for thisWatchServiceThe given listener will be notified about all events related to files and directories (including subdirectories) in the givenPathdefault voidregisterListener(WatchService.WatchEventListener watchEventListener, Path path, boolean withSubDirectories) Register a listener for thisWatchServiceThe given listener will be notified about all events related to files and directories in the givenPathdefault voidregisterListener(WatchService.WatchEventListener watchEventListener, List<Path> paths) Register a listener for thisWatchServiceThe given listener will be notified about all events related to files and directories (including subdirectories) in the givenPathvoidregisterListener(WatchService.WatchEventListener watchEventListener, List<Path> paths, boolean withSubDirectories) Register a listener for thisWatchServiceThe given listener will be notified about all events related to files and directories in the given list ofPathvoidunregisterListener(WatchService.WatchEventListener watchEventListener) Unregister a listener from thisWatchServiceThe 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 thisWatchServiceThe given listener will be notified about all events related to files and directories (including subdirectories) in the givenPathListeners must unregister themselves before they are disposed- Parameters:
watchEventListener- the listener for this configurationpath- aPaththat the listener is interested in, relative to the base path of the watch service
-
registerListener
Register a listener for thisWatchServiceThe given listener will be notified about all events related to files and directories (including subdirectories) in the givenPathListeners must unregister themselves before they are disposed- Parameters:
watchEventListener- the listener for this configurationpaths- a list ofPaththat 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 thisWatchServiceThe given listener will be notified about all events related to files and directories in the givenPathListeners must unregister themselves before they are disposed- Parameters:
watchEventListener- the listener for this configurationpath- thePaththat 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 thisWatchServiceThe given listener will be notified about all events related to files and directories in the given list ofPathListeners must unregister themselves before they are disposed- Parameters:
watchEventListener- the listener for this configurationpaths- a list ofPaththat 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 thisWatchServiceThe 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
Paththat is the base path for all reported events
-