Class ScriptManager

java.lang.Object
com.netflix.genie.web.scripts.ScriptManager

@ThreadSafe public class ScriptManager extends Object
Utility to load, reload and execute scripts (in whichever format/language supported by ScriptEngine) via URI (e.g., local file, classpath, URL).

N.B.: Scripts must be explicitly registered by calling manageScript(URI) in order to be evaluated.

N.B.: If a compilation or access error is encountered while reloading a previously compiled script, the latest compiled version is retained, until it can be replaced with a newer one.

Since:
4.0.0
  • Constructor Details

    • ScriptManager

      public ScriptManager(ScriptManagerProperties properties, org.springframework.scheduling.TaskScheduler taskScheduler, ExecutorService executorService, ScriptEngineManager scriptEngineManager, org.springframework.core.io.ResourceLoader resourceLoader, io.micrometer.core.instrument.MeterRegistry meterRegistry)
      Constructor.
      Parameters:
      properties - properties
      taskScheduler - task scheduler
      executorService - executor service
      scriptEngineManager - script engine manager
      resourceLoader - resource loader
      meterRegistry - meter registry
  • Method Details

    • manageScript

      public void manageScript(URI scriptUri)
      Start managing the given script, loading it ASAP (asynchronously) and refreshing it periodically. Because the execution of this task is asynchronous, this method returns immediately and does not surface any loading errors encountered.
      Parameters:
      scriptUri - the script to load and manage
    • evaluateScript

      protected Object evaluateScript(URI scriptUri, Bindings bindings, long timeout) throws ScriptNotConfiguredException, ScriptExecutionException
      Evaluate a given script.
      Parameters:
      scriptUri - the script URI
      bindings - the input parameter bindings
      timeout - the timeout in milliseconds
      Returns:
      the result of the evaluation
      Throws:
      ScriptNotConfiguredException - if the script is not loaded (due to invalid URI or compilation errors).
      ScriptExecutionException - if the script evaluation produces an error