* [jsscripting] Fix bundling of global script & regression from #14135
Fixes the regression from https://github.com/openhab/openhab-addons/pull/14135#issuecomment-1369231126.
While working on this, I also noticed that the cache openhab-js does not work because of wrong webpack commandline args in the pom (wrong entrypoint).
* [jsscripting] Enable stack logging for IllegalArgumentExceptions
* [jsscripting] Upgrade openhab-js to 3.2.4
* [jsscripting] Update README for recent PR
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
* [jsscripting] Extend comments for wraprequire
* [jsscripting] Enable openhab-js caching to improve performance
On my dev system (which I guess is much more powerful than most openHAB servers), cached openhab-js injection takes 100-200 ms.
openhab-js injection from file system takes about 1000 ms.
* [jsscripting] Update configuration language
* [jsscripting] Upgrade openhab-js version to 3.2.1 for required webpack changes
Documentation updates will follow in another PR to keep this one clean.
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
* [jsscripting] Share org.graalvm.polyglot.Engine across all OpenhabGraalJSScriptEngine instances
See https://github.com/oracle/graaljs/issues/121#issuecomment-880056648, it is not required to have one engine per GraalJSScriptEngine.
This might improve performance a bit on less powerful systems (Raspberry Pi) and decreases heap usage:
With 5 GraalJS UI scripts, heap usage is now below 100 MB. Before this change, it was over 100 MB.
* [jsscripting] Extend debug logging
* [jsscripting] Cache `@jsscripting-globals.js` across all engines
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
* [jsscripting] Remove asm from dependencies in pom
GraalJS >= 20.3.0 doesn't require org.ow2.asm as compile dependency anymore, see https://mvnrepository.com/artifact/org.graalvm.js/js/20.3.0.
* [jsscripting] Remove dependency org.graalvm.js/js-launcher as it is not required
js-launcher is GraalVM's JavaScript command line interpreter and not required in the addon.
See https://www.graalvm.org/22.1/reference-manual/js/RunOnJDK/.
* [jsscripting] Add missing com.ibm.icu dependency
GraalJS changelog says that it is not required for GraalJS >= 22.0.0 (see 685e5873af/CHANGELOG.md (version-2200)).
But GraalJS 22.3.0 attempts to load classes from it during runtime.
* [jsscripting] Update GraalJS engine options
Compat, as its additional functionality is not used by openhab-js and user code is not expected to use it.
* [jsscripting] Remove com.ibm.icu/icu4j dependency
* [jsscripting] Don't disable Nashorn compat mode as openhab-js requires it for accessors
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
* New translations knx.properties (German)
* New translations yamahamusiccast.properties (German)
* New translations hdpowerview.properties (Danish)
* New translations jsscripting.properties (Danish)
* New translations chromecast.properties (Italian)
* New translations sonos.properties (Italian)
* New translations exec.properties (Italian)
* New translations knx.properties (German)
* New translations jsscripting.properties (German)
* New translations yamahamusiccast.properties (German)
* [jsscripting] Extend synchronization to common ScriptEngine methods
This extends the multi-thread synchronization to "eval" and "invokeMethod" and moves synchronization for "invokeFunction" to the DelegatingScriptEngineWithInvocableAndAutocloseableAndSynchronization class. Fixes the multi-thread access requested warnings described in the community (https://community.openhab.org/t/openhab-3-4-milestone-discussion/138093/130) and related to https://github.com/openhab/openhab-core/pull/3180.
* Revert "[jsscripting] Extend synchronization to common ScriptEngine methods"
This reverts commit aadd21e45879c10aad29bf279ddbb0afd789b0aa.
* [jsscripting] Extend synchronization to common ScriptEngine methods & Switch to ReentrantLock
This extends the multi-thread synchronization to "eval" and "invokeMethod" and moves synchronization for "invokeFunction" to the InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable class.
The synchronization mechanism changed from using synchronized to using a ReentrantLock together with catch_finally to avoid having deadlocks when an exception is thrown.
Fixes the multi-thread access requested warnings described in the community (https://community.openhab.org/t/openhab-3-4-milestone-discussion/138093/130) and related to https://github.com/openhab/openhab-core/pull/3180.
* [jsscripting] Reduce compiler warnings
* [jsscripting] Replace finally blocks & Wrap returns in afterInvocation
* [jsscripting] Fix deadlock caused by NoSuchMethodException in Invocable interface methods
During testing my latest changes, I noticed that there is a deadlock when invokeFunction or invokeMethod are called on a non-existing method.
This happens because the NoSuchMethodException keeps afterInvocation from running and therefore the lock never gets released.
* [jsscripting] Also rethrow NPE & Fix PMD warnings/errors
* [jsscripting] Wrap and rethrow other exceptions instead of returning them
* [jsscripting] Address review comment from @jpg0
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
In recent PR #13824, I added closing the context when the engine is closed, but core seems to have problems with that.
It logs: "[ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error removing ScriptEngine
java.lang.IllegalStateException: The Context is already closed."
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
The alternative MIME type text/javascript is also used by Nashorn, therefore we add the same extension as for the main MIME type.
The alias is introduced to simplify the usage in SCRIPT transformation profiles.
* Fix syntax problems in the bndtools file
* Add null check to avoid potential NPE
In some cases during testing, a NPE occured, this should solve it.
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
* [jsscripting] Fix memory-leak caused by com.oracle.truffle.host.HostObject
Fixes this memory leak by making the HostAccess for the GraalJSScriptEngine available in a static final variable instead of creating it for each new engine.
Solution proposed in https://github.com/oracle/graaljs/issues/121#issuecomment-690179954.
Sharing a single engine across all Contexts (as proposed in https://github.com/oracle/graaljs/issues/121#issuecomment-880056648) is not possible, because core expects a ScriptEngine.
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
* [jsscripting] Update JavaDoc
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
* [jsscripting] Close `GraalJSScriptEngine` when `OpenhabGraalJSScriptEngine` is closed
My breakpoint inside the close method of GraalJSScriptEngine did not trigger until this change was made.
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
* [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>
This fixed the maven build, that fails because webpack-cli version 5.0.0 doesn’t properly process the given entrypoint.
Instead, webpack tries to use the entrypoint from openhab-js‘ webpack config file.
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
* [jsscripting] Downgrade GraalVM to fix issue with armv7l & OpenJDK 11.0.16
The community reported several cases where JS Scripting was not working due to some issue with the injection of the global script.
This issue seems to only occur on armv7l (e.g. Raspberry Pi 32bit) and OpenJDK 11.0.16.
Investigation showed that the occurrence of the problem depends on the GraalJS version.
See https://community.openhab.org/t/js-scripting-all-scripts-stop-working-when-upgrading-to-3-4-0-m4/140837.
* [jsscripting] Add logging for injection of JSRuntimeFeatures
* [jsscripting] Lint `@jsscripting-globals.js` with semistandard
* [jsscripting] Remove ICU4J as it moved to `org.graalvm.truffle`
Reference f5661d4655/CHANGELOG.md (version-2200).
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
* [jsscripting] Reimplement timers to conform standard JS
* [jsscripting] Name scheduled jobs by loggerName + id
* [jsscripting] Update timer identifiers
* [jsscripting] Update identifiers for scheduled jobs
* [jsscripting] Synchronize method that is called when the script is reloaded
* [jsscripting] Cancel all scheduled jobs when the engine is closed
* [jsscripting] Ensure that a timerId is never reused by a subsequent call & Use long primitive type instead of Integer
* [jsscripting] Use an abstraction class to inject features into the JS runtime
* [jsscripting] Make ThreadsafeTimers threadsafe for concurrent access to the class itself
* [jsscripting] Move the locking for `invokeFunction` to `OpenhabGraalJSScriptEngine`
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
* [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>
* Bump openhab-js version to 2.0.0
* Update README for current openhab-js version
* README: Fix paths to images
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>