Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Configuring the script execution



It is possible to configure the way the script execution runs:
  • By default, the script runs in the same Thread as the caller
  • It is possible to configure the framework for running the script in another Thread by ScriptWrapper.setExecutionMode(short)

Running in the same Thread as the caller

This is the default behavior. For example suppose we have the following interface:
      public interface Script {
        public int computeResult(int value);
      }
We can use this code to use a script which implements this interface:
      ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() {};
      Script script = wrapper.getScript();

      File file = new File(<our script file>);
      wrapper.installScript(file);

      int value = script.computeResult(10);

Running in another Thread as the caller

This behavior can be set by ScriptWrapper.setExecutionMode(short). Note that in the case calling the execution of the script will not return directly the output value. The ScriptProxyListener will allow to listen to the effective computation.

For example suppose we have the following interface:
      public interface Script {
        public int computeResult(int value);
      }
We can use this code to use a script which implements this interface:
      ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() {};
      wrapper.setExecutionMode(ScriptWrapper.NON_BLOCKING);
      Script script = wrapper.getScript();

      File file = new File(<our script file>);
      wrapper.installScript(file);

      wrapper.getScriptProxy.addListener(new ScriptProxyListener() {
        public void computed(Object result) {
          System.out.println("The result is: " + (Integer)result);
        }
      }

      script.computeResult(10);

See also


Categories: api

Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence