-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[jsscripting] Reimplement timer creation method of ScriptExecution
#13695
[jsscripting] Reimplement timer creation method of ScriptExecution
#13695
Conversation
…ead of in an extra methods Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…ript services Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
… for thread-safety Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/js-scripting-why-are-we-deprecated-createtimer/140748/18 |
...ng/src/main/java/org/openhab/automation/jsscripting/internal/threading/ThreadsafeTimers.java
Show resolved
Hide resolved
...ting/src/main/java/org/openhab/automation/jsscripting/internal/GraalJSScriptServiceUtil.java
Outdated
Show resolved
Hide resolved
...ng/src/main/java/org/openhab/automation/jsscripting/internal/threading/ThreadsafeTimers.java
Outdated
Show resolved
Hide resolved
...ng/src/main/java/org/openhab/automation/jsscripting/internal/threading/ThreadsafeTimers.java
Show resolved
Hide resolved
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@jpg0 I addressed your review, could you please re-review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only issue I have is with the use of OSGi. If it's a common pattern in openHAB I'm not concerned about it though.
...scripting/src/main/java/org/openhab/automation/jsscripting/internal/JSScriptServiceUtil.java
Outdated
Show resolved
Hide resolved
…th an injection mechanism Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
21c04be
to
fb0ca2d
Compare
…raalJSScriptEngineFactory` Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@kaikreuzer - it seems that @jpg0 is missing as member of the addons contributors group, could you add him? |
…y of `JSRuntimeFeatures` Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
FYI: DCO is failing because of @J-N-K GitHub username is not his real name, which he used to signoff. |
ScriptExecution
ScriptExecution
78a41e0
to
b447b57
Compare
ScriptExecution
ScriptExecution
@jlaur This is ready for your review and merging now. FYI: digitaldan and jpg0 approved at some point, after that I’ve changed the implementation of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Only a small simplification/optimization suggested.
...ng/src/main/java/org/openhab/automation/jsscripting/internal/threading/ThreadsafeTimers.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@jlaur I addressed your review, let's merge. |
ScriptExecution
ScriptExecution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@jlaur All checks have passed. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/js-scripting-why-are-we-deprecated-createtimer/140748/22 |
…penhab#13695) * [jsscripting] Refactor ThreadsafeTimers to create futures inline instead of in an extra methods * [jsscripting] Introduce utility class for providing easy access to script services * [jsscripting] Reimplement timer creation methods from ScriptExecution for thread-safety * [jsscripting] Add missing JavaDoc for reimplement timer creation methods * [jsscripting] Remove the future from the map when setTimeout expires * [jsscripting] Rename `GraalJSScriptServiceUtil` to `JSScriptServiceUtil` * [jsscripting] Remove the `createTimerWithArgument` method * [jsscripting] Replace the OSGi workaround of `JSScriptServiceUtil` with an injection mechanism * [jsscripting] Use constructor to inject `JSScriptServiceUtil` into `GraalJSScriptEngineFactory` * [jsscripting] Minor improvements by @J-N-K (#1) * [jsscripting] Minor changes related to last commit to keep flexibility of `JSRuntimeFeatures` * [jsscripting] Upgrade openhab-js to v2.1.1 * [jsscripting] Remove unused code Signed-off-by: Florian Hotze <florianh_dev@icloud.com> Co-authored-by: Jan N. Klug <github@klug.nrw> Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/typeerror-timer-reschedule-is-not-a-function/141518/10 |
…penhab#13695) * [jsscripting] Refactor ThreadsafeTimers to create futures inline instead of in an extra methods * [jsscripting] Introduce utility class for providing easy access to script services * [jsscripting] Reimplement timer creation methods from ScriptExecution for thread-safety * [jsscripting] Add missing JavaDoc for reimplement timer creation methods * [jsscripting] Remove the future from the map when setTimeout expires * [jsscripting] Rename `GraalJSScriptServiceUtil` to `JSScriptServiceUtil` * [jsscripting] Remove the `createTimerWithArgument` method * [jsscripting] Replace the OSGi workaround of `JSScriptServiceUtil` with an injection mechanism * [jsscripting] Use constructor to inject `JSScriptServiceUtil` into `GraalJSScriptEngineFactory` * [jsscripting] Minor improvements by @J-N-K (openhab#1) * [jsscripting] Minor changes related to last commit to keep flexibility of `JSRuntimeFeatures` * [jsscripting] Upgrade openhab-js to v2.1.1 * [jsscripting] Remove unused code Signed-off-by: Florian Hotze <florianh_dev@icloud.com> Co-authored-by: Jan N. Klug <github@klug.nrw>
…penhab#13695) * [jsscripting] Refactor ThreadsafeTimers to create futures inline instead of in an extra methods * [jsscripting] Introduce utility class for providing easy access to script services * [jsscripting] Reimplement timer creation methods from ScriptExecution for thread-safety * [jsscripting] Add missing JavaDoc for reimplement timer creation methods * [jsscripting] Remove the future from the map when setTimeout expires * [jsscripting] Rename `GraalJSScriptServiceUtil` to `JSScriptServiceUtil` * [jsscripting] Remove the `createTimerWithArgument` method * [jsscripting] Replace the OSGi workaround of `JSScriptServiceUtil` with an injection mechanism * [jsscripting] Use constructor to inject `JSScriptServiceUtil` into `GraalJSScriptEngineFactory` * [jsscripting] Minor improvements by @J-N-K (#1) * [jsscripting] Minor changes related to last commit to keep flexibility of `JSRuntimeFeatures` * [jsscripting] Upgrade openhab-js to v2.1.1 * [jsscripting] Remove unused code Signed-off-by: Florian Hotze <florianh_dev@icloud.com> Co-authored-by: Jan N. Klug <github@klug.nrw>
…penhab#13695) * [jsscripting] Refactor ThreadsafeTimers to create futures inline instead of in an extra methods * [jsscripting] Introduce utility class for providing easy access to script services * [jsscripting] Reimplement timer creation methods from ScriptExecution for thread-safety * [jsscripting] Add missing JavaDoc for reimplement timer creation methods * [jsscripting] Remove the future from the map when setTimeout expires * [jsscripting] Rename `GraalJSScriptServiceUtil` to `JSScriptServiceUtil` * [jsscripting] Remove the `createTimerWithArgument` method * [jsscripting] Replace the OSGi workaround of `JSScriptServiceUtil` with an injection mechanism * [jsscripting] Use constructor to inject `JSScriptServiceUtil` into `GraalJSScriptEngineFactory` * [jsscripting] Minor improvements by @J-N-K (#1) * [jsscripting] Minor changes related to last commit to keep flexibility of `JSRuntimeFeatures` * [jsscripting] Upgrade openhab-js to v2.1.1 * [jsscripting] Remove unused code Signed-off-by: Florian Hotze <florianh_dev@icloud.com> Co-authored-by: Jan N. Klug <github@klug.nrw>
…penhab#13695) * [jsscripting] Refactor ThreadsafeTimers to create futures inline instead of in an extra methods * [jsscripting] Introduce utility class for providing easy access to script services * [jsscripting] Reimplement timer creation methods from ScriptExecution for thread-safety * [jsscripting] Add missing JavaDoc for reimplement timer creation methods * [jsscripting] Remove the future from the map when setTimeout expires * [jsscripting] Rename `GraalJSScriptServiceUtil` to `JSScriptServiceUtil` * [jsscripting] Remove the `createTimerWithArgument` method * [jsscripting] Replace the OSGi workaround of `JSScriptServiceUtil` with an injection mechanism * [jsscripting] Use constructor to inject `JSScriptServiceUtil` into `GraalJSScriptEngineFactory` * [jsscripting] Minor improvements by @J-N-K (#1) * [jsscripting] Minor changes related to last commit to keep flexibility of `JSRuntimeFeatures` * [jsscripting] Upgrade openhab-js to v2.1.1 * [jsscripting] Remove unused code Signed-off-by: Florian Hotze <florianh_dev@icloud.com> Co-authored-by: Jan N. Klug <github@klug.nrw> Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
Description
This PR reimplements the openHAB Core API for creating timers to make this also threadsafe.
As discussed on the forum https://community.openhab.org/t/js-scripting-why-are-we-deprecated-createtimer/140748, the
setTimeout
andsetInterval
methods do not provide the functionality that advanced users need, and to avoid that those users and users coming from Rules DSL leave JS Scripting because of this missing API, we have to provide thread-safe access to it.Furthermore,
JSScriptServiceUtil
was introduced to provide easy access from to script services provided by core. This replaces the usage of theJSScriptServiceUtil
from the Rules DSL parts of core and therefore reduces dependency on a part that might become an addon in the future.openhab-js is also upgraded to 2.1.1.
Testing
Use the following file-based script to test: