Class ScriptedRunnable
- java.lang.Object
-
- ca.cgjennings.apps.arkham.plugins.ScriptedRunnable
-
- All Implemented Interfaces:
java.lang.Runnable
public class ScriptedRunnable extends java.lang.Object implements java.lang.Runnable
ARunnable
that can execute script code in another thread. This can be used to parallelize script code usingSplitJoin
. It is also used by thethreads
library to support with script code.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ScriptedRunnable.Future
The interface that will be implemented using the function passed to the constructor.
-
Constructor Summary
Constructors Constructor Description ScriptedRunnable(ScriptedRunnable.Future task)
A runnable that executes the script code represented by the specifiedScriptedRunnable.Future
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
getDefaultThreadName()
Returns a unique default name for a thread running in a script.java.lang.Object
getReturnValue()
Returns the return value of the script function.boolean
hasReturnValue()
Returnstrue
if the runnable has completed.void
run()
Implements theRunnable
interface required for threads andSplitJoin
tasks.
-
-
-
Constructor Detail
-
ScriptedRunnable
public ScriptedRunnable(ScriptedRunnable.Future task)
A runnable that executes the script code represented by the specifiedScriptedRunnable.Future
instance. From script code, aScriptedRunnable
can be instantiated by passing any function to this constructor. A trivial example:importClass( ca.cgjennings.apps.arkham.plugins.ScriptedRunnable ); importClass( ca.cgjennings.apps.arkham.plugins.ScriptedRunnable.Future ); new ScriptedRunnable( function f() { println('f()'); } ).run();
- Parameters:
task
- a function to be executed when this runnable isrun()
-
-
Method Detail
-
run
public void run()
Implements theRunnable
interface required for threads andSplitJoin
tasks. This will perform the necessary setup to execute script code in a given thread, call the scripted function (with no arguments), then clean up the script execution environment.- Specified by:
run
in interfacejava.lang.Runnable
-
getReturnValue
public java.lang.Object getReturnValue()
Returns the return value of the script function. If an exception was thrown by the function, it will be thrown when this is called. If the function has not completed or returned no value, returnsnull
.- Returns:
- the return value of the function, or
null
-
hasReturnValue
public boolean hasReturnValue()
Returnstrue
if the runnable has completed.- Returns:
true
if the runnable finished running
-
getDefaultThreadName
public static java.lang.String getDefaultThreadName()
Returns a unique default name for a thread running in a script. The name consists of the text "Scripted Thread", a space, and an integer that increases monotonically with each call.- Returns:
- a default thread name
-
-