Skip to content

Commit a09886c

Browse files
JSR223 mention lifecycle preset
1 parent 7ae2f0c commit a09886c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

configuration/jsr223.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ With `scriptExtension.get("automationManager")` the `automationManager` can be m
250250
- [`RuleFactories` Preset](#rulefactories-preset)
251251
- [`ScriptAction` Preset](#scriptaction-preset)
252252
- [`cache` Preset](#cache-preset)
253+
- [`lifecycle` Preset](#lifecycle-preset)
253254
- [`TriggerType` Objects (all JSR223 languages)](#triggertype-objects-all-jsr223-languages)
254255

255256
#### Default Preset (`importPreset` not required)
@@ -526,6 +527,43 @@ Both caches implement the `org.openhab.core.automation.module.script.rulesupport
526527
- `Object get(String key)`: Get the value for the given key from the cache. Non-existent keys return `null`.
527528
- `Object get(String key, Supplier<Object> supplier`: Get the value for the given key. If no value is present, add the value that is return from the `supplier`.
528529

530+
#### `lifecycle` Preset
531+
532+
It provides a mechanism to execute code, when the input file is deleted. Modifying a file deletes it and creates it again.
533+
534+
535+
| Variable | Description |
536+
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
537+
| `lifecycleTracker` | [`org.openhab.core.automation.module.script.LifecycleScriptExtensionProvider.LifecycleTracker`](https://www.openhab.org/javadoc/latest/org/openhab/core/automation/module/script/lifecyclescriptextensionprovider.lifecycletracker) |
538+
539+
:::: tabs
540+
541+
::: tab Groovy
542+
543+
```groovy
544+
scriptExtension.importPreset("lifecycle")
545+
546+
lifecycleTracker.addDisposeHook(new org.openhab.core.automation.module.script.LifecycleScriptExtensionProvider.Disposable() {
547+
public void dispose() {
548+
org.slf4j.LoggerFactory.getLogger('org.openhab.automation.example').info("Bye")
549+
}
550+
})
551+
```
552+
553+
:::
554+
555+
::: tab Nashorn&nbsp;JS
556+
557+
```js
558+
scriptExtension.importPreset("lifecycle")
559+
560+
lifecycleTracker.addDisposeHook(function() {
561+
Java.type('org.slf4j.LoggerFactory').getLogger("org.openhab.core.automation.examples").info("Bye")
562+
})
563+
```
564+
565+
:::
566+
529567
### `TriggerType` Objects (all JSR223 languages)
530568

531569
The following trigger types are defined by openHAB (custom triggers can also be defined) and take the specified configuration parameters.

0 commit comments

Comments
 (0)