[jsscripting] Wrapped GraalJS ScriptEngines now also Autocloseable (#12022)
Signed-off-by: Jonathan Gilbert <jpg@trillica.com>pull/12057/head
parent
67b701b6b4
commit
4d88ad06ae
|
@ -18,7 +18,7 @@ import javax.script.ScriptEngine;
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
|
|
||||||
import org.graalvm.polyglot.PolyglotException;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ import org.slf4j.LoggerFactory;
|
||||||
*
|
*
|
||||||
* @author Jonathan Gilbert - Initial contribution
|
* @author Jonathan Gilbert - Initial contribution
|
||||||
*/
|
*/
|
||||||
class DebuggingGraalScriptEngine<T extends ScriptEngine & Invocable>
|
class DebuggingGraalScriptEngine<T extends ScriptEngine & Invocable & AutoCloseable>
|
||||||
extends InvocationInterceptingScriptEngineWithInvocable<T> {
|
extends InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable<T> {
|
||||||
|
|
||||||
private static final Logger STACK_LOGGER = LoggerFactory
|
private static final Logger STACK_LOGGER = LoggerFactory
|
||||||
.getLogger("org.openhab.automation.script.javascript.stack");
|
.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.PrefixedSeekableByteChannel;
|
||||||
import org.openhab.automation.jsscripting.internal.fs.ReadOnlySeekableByteArrayChannel;
|
import org.openhab.automation.jsscripting.internal.fs.ReadOnlySeekableByteArrayChannel;
|
||||||
import org.openhab.automation.jsscripting.internal.fs.watch.JSDependencyTracker;
|
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.openhab.core.automation.module.script.ScriptExtensionAccessor;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -59,7 +59,8 @@ import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
|
||||||
* @author Jonathan Gilbert - Initial contribution
|
* @author Jonathan Gilbert - Initial contribution
|
||||||
* @author Dan Cunningham - Script injections
|
* @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 Logger LOGGER = LoggerFactory.getLogger(OpenhabGraalJSScriptEngine.class);
|
||||||
private static final String GLOBAL_REQUIRE = "require(\"@jsscripting-globals\");";
|
private static final String GLOBAL_REQUIRE = "require(\"@jsscripting-globals\");";
|
||||||
|
|
|
@ -28,11 +28,11 @@ import javax.script.ScriptException;
|
||||||
*
|
*
|
||||||
* @author Jonathan Gilbert - Initial contribution
|
* @author Jonathan Gilbert - Initial contribution
|
||||||
*/
|
*/
|
||||||
public abstract class DelegatingScriptEngineWithInvocable<T extends ScriptEngine & Invocable>
|
public abstract class DelegatingScriptEngineWithInvocableAndAutocloseable<T extends ScriptEngine & Invocable & AutoCloseable>
|
||||||
implements ScriptEngine, Invocable {
|
implements ScriptEngine, Invocable, AutoCloseable {
|
||||||
protected T delegate;
|
protected T delegate;
|
||||||
|
|
||||||
public DelegatingScriptEngineWithInvocable(T delegate) {
|
public DelegatingScriptEngineWithInvocableAndAutocloseable(T delegate) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,4 +125,9 @@ public abstract class DelegatingScriptEngineWithInvocable<T extends ScriptEngine
|
||||||
public <T> T getInterface(Object o, Class<T> aClass) {
|
public <T> T getInterface(Object o, Class<T> aClass) {
|
||||||
return delegate.getInterface(o, 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
|
* @param <T> The delegate class
|
||||||
* @author Jonathan Gilbert - Initial contribution
|
* @author Jonathan Gilbert - Initial contribution
|
||||||
*/
|
*/
|
||||||
public abstract class InvocationInterceptingScriptEngineWithInvocable<T extends ScriptEngine & Invocable>
|
public abstract class InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable<T extends ScriptEngine & Invocable & AutoCloseable>
|
||||||
extends DelegatingScriptEngineWithInvocable<T> {
|
extends DelegatingScriptEngineWithInvocableAndAutocloseable<T> {
|
||||||
|
|
||||||
public InvocationInterceptingScriptEngineWithInvocable(T delegate) {
|
public InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable(T delegate) {
|
||||||
super(delegate);
|
super(delegate);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue