Class ScriptedRunnable

  • All Implemented Interfaces:
    java.lang.Runnable

    public class ScriptedRunnable
    extends java.lang.Object
    implements java.lang.Runnable
    A Runnable that can execute script code in another thread. This can be used to parallelize script code using SplitJoin. It is also used by the threads 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 specified ScriptedRunnable.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()
      Returns true if the runnable has completed.
      void run()
      Implements the Runnable interface required for threads and SplitJoin tasks.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ScriptedRunnable

        public ScriptedRunnable​(ScriptedRunnable.Future task)
        A runnable that executes the script code represented by the specified ScriptedRunnable.Future instance. From script code, a ScriptedRunnable 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 is run()
    • Method Detail

      • run

        public void run()
        Implements the Runnable interface required for threads and SplitJoin 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 interface java.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, returns null.
        Returns:
        the return value of the function, or null
      • hasReturnValue

        public boolean hasReturnValue()
        Returns true 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