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:
Ryan Ernst 2017-05-24 13:19:27 -07:00 committed by GitHub
parent 7a6db074ee
commit 0ddd219423
10 changed files with 7 additions and 31 deletions

View File

@ -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 {}
}

View File

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

View File

@ -101,9 +101,6 @@ public class ExplainableScriptIT extends ESIntegTestCase {
}
};
}
@Override
public void close() {}
};
}
}

View File

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

View File

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

View File

@ -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.
* */

View File

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

View File

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

View File

@ -134,7 +134,9 @@ public class ExpertScriptPlugin extends Plugin implements ScriptPlugin {
}
@Override
public void close() {}
public void close() {
// optionally close resources
}
}
// end::expert_engine
}

View File

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