Class ScriptFileWatcher
- java.lang.Object
-
- org.openhab.core.service.AbstractWatchService
-
- org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher
-
- All Implemented Interfaces:
DependencyTracker.DependencyChangeListener
,ScriptEngineManager.FactoryChangeListener
,ReadyService.ReadyTracker
@NonNullByDefault public class ScriptFileWatcher extends AbstractWatchService implements ReadyService.ReadyTracker, DependencyTracker.DependencyChangeListener, ScriptEngineManager.FactoryChangeListener
TheScriptFileWatcher
watches a directory for files. If a new/modified file is detected, the script is read and passed to theScriptEngineManager
.- Author:
- Simon Merschjohann - Initial contribution, Kai Kreuzer - improved logging and removed thread pool, Jonathan Gilbert - added dependency tracking & per-script start levels; made reusable
-
-
Field Summary
-
Fields inherited from class org.openhab.core.service.AbstractWatchService
pathToWatch, watchQueueReader
-
-
Constructor Summary
Constructors Constructor Description ScriptFileWatcher(ScriptEngineManager manager, @Nullable DependencyTracker dependencyTracker, ReadyService readyService, String fileDirectory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activate()
Method to call on service activationprotected boolean
createAndLoad(ScriptFileReference ref)
void
deactivate()
Method to call on service deactivationvoid
factoryAdded(@Nullable String scriptType)
Called by theScriptEngineManager
when a ScriptEngineFactory is addedvoid
factoryRemoved(@Nullable String scriptType)
Called by theScriptEngineManager
when a ScriptEngineFactory is removedprotected WatchEvent.Kind<?> @Nullable []
getWatchEventKinds(@Nullable Path subDir)
Provides theWatchKey
s for the registration of the directory, which will be registered in the watch service.protected void
importFile(ScriptFileReference ref)
void
onDependencyChange(@Nullable String scriptPath)
void
onReadyMarkerAdded(ReadyMarker readyMarker)
Gets called when a newReadyMarker
was registered as being "ready".void
onReadyMarkerRemoved(ReadyMarker readyMarker)
Gets called when aReadyMarker
was unregistered.protected void
processWatchEvent(@Nullable WatchEvent<?> event, @Nullable WatchEvent.Kind<?> kind, @Nullable Path path)
Processes the given watch event.protected boolean
watchSubDirectories()
Determines whether the subdirectories of the source path (determined by theAbstractWatchService.getSourcePath()
) will be watched or not.-
Methods inherited from class org.openhab.core.service.AbstractWatchService
changeWatchDirectory, getSourcePath
-
-
-
-
Constructor Detail
-
ScriptFileWatcher
public ScriptFileWatcher(ScriptEngineManager manager, @Nullable DependencyTracker dependencyTracker, ReadyService readyService, String fileDirectory)
-
-
Method Detail
-
deactivate
public void deactivate()
Description copied from class:AbstractWatchService
Method to call on service deactivation- Overrides:
deactivate
in classAbstractWatchService
-
activate
public void activate()
Description copied from class:AbstractWatchService
Method to call on service activation- Overrides:
activate
in classAbstractWatchService
-
watchSubDirectories
protected boolean watchSubDirectories()
Description copied from class:AbstractWatchService
Determines whether the subdirectories of the source path (determined by theAbstractWatchService.getSourcePath()
) will be watched or not.- Specified by:
watchSubDirectories
in classAbstractWatchService
- Returns:
true
if the subdirectories will be watched andfalse
if only the source path (determined by theAbstractWatchService.getSourcePath()
) will be watched
-
getWatchEventKinds
protected WatchEvent.Kind<?> @Nullable [] getWatchEventKinds(@Nullable Path subDir)
Description copied from class:AbstractWatchService
Provides theWatchKey
s for the registration of the directory, which will be registered in the watch service.- Specified by:
getWatchEventKinds
in classAbstractWatchService
- Parameters:
subDir
- the directory, which will be registered in the watch service- Returns:
- The array of
WatchKey
s for the registration ornull
if no registration has been done.
-
processWatchEvent
protected void processWatchEvent(@Nullable WatchEvent<?> event, @Nullable WatchEvent.Kind<?> kind, @Nullable Path path)
Description copied from class:AbstractWatchService
Processes the given watch event. Note that the kind and the number of the events for the watched directory is a platform dependent (see the "Platform dependencies" sections ofWatchService
).- Specified by:
processWatchEvent
in classAbstractWatchService
- Parameters:
event
- the watch event to be handledkind
- the event's kindpath
- the path of the event (resolved to theAbstractWatchService.pathToWatch
)
-
importFile
protected void importFile(ScriptFileReference ref)
-
createAndLoad
protected boolean createAndLoad(ScriptFileReference ref)
-
onDependencyChange
public void onDependencyChange(@Nullable String scriptPath)
- Specified by:
onDependencyChange
in interfaceDependencyTracker.DependencyChangeListener
-
onReadyMarkerAdded
public void onReadyMarkerAdded(ReadyMarker readyMarker)
Description copied from interface:ReadyService.ReadyTracker
Gets called when a newReadyMarker
was registered as being "ready".- Specified by:
onReadyMarkerAdded
in interfaceReadyService.ReadyTracker
-
onReadyMarkerRemoved
public void onReadyMarkerRemoved(ReadyMarker readyMarker)
Description copied from interface:ReadyService.ReadyTracker
Gets called when aReadyMarker
was unregistered.- Specified by:
onReadyMarkerRemoved
in interfaceReadyService.ReadyTracker
-
factoryAdded
public void factoryAdded(@Nullable String scriptType)
Description copied from interface:ScriptEngineManager.FactoryChangeListener
Called by theScriptEngineManager
when a ScriptEngineFactory is added- Specified by:
factoryAdded
in interfaceScriptEngineManager.FactoryChangeListener
- Parameters:
scriptType
- the script type supported by the newly added factory
-
factoryRemoved
public void factoryRemoved(@Nullable String scriptType)
Description copied from interface:ScriptEngineManager.FactoryChangeListener
Called by theScriptEngineManager
when a ScriptEngineFactory is removed- Specified by:
factoryRemoved
in interfaceScriptEngineManager.FactoryChangeListener
- Parameters:
scriptType
- the script type supported by the removed factory
-
-