Skip to content

Commit

Permalink
[jsscripting] Wrapped GraalJS ScriptEngines now also Autocloseable (#…
Browse files Browse the repository at this point in the history
…12022)

Signed-off-by: Jonathan Gilbert <jpg@trillica.com>
  • Loading branch information
jpg0 authored Jan 15, 2022
1 parent 67b701b commit 4d88ad0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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;

Expand All @@ -27,8 +27,8 @@
*
* @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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
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;
Expand All @@ -59,7 +59,8 @@
* @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\");";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
*
* @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;
}

Expand Down Expand Up @@ -125,4 +125,9 @@ public <T> T getInterface(Class<T> aClass) {
public <T> T getInterface(Object o, Class<T> aClass) {
return delegate.getInterface(o, aClass);
}

@Override
public void close() throws Exception {
delegate.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
* @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);
}

Expand Down

0 comments on commit 4d88ad0

Please sign in to comment.