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.RunnableARunnablethat can execute script code in another thread. This can be used to parallelize script code usingSplitJoin. It is also used by thethreadslibrary to support with script code.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceScriptedRunnable.FutureThe 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.Futureinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgetDefaultThreadName()Returns a unique default name for a thread running in a script.java.lang.ObjectgetReturnValue()Returns the return value of the script function.booleanhasReturnValue()Returnstrueif the runnable has completed.voidrun()Implements theRunnableinterface required for threads andSplitJointasks.
-
-
-
Constructor Detail
-
ScriptedRunnable
public ScriptedRunnable(ScriptedRunnable.Future task)
A runnable that executes the script code represented by the specifiedScriptedRunnable.Futureinstance. From script code, aScriptedRunnablecan 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 theRunnableinterface required for threads andSplitJointasks. 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:
runin 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()
Returnstrueif the runnable has completed.- Returns:
trueif 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
-
-