Package com.netflix.genie.web.scripts
Class ScriptManager
- java.lang.Object
-
- com.netflix.genie.web.scripts.ScriptManager
-
@ThreadSafe public class ScriptManager extends java.lang.Object
Utility to load, reload and execute scripts (in whichever format/language supported byScriptEngine
) 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 Summary
Constructors Constructor Description ScriptManager(ScriptManagerProperties properties, org.springframework.scheduling.TaskScheduler taskScheduler, java.util.concurrent.ExecutorService executorService, javax.script.ScriptEngineManager scriptEngineManager, org.springframework.core.io.ResourceLoader resourceLoader, io.micrometer.core.instrument.MeterRegistry meterRegistry)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
evaluateScript(java.net.URI scriptUri, javax.script.Bindings bindings, long timeout)
Evaluate a given script.void
manageScript(java.net.URI scriptUri)
Start managing the given script, loading it ASAP (asynchronously) and refreshing it periodically.
-
-
-
Constructor Detail
-
ScriptManager
public ScriptManager(ScriptManagerProperties properties, org.springframework.scheduling.TaskScheduler taskScheduler, java.util.concurrent.ExecutorService executorService, javax.script.ScriptEngineManager scriptEngineManager, org.springframework.core.io.ResourceLoader resourceLoader, io.micrometer.core.instrument.MeterRegistry meterRegistry)
Constructor.- Parameters:
properties
- propertiestaskScheduler
- task schedulerexecutorService
- executor servicescriptEngineManager
- script engine managerresourceLoader
- resource loadermeterRegistry
- meter registry
-
-
Method Detail
-
manageScript
public void manageScript(java.net.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 java.lang.Object evaluateScript(java.net.URI scriptUri, javax.script.Bindings bindings, long timeout) throws ScriptNotConfiguredException, ScriptExecutionException
Evaluate a given script.- Parameters:
scriptUri
- the script URIbindings
- the input parameter bindingstimeout
- 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
-
-