Class ScriptManager

java.lang.Object
ecmwf.common.technical.ScriptManager
All Implemented Interfaces:
AutoCloseable

public final class ScriptManager extends Object implements AutoCloseable
The Class ScriptManager.
  • Field Details

    • LONG_RUNNING_TIME

      public static final long LONG_RUNNING_TIME
      The Constant LONG_RUNNING_TIME.
    • JS

      public static final String JS
      The Constant JS.
      See Also:
    • PYTHON

      public static final String PYTHON
      The Constant PYTHON.
      See Also:
  • Constructor Details

    • ScriptManager

      public ScriptManager(String language)
      Instantiates a new script manager. Uses the requested script engine.
      Parameters:
      language - the language
    • ScriptManager

      public ScriptManager(long limit, String language)
      Instantiates a new script manager. Uses the requested script engine with a limit.
      Parameters:
      limit - the limit
      language - the language
  • Method Details

    • exec

      public static <T> T exec(Class<T> clazz, String defaultLanguage, String script) throws ScriptException
      Exec. If no language is specified in the header of the script then the default language is used (e.g. script=js:code or script=python:code).
      Type Parameters:
      T - the generic type
      Parameters:
      clazz - the clazz
      defaultLanguage - the default language
      script - the script
      Returns:
      the t
      Throws:
      ScriptException - the script exception
    • exec

      public static void exec(String defaultLanguage, String script) throws ScriptException
      Exec. If no language is specified in the header of the script then the default language is used (e.g. script=js:code or script=python:code).
      Parameters:
      defaultLanguage - the default language
      script - the script
      Throws:
      ScriptException - the script exception
    • eval

      public <T> T eval(Class<T> clazz, String script) throws ScriptException
      Eval.
      Type Parameters:
      T - the generic type
      Parameters:
      clazz - the clazz
      script - the script
      Returns:
      the t
      Throws:
      ScriptException - the script exception
    • eval

      public void eval(String script) throws ScriptException
      Eval.
      Parameters:
      script - the script
      Throws:
      ScriptException - the script exception
    • put

      public void put(String key, Object value) throws ScriptException
      Put.
      Parameters:
      key - the key
      value - the value
      Throws:
      ScriptException - the script exception
    • put

      public void put(Map<String,Object> context) throws ScriptException
      Put.
      Parameters:
      context - the context
      Throws:
      ScriptException - the script exception
    • get

      public <T> T get(Class<T> clazz, String name, Object... args) throws ScriptException
      Gets the value, execute it with the provided arguments if it is a function and then cast it to the desired class.
      Type Parameters:
      T - the generic type
      Parameters:
      clazz - the clazz
      name - the name
      args - the args
      Returns:
      the t
      Throws:
      ScriptException - the script exception
    • getProperties

      public Map<String,String> getProperties() throws ScriptException
      Gets the properties. Just for debugging (values are shorten with ...).
      Returns:
      the properties
      Throws:
      ScriptException - the script exception
    • exists

      public boolean exists(String name) throws ScriptException
      Checks if a variable exists in the underlying script (e.g. mqtt.message.qos).
      Parameters:
      name - the name
      Returns:
      true, if successful
      Throws:
      ScriptException - the script exception
    • close

      public void close()
      Close.
      Specified by:
      close in interface AutoCloseable