mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[jsscripting] Wrapped GraalJS ScriptEngines now also Autocloseable (#12022)
Signed-off-by: Jonathan Gilbert <jpg@trillica.com>
This commit is contained in:
parent
1ce10b1cc1
commit
611f898814
@ -18,7 +18,7 @@ import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import org.graalvm.polyglot.PolyglotException;
|
||||
import org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable;
|
||||
import org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -27,8 +27,8 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jonathan Gilbert - Initial contribution
|
||||
*/
|
||||
class DebuggingGraalScriptEngine<T extends ScriptEngine & Invocable>
|
||||
extends InvocationInterceptingScriptEngineWithInvocable<T> {
|
||||
class DebuggingGraalScriptEngine<T extends ScriptEngine & Invocable & AutoCloseable>
|
||||
extends InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable<T> {
|
||||
|
||||
private static final Logger STACK_LOGGER = LoggerFactory
|
||||
.getLogger("org.openhab.automation.script.javascript.stack");
|
||||
|
@ -46,7 +46,7 @@ import org.openhab.automation.jsscripting.internal.fs.DelegatingFileSystem;
|
||||
import org.openhab.automation.jsscripting.internal.fs.PrefixedSeekableByteChannel;
|
||||
import org.openhab.automation.jsscripting.internal.fs.ReadOnlySeekableByteArrayChannel;
|
||||
import org.openhab.automation.jsscripting.internal.fs.watch.JSDependencyTracker;
|
||||
import org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable;
|
||||
import org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable;
|
||||
import org.openhab.core.automation.module.script.ScriptExtensionAccessor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -59,7 +59,8 @@ import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
|
||||
* @author Jonathan Gilbert - Initial contribution
|
||||
* @author Dan Cunningham - Script injections
|
||||
*/
|
||||
public class OpenhabGraalJSScriptEngine extends InvocationInterceptingScriptEngineWithInvocable<GraalJSScriptEngine> {
|
||||
public class OpenhabGraalJSScriptEngine
|
||||
extends InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable<GraalJSScriptEngine> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(OpenhabGraalJSScriptEngine.class);
|
||||
private static final String GLOBAL_REQUIRE = "require(\"@jsscripting-globals\");";
|
||||
|
@ -28,11 +28,11 @@ import javax.script.ScriptException;
|
||||
*
|
||||
* @author Jonathan Gilbert - Initial contribution
|
||||
*/
|
||||
public abstract class DelegatingScriptEngineWithInvocable<T extends ScriptEngine & Invocable>
|
||||
implements ScriptEngine, Invocable {
|
||||
public abstract class DelegatingScriptEngineWithInvocableAndAutocloseable<T extends ScriptEngine & Invocable & AutoCloseable>
|
||||
implements ScriptEngine, Invocable, AutoCloseable {
|
||||
protected T delegate;
|
||||
|
||||
public DelegatingScriptEngineWithInvocable(T delegate) {
|
||||
public DelegatingScriptEngineWithInvocableAndAutocloseable(T delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@ -125,4 +125,9 @@ public abstract class DelegatingScriptEngineWithInvocable<T extends ScriptEngine
|
||||
public <T> T getInterface(Object o, Class<T> aClass) {
|
||||
return delegate.getInterface(o, aClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
delegate.close();
|
||||
}
|
||||
}
|
@ -28,10 +28,10 @@ import javax.script.ScriptException;
|
||||
* @param <T> The delegate class
|
||||
* @author Jonathan Gilbert - Initial contribution
|
||||
*/
|
||||
public abstract class InvocationInterceptingScriptEngineWithInvocable<T extends ScriptEngine & Invocable>
|
||||
extends DelegatingScriptEngineWithInvocable<T> {
|
||||
public abstract class InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable<T extends ScriptEngine & Invocable & AutoCloseable>
|
||||
extends DelegatingScriptEngineWithInvocableAndAutocloseable<T> {
|
||||
|
||||
public InvocationInterceptingScriptEngineWithInvocable(T delegate) {
|
||||
public InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable(T delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user