Class 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 Detail

      • result

        protected R result
      • args

        protected A[] args
    • Constructor Detail

      • FunctionTask

        public FunctionTask​(Function<R,​A> runnable,
                            Object syncObject,
                            boolean catchExceptions,
                            PrintStream exceptionOut)
        Create a RunnableTask object w/ synchronization, ie. suitable for invokeAndWait().
        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 Detail

      • invokeOnCurrentThread

        public static <U,​V> FunctionTask<U,​V> invokeOnCurrentThread​(Function<U,​V> func,
                                                                                V... args)
        Invokes func on the current Thread.

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

        func - the Function to execute.
        args - the Function arguments
        the newly created and invoked FunctionTask
      • 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.
      • 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>
        args - variable argument list, A[], maybe null
        the result.