Package com.nuix.enginebaseline
Class RubyScriptRunner
- java.lang.Object
 - 
- com.nuix.enginebaseline.RubyScriptRunner
 
 
- 
public class RubyScriptRunner extends java.lang.ObjectProvides an easy way to execute Ruby scripts. 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected java.util.function.BiConsumer<java.lang.Object,org.jruby.embed.internal.BiVariableMap>completedCallbackprotected java.util.function.Consumer<java.lang.String>errorOutputprotected org.jruby.embed.ScriptingContainerscriptingContainerprotected java.lang.ThreadscriptThreadprotected java.util.function.Consumer<java.lang.String>standardOutput 
- 
Constructor Summary
Constructors Constructor Description RubyScriptRunner() 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidinterrupt()Interrupts running script thread if there is one running.booleanisAlive()Checks if script thread exists and is currently running.voidjoin()Joins script thread (if it exists) viaThread.join().voidjoin(long timeoutMillis)Joins script thread (if it exists) viaThread.join(long).voidrunFileAsync(java.io.File scriptFile, java.lang.String nuixVersion, java.util.Map<java.lang.String,java.lang.Object> variables)Runs a ruby script asynchronouslyvoidrunScriptAsync(java.lang.String script, java.lang.String nuixVersion, java.util.Map<java.lang.String,java.lang.Object> variables)Runs a ruby script asynchronouslyvoidsetErrorOutputConsumer(java.util.function.Consumer<java.lang.String> errorOutput)Sets theConsumerwhich will receive error output while script is running.voidsetStandardOutputConsumer(java.util.function.Consumer<java.lang.String> standardOutput)Sets theConsumerwhich will receive standard output while script is running.voidwhenScriptCompletes(java.util.function.BiConsumer<java.lang.Object,org.jruby.embed.internal.BiVariableMap> completedCallback)Allows you to provide a callback to be invoked when script finishes. 
 - 
 
- 
- 
Field Detail
- 
scriptingContainer
protected org.jruby.embed.ScriptingContainer scriptingContainer
 
- 
scriptThread
protected java.lang.Thread scriptThread
 
- 
standardOutput
protected java.util.function.Consumer<java.lang.String> standardOutput
 
- 
errorOutput
protected java.util.function.Consumer<java.lang.String> errorOutput
 
- 
completedCallback
protected java.util.function.BiConsumer<java.lang.Object,org.jruby.embed.internal.BiVariableMap> completedCallback
 
 - 
 
- 
Method Detail
- 
whenScriptCompletes
public void whenScriptCompletes(java.util.function.BiConsumer<java.lang.Object,org.jruby.embed.internal.BiVariableMap> completedCallback)
Allows you to provide a callback to be invoked when script finishes.- Parameters:
 completedCallback- AConsumerthat accepts an Object (the final returned value) and a Map containing all the variables in the scripting container upon completion.
 
- 
interrupt
public void interrupt()
Interrupts running script thread if there is one running. See alsoisAlive(). 
- 
isAlive
public boolean isAlive()
Checks if script thread exists and is currently running.- Returns:
 - True if script thread exists (non-null) and 
Thread.isAlive()returns true. 
 
- 
join
public void join(long timeoutMillis) throws java.lang.InterruptedExceptionJoins script thread (if it exists) viaThread.join(long).- Parameters:
 timeoutMillis- the time to wait in milliseconds- Throws:
 java.lang.InterruptedException- if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
 
- 
join
public void join() throws java.lang.InterruptedExceptionJoins script thread (if it exists) viaThread.join().- Throws:
 java.lang.InterruptedException- if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
 
- 
setStandardOutputConsumer
public void setStandardOutputConsumer(java.util.function.Consumer<java.lang.String> standardOutput)
Sets theConsumerwhich will receive standard output while script is running. If null when a script is executed, received messages will be logged by this instance via log4j2.- Parameters:
 standardOutput- The consumer of running script's standard output
 
- 
setErrorOutputConsumer
public void setErrorOutputConsumer(java.util.function.Consumer<java.lang.String> errorOutput)
Sets theConsumerwhich will receive error output while script is running. If null when a script is executed, received messages will be logged by this instance via log4j2.- Parameters:
 errorOutput- The consumer of running script's error output
 
- 
runScriptAsync
public void runScriptAsync(java.lang.String script, java.lang.String nuixVersion, java.util.Map<java.lang.String,java.lang.Object> variables)Runs a ruby script asynchronously- Parameters:
 script- A string containing the Ruby scriptnuixVersion- A string containing the Nuix version to be assigned to constant 'NUIX_VERSION'variables- A map of variables to inject into the script container. Key is variable name, value is the value to assign to that variable. Prefix name with $ for global variables.
 
- 
runFileAsync
public void runFileAsync(java.io.File scriptFile, java.lang.String nuixVersion, java.util.Map<java.lang.String,java.lang.Object> variables)Runs a ruby script asynchronously- Parameters:
 scriptFile- A file containing a Ruby scriptnuixVersion- A string containing the Nuix version to be assigned to constant 'NUIX_VERSION'variables- A map of variables to inject into the script container. Key is variable name, value is the value to assign to that variable. Prefix name with $ for global variables.
 
 - 
 
 -