[jsscripting] Fix multi-thread access (#13582)

* [jsscripting] Share the lock mechanism that was used only for rules
This change moves the lock object that was originally created for ThreadsafeSimpleRuleDelegate to OpenhabGraalJSScriptEngine to make share it across the whole engine.

* [jsscripting] Inject the lock object into the JS runtime
* [jsscripting] Update `setTimeout` & `setInterval` polyfills to enable threadsafety
* [jsscripting] Upgrade GraalJS from 21.3.0 to 22.3.0
* [jsscripting] Reduce compiler warnings
* [jsscripting] Update node version of frontend-maven-plugin

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This commit is contained in:
Florian Hotze
2022-10-24 13:35:33 +02:00
committed by GitHub
parent 671d2de9b2
commit cf47dc0f39
12 changed files with 222 additions and 65 deletions

View File

@@ -2,10 +2,9 @@
(function (global) {
'use strict';
//Append the script file name OR rule UID depending on which is available
// Append the script file name OR rule UID depending on which is available
const defaultLoggerName = "org.openhab.automation.script" + (globalThis["javax.script.filename"] ? ".file." + globalThis["javax.script.filename"].replace(/^.*[\\\/]/, '') : globalThis["ruleUID"] ? ".ui." + globalThis["ruleUID"] : "");
const System = Java.type('java.lang.System');
const ScriptExecution = Java.type('org.openhab.core.model.script.actions.ScriptExecution');
const ZonedDateTime = Java.type('java.time.ZonedDateTime');
const formatRegExp = /%[sdj%]/g;
@@ -173,7 +172,7 @@
function setTimeout(cb, delay) {
const args = Array.prototype.slice.call(arguments, 2);
return ScriptExecution.createTimerWithArgument(
return ThreadsafeTimers.createTimerWithArgument(
ZonedDateTime.now().plusNanos(delay * 1000000),
args,
function (args) {
@@ -191,7 +190,7 @@
function setInterval(cb, delay) {
const args = Array.prototype.slice.call(arguments, 2);
const delayNanos = delay * 1000000
let timer = ScriptExecution.createTimerWithArgument(
let timer = ThreadsafeTimers.createTimerWithArgument(
ZonedDateTime.now().plusNanos(delayNanos),
args,
function (args) {