-
-
Notifications
You must be signed in to change notification settings - Fork 431
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
[automation] Add support for synchronized execution of compiled scripts #4402
[automation] Add support for synchronized execution of compiled scripts #4402
Conversation
…e implements Lock interface Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
.../org/openhab/core/automation/module/script/internal/handler/AbstractScriptModuleHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@J-N-K I adressed your review 👍 |
FYI this is for openhab/openhab-addons#17510. |
Jenkins finally finished the PR build. |
return compiledScript.get().eval(engine.getContext()); | ||
Object result; |
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.
Why do you create a new object here? You could also return it directly and move the return null
from the ScriptException
catch-block to the end of method (or return nul in the finally
block.
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.
It "feels" better this way for me when reading the code, but I have changed it.
if (engine instanceof Lock lock) { | ||
if (!lock.tryLock(1, TimeUnit.MINUTES)) { |
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.
if (engine instanceof Lock lock) { | |
if (!lock.tryLock(1, TimeUnit.MINUTES)) { | |
if (engine instanceof Lock lock && !lock.tryLock(1, TimeUnit.MINUTES)) { |
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.
Changed.
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
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!
…implements Lock This moves the locking mechanism added in openhab#4402 to the inheritors of AbstractScriptModuleHandler to synchronize execution context access as well. This fixes the problem thathttps://github.com/openhab/openhab-addons/pull/17510 worked around by using Thread.sleep. Signed-off-by: Florian Hotze <dev@florianhotze.com>
…implements Lock (#4426) This moves the locking mechanism added in #4402 to the inheritors of AbstractScriptModuleHandler to synchronize execution context access as well. This fixes the problem thathttps://github.com/openhab/openhab-addons/pull/17510 worked around by using Thread.sleep. Signed-off-by: Florian Hotze <dev@florianhotze.com>
If the ScriptEngine implements the Lock interface, the execution of the CompiledScript is synced by acquisition and release of the log.
This is required for add-ons like JS Scripting.