Class PolyglotExecutor

java.lang.Object
com.iamsoft.util.ui.javafx.script.PolyglotExecutor
All Implemented Interfaces:
ScriptExecutor

public class PolyglotExecutor extends Object implements ScriptExecutor
  • Constructor Details

    • PolyglotExecutor

      public PolyglotExecutor(Language pLanguage)
    • PolyglotExecutor

      public PolyglotExecutor(Language pLanguage, Consumer<Runnable> pExecutor)
      Parameters:
      pExecutor - A single-thread executor or an executor which doesn't run the tasks simultaneously - should run them one after the other.
  • Method Details

    • getLanguage

      public final Language getLanguage()
      Specified by:
      getLanguage in interface ScriptExecutor
    • getExecutor

      public Consumer<Runnable> getExecutor()
      Specified by:
      getExecutor in interface ScriptExecutor
    • createContext

      protected org.graalvm.polyglot.Context createContext()
    • resetContext

      public void resetContext()
    • eval

      public <T> T eval(String pSource, Map<String,Object> pVarMap, Class<T> pResultType)
      Description copied from interface: ScriptExecutor
      Evaluates the specified code.
      Specified by:
      eval in interface ScriptExecutor
    • eval

      public <T> T eval(String pSource, Map<String,Object> pVarMap, Class<T> pResultType, long pTimeoutMs) throws Exception
      Throws:
      Exception
    • eval

      public <T> void eval(String pSource, Map<String,Object> pVarMap, Class<T> pResultType, BiConsumer<T,Exception> pResultConsumer, long pTimeoutMs)
      Evaluates the specified code and supply the result to the specified result consumer. This method should be invoked only from the JavaFX thread.
      Specified by:
      eval in interface ScriptExecutor
      Parameters:
      pVarMap - A map containing variables with values to pass to guest code execution. The map should be thread-safe.
    • evalAsync

      public <T> T evalAsync(String pSource, Function<org.graalvm.polyglot.Value,T> pResultMapper, long pTimeoutMs) throws InterruptedException
      Evaluates the specified code using the specified context executor and waits for result without blocking the UI. This method must either be called from an input event handler or from the run method of a Runnable passed to Platform.runLater. It must not be called during animation or layout processing.
      Throws:
      InterruptedException - if the specified timeout is reached
    • evalAsync

      public <T> T evalAsync(String pSource, Map<String,Object> pVarMap, Function<org.graalvm.polyglot.Value,T> pResultMapper)
      Evaluates the specified code using the specified context executor and waits for result without blocking the UI. This method must either be called from an input event handler or from the run method of a Runnable passed to Platform.runLater. It must not be called during animation or layout processing.
    • evalAsync

      public <T> T evalAsync(String pSource, Map<String,Object> pVarMap, Class<T> pResultType, long pTimeoutMs) throws InterruptedException
      Evaluates the specified code and waits for result without blocking the UI. This method must either be called from an input event handler or from the run method of a Runnable passed to Platform.runLater. It must not be called during animation or layout processing.
      Parameters:
      pVarMap - A map containing variables with values to pass to guest code execution. The map should be thread-safe.
      Throws:
      InterruptedException - if the specified timeout is reached
    • evalAsync

      public <T> T evalAsync(String pSource, Map<String,Object> pVarMap, Function<org.graalvm.polyglot.Value,T> pResultMapper, long pTimeoutMs) throws InterruptedException
      Evaluates the specified code and waits for result without blocking the UI. This method must either be called from an input event handler or from the run method of a Runnable passed to Platform.runLater. It must not be called during animation or layout processing.
      Parameters:
      pVarMap - A map containing variables with values to pass to guest code execution. The map should be thread-safe.
      Throws:
      InterruptedException - if the specified timeout is reached
    • evalAsync

      public <T> T evalAsync(String pSource, Function<org.graalvm.polyglot.Value,T> pResultMapper, long pTimeoutMs, Consumer<org.graalvm.polyglot.Context> pBeforeEval, Consumer<org.graalvm.polyglot.Context> pAfterEval) throws InterruptedException
      Evaluates the specified code and waits for result without blocking the UI. This method must either be called from an input event handler or from the run method of a Runnable passed to Platform.runLater. It must not be called during animation or layout processing.
      Throws:
      InterruptedException - if the specified timeout is reached
    • evalString

      public String evalString(String pSource)
      Evaluates the specified code and waits for result without blocking the UI. This method must either be called from an input event handler or from the run method of a Runnable passed to Platform.runLater. It must not be called during animation or layout processing.
    • evalString

      public String evalString(String pSource, Map<String,Object> pVarMap)
      Evaluates the specified code and waits for result without blocking the UI. This method must either be called from an input event handler or from the run method of a Runnable passed to Platform.runLater. It must not be called during animation or layout processing.
      Parameters:
      pVarMap - A map containing variables with values to pass to guest code execution. The map should be thread-safe.
    • evalString

      public String evalString(String pSource, long pTimeoutMs) throws InterruptedException
      Evaluates the specified code and waits for result without blocking the UI. This method must either be called from an input event handler or from the run method of a Runnable passed to Platform.runLater. It must not be called during animation or layout processing.
      Throws:
      InterruptedException - if the specified timeout is reached
    • evalString

      public String evalString(String pSource, Map<String,Object> pVarMap, long pTimeoutMs) throws InterruptedException
      Evaluates the specified code using the specified context executor and waits for result without blocking the UI. This method should be invoked only from the JavaFX thread. This method must either be called from an input event handler or from the run method of a Runnable passed to Platform.runLater. It must not be called during animation or layout processing.
      Parameters:
      pVarMap - A map containing variables with values to pass to guest code execution. The map should be thread-safe.
      Throws:
      InterruptedException - if the specified timeout is reached