Class FunctionTask<R,A>

java.lang.Object
com.jogamp.common.util.TaskBase
com.jogamp.common.util.FunctionTask<R,A>
All Implemented Interfaces:
Function<R,A>, Runnable

public class FunctionTask<R,A> extends TaskBase implements Function<R,A>
Helper class to provide a Runnable queue implementation with a Runnable wrapper which notifies after execution for the invokeAndWait() semantics.
  • Field Details

    • runnable

      protected Function<R,A> runnable
    • result

      protected R result
    • args

      protected A[] args
  • Constructor Details

    • FunctionTask

      public FunctionTask(Function<R,A> runnable, Object syncObject, boolean catchExceptions, PrintStream exceptionOut)
      Create a RunnableTask object w/ synchronization, ie. suitable for invokeAndWait().
      Parameters:
      runnable - the user action
      syncObject - the synchronization object the caller shall wait until runnable execution is completed, or null if waiting is not desired.
      catchExceptions - Influence an occurring exception during runnable execution. If true, the exception is silenced and can be retrieved via TaskBase.getThrowable(), otherwise the exception is thrown.
      exceptionOut - If not null, exceptions are written to this PrintStream.
  • Method Details

    • invoke

      public static <U, V> U invoke(boolean waitUntilDone, Function<U,V> func, V... args)
      Deprecated.
    • invokeOnNewThread

      public static <U, V> FunctionTask<U,V> invokeOnNewThread(ThreadGroup tg, String threadName, boolean waitUntilDone, Function<U,V> func, V... args)
      Invokes func on a new InterruptSource.Thread, see Thread(ThreadGroup, Runnable, String) for details.

      The result can be retrieved via getResult(), using the returned instance.

      Parameters:
      tg - the ThreadGroup for the new thread, maybe null
      threadName - the name for the new thread, maybe null
      waitUntilDone - if true, waits until func execution is completed, otherwise returns immediately.
      func - the Function to execute.
      args - the Function arguments
      Returns:
      the newly created and invoked FunctionTask
      Since:
      2.3.2
    • getRunnable

      public final Function<R,A> getRunnable()
      Return the user action
    • setArgs

      public final void setArgs(A... args)
      Sets the arguments for run(). They will be cleared after calling run() or eval(Object...).
    • getResult

      public final R getResult()
      Retrieves the cached result of run() and is cleared within this method.
    • run

      public final void run()

      Calls eval(Object...).

      You may set the eval(Object...) arguments via setArgs(Object...) and retrieve the result via getResult().

      Specified by:
      run in interface Runnable
      Specified by:
      run in class TaskBase
    • eval

      public final R eval(A... args)
      Description copied from interface: Function
      Implementation may compute variable args list and returns a result.
      Specified by:
      eval in interface Function<R,A>
      Parameters:
      args - variable argument list, A[], maybe null
      Returns:
      the result.