Class BaseScriptEvaluator

java.lang.Object
org.jppf.scripting.BaseScriptEvaluator
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ScriptedJobSelector, ScriptedNodeSelector

public class BaseScriptEvaluator extends Object implements Serializable
Base class for implementing and embedding all sorts of scripted logic. Scripts are evaluated using the javax.script.* API (JSR-223).
Since:
5.2
Author:
Laurent Cohen
See Also:
  • Constructor Details

    • BaseScriptEvaluator

      public BaseScriptEvaluator(String language, String script)
      Initialize this selector with the specfied language and script.
      Parameters:
      language - the language of the script to evaluate.
      script - the script to evaluate.
    • BaseScriptEvaluator

      public BaseScriptEvaluator(String language, Reader scriptReader) throws IOException
      Initialize this selector with the specfied language and script reader.
      Parameters:
      language - the language of the script to evaluate.
      scriptReader - a reader from which to read the script to evaluate.
      Throws:
      IOException - if the script could not be read.
    • BaseScriptEvaluator

      public BaseScriptEvaluator(String language, File scriptFile) throws IOException
      Initialize this selector with the specfied language and script file.
      Parameters:
      language - the language of the script to evaluate.
      scriptFile - a file from which to read the script to evaluate.
      Throws:
      IOException - if the script could not be read.
  • Method Details

    • getLanguage

      public String getLanguage()
      Get the language of the script to evaluate.
      Returns:
      the language as a string.
    • getScript

      public String getScript()
      Get the script to evaluate.
      Returns:
      th script as a string.
    • evaluate

      protected Object evaluate(Map<String,Object> variables)
      Evaluate the script with the specified variable bindings.
      Parameters:
      variables - the variables to use i the script.
      Returns:
      whatever is returned by the script, or null if the script evaluation raised an exception.
    • toString

      public String toString()
      Overrides:
      toString in class Object