@Test public void testScriptEngine() throws ScriptException, ExecutionException { GrvyScriptEngineClient client = this.context.getBean(GrvyScriptEngineClient.class); String script = " def list = [\"1101\",\"1411\",\"1121\",\"1131\"]\n" + " def channels = [\"NET\",\"NCUP\"]\n" + " if (list.contains(交易码) && channels.contains(渠道))\n" + " return true "; Map<String,Object> map = Maps.newHashMap(); map.put("交易码","1101"); map.put("渠道","NET"); ScriptContext scriptContext = new SimpleScriptContext(); Bindings binding = new SimpleBindings(); binding.putAll(map); scriptContext.setBindings(binding,ScriptContext.ENGINE_SCOPE); Boolean flag = client.eval(script,scriptContext); System.out.println("flag-> " + flag); }
public <T> T eval(String script, ScriptContext scripCtx) throws ExecutionException, ScriptException { GroovyCompiledScript compiledScript = grvyCompileScriptCache.get(script); Object result; synchronized (compiledScript) { result = compiledScript.eval(scripCtx); } return (T) result; }
GrvyScriptEngineClient { public <T> T eval(String script, ScriptContext scripCtx) throws ExecutionException, ScriptException { GroovyCompiledScript compiledScript = grvyCompileScriptCache.get(script); Object result; synchronized (compiledScript) { result = compiledScript.eval(scripCtx); } return (T) result; } }
GrvyScriptEngineClient { public <T> T eval(String script, ScriptContext scripCtx) throws ExecutionException, ScriptException { GroovyCompiledScript compiledScript = grvyCompileScriptCache.get(script); Object result; synchronized (compiledScript) { result = compiledScript.eval(scripCtx); } return (T) result; } GrvyScriptEngineClient();  GrvyScriptEngineClient(GroovyClassLoader classLoader); }
GrvyScriptEngineClient { public <T> T eval(String script, ScriptContext scripCtx) throws ExecutionException, ScriptException { GroovyCompiledScript compiledScript = grvyCompileScriptCache.get(script); Object result; synchronized (compiledScript) { result = compiledScript.eval(scripCtx); } return (T) result; } GrvyScriptEngineClient();  GrvyScriptEngineClient(GroovyClassLoader classLoader); T eval(String script, ScriptContext scripCtx); void flushLoadingCache(String key); void flushLoadingCache(List<String> keyList); }
GrvyScriptEngineClient { public <T> T eval(String script, ScriptContext scripCtx) throws ExecutionException, ScriptException { GroovyCompiledScript compiledScript = grvyCompileScriptCache.get(script); Object result; synchronized (compiledScript) { result = compiledScript.eval(scripCtx); } return (T) result; } GrvyScriptEngineClient();  GrvyScriptEngineClient(GroovyClassLoader classLoader); T eval(String script, ScriptContext scripCtx); void flushLoadingCache(String key); void flushLoadingCache(List<String> keyList);  }