[jsscripting] Wrapped GraalJS ScriptEngines now also Autocloseable (#12022)

Signed-off-by: Jonathan Gilbert <jpg@trillica.com>
This commit is contained in:
Jonathan Gilbert 2022-01-15 16:44:15 +00:00 committed by Wouter Born
parent 1ce10b1cc1
commit 611f898814
No known key found for this signature in database
GPG Key ID: A58E5C231E0E72B5
4 changed files with 17 additions and 11 deletions

View File

@ -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");

View File

@ -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\");";

View File

@ -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();
}
}

View File

@ -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);
}