Scripting: Add default implementation of close() for ScriptEngine (#24851)
Since groovy was removed, we no longer have any ScriptEngines with resources to release. We may want to keep the option open for a script engine to close resources, but this would not be common. This commit adds a default implementation to ScriptEngine for `close()` to reduce the boiler plate that must be added for a ScriptEngine implementation.
This commit is contained in:
parent
7a6db074ee
commit
0ddd219423
|
@ -23,6 +23,7 @@ import org.elasticsearch.common.Nullable;
|
|||
import org.elasticsearch.search.lookup.SearchLookup;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -47,4 +48,7 @@ public interface ScriptEngine extends Closeable {
|
|||
ExecutableScript executable(CompiledScript compiledScript, @Nullable Map<String, Object> vars);
|
||||
|
||||
SearchScript search(CompiledScript compiledScript, SearchLookup lookup, @Nullable Map<String, Object> vars);
|
||||
|
||||
@Override
|
||||
default void close() throws IOException {}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,6 @@ public class ScriptServiceTests extends ESTestCase {
|
|||
}
|
||||
scripts.put("script", p -> null);
|
||||
scriptEngine = new MockScriptEngine(Script.DEFAULT_SCRIPT_LANG, scripts);
|
||||
|
||||
//prevent duplicates using map
|
||||
contexts = new HashMap<>(ScriptContext.BUILTINS);
|
||||
engines = new HashMap<>();
|
||||
|
@ -316,5 +315,4 @@ public class ScriptServiceTests extends ESTestCase {
|
|||
notNullValue()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -101,9 +101,6 @@ public class ExplainableScriptIT extends ESIntegTestCase {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1021,10 +1021,6 @@ public class SuggestSearchIT extends ESIntegTestCase {
|
|||
// which makes the collate code thinks mustache is evaluating the query.
|
||||
public static final String NAME = "mustache";
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return NAME;
|
||||
|
|
|
@ -252,7 +252,4 @@ public class ExpressionScriptEngine extends AbstractComponent implements ScriptE
|
|||
public ExecutableScript executable(CompiledScript compiledScript, Map<String, Object> vars) {
|
||||
return new ExpressionExecutableScript(compiledScript, vars);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
}
|
||||
|
|
|
@ -97,11 +97,6 @@ public final class MustacheScriptEngine implements ScriptEngine {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// Nothing to do here
|
||||
}
|
||||
|
||||
/**
|
||||
* Used at query execution time by script service in order to execute a query template.
|
||||
* */
|
||||
|
|
|
@ -211,14 +211,6 @@ public final class PainlessScriptEngine extends AbstractComponent implements Scr
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Action taken when the engine is closed.
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
private ScriptException convertToScriptException(String scriptName, String scriptSource, Throwable t) {
|
||||
// create a script stack: this is just the script portion
|
||||
List<String> scriptStack = new ArrayList<>();
|
||||
|
|
|
@ -60,7 +60,6 @@ public class NeedsScoreTests extends ESSingleNodeTestCase {
|
|||
ss = service.search(new CompiledScript(ScriptType.INLINE, "randomName", "painless", compiled),
|
||||
lookup, Collections.<String, Object>emptyMap());
|
||||
assertTrue(ss.needsScores());
|
||||
service.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -134,7 +134,9 @@ public class ExpertScriptPlugin extends Plugin implements ScriptPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
public void close() {
|
||||
// optionally close resources
|
||||
}
|
||||
}
|
||||
// end::expert_engine
|
||||
}
|
||||
|
|
|
@ -90,10 +90,6 @@ public class MockScriptEngine implements ScriptEngine {
|
|||
return compiled.createSearchScript(vars, lookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
public class MockCompiledScript {
|
||||
|
||||
private final String name;
|
||||
|
|
Loading…
Reference in New Issue