Package com.jogamp.common.util
Class FunctionTask<R,A>
- java.lang.Object
-
- com.jogamp.common.util.TaskBase
-
- com.jogamp.common.util.FunctionTask<R,A>
-
-
Field Summary
Fields Modifier and Type Field Description protected A[]argsprotected Rresultprotected Function<R,A>runnable-
Fields inherited from class com.jogamp.common.util.TaskBase
attachment, catchExceptions, exceptionOut, execThread, isExecuted, isFlushed, runnableException, sourceStack, syncObject, tCreated, tExecuted, tStarted
-
-
Constructor Summary
Constructors Constructor Description FunctionTask(Function<R,A> runnable, Object syncObject, boolean catchExceptions, PrintStream exceptionOut)Create a RunnableTask object w/ synchronization, ie.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Reval(A... args)Implementation may compute variableargslist and returns a result.RgetResult()Retrieves the cached result ofrun()and is cleared within this method.Function<R,A>getRunnable()Return the user actionstatic <U,V>
FunctionTask<U,V>invokeOnCurrentThread(Function<U,V> func, V... args)Invokesfuncon the currentThread.static <U,V>
FunctionTask<U,V>invokeOnNewThread(ThreadGroup tg, String threadName, boolean waitUntilDone, Function<U,V> func, V... args)Invokesfuncon a newInterruptSource.Thread, seeThread(ThreadGroup, Runnable, String)for details.voidrun()voidsetArgs(A... args)Sets the arguments forrun().-
Methods inherited from class com.jogamp.common.util.TaskBase
flush, getAttachment, getDurationInExec, getDurationInQueue, getDurationTotal, getExceptionOutIntro, getExecutionThread, getSyncObject, getThrowable, getTimestampAfterExec, getTimestampBeforeExec, getTimestampCreate, hasWaiter, isExecuted, isFlushed, isInQueue, printSourceTrace, setAttachment, toString
-
-
-
-
Constructor Detail
-
FunctionTask
public FunctionTask(Function<R,A> runnable, Object syncObject, boolean catchExceptions, PrintStream exceptionOut)
Create a RunnableTask object w/ synchronization, ie. suitable forinvokeAndWait().- Parameters:
runnable- the user actionsyncObject- the synchronization object the caller shall wait untilrunnableexecution is completed, ornullif waiting is not desired.catchExceptions- Influence an occurring exception duringrunnableexecution. Iftrue, the exception is silenced and can be retrieved viaTaskBase.getThrowable(), otherwise the exception is thrown.exceptionOut- If notnull, exceptions are written to thisPrintStream.
-
-
Method Detail
-
invokeOnCurrentThread
public static <U,V> FunctionTask<U,V> invokeOnCurrentThread(Function<U,V> func, V... args)
Invokesfuncon the currentThread.The result can be retrieved via
getResult(), using the returned instance.- Parameters:
func- theFunctionto execute.args- theFunctionarguments- Returns:
- the newly created and invoked
FunctionTask - Since:
- 2.4.0
-
invokeOnNewThread
public static <U,V> FunctionTask<U,V> invokeOnNewThread(ThreadGroup tg, String threadName, boolean waitUntilDone, Function<U,V> func, V... args)
Invokesfuncon a newInterruptSource.Thread, seeThread(ThreadGroup, Runnable, String)for details.The result can be retrieved via
getResult(), using the returned instance.- Parameters:
tg- theThreadGroupfor the new thread, maybenullthreadName- the name for the new thread, maybenullwaitUntilDone- iftrue, waits untilfuncexecution is completed, otherwise returns immediately.func- theFunctionto execute.args- theFunctionarguments- Returns:
- the newly created and invoked
FunctionTask - Since:
- 2.3.2
-
setArgs
public final void setArgs(A... args)
-
getResult
public final R getResult()
Retrieves the cached result ofrun()and is cleared within this method.
-
run
public final void run()
Calls
eval(Object...).You may set the
eval(Object...)arguments viasetArgs(Object...)and retrieve the result viagetResult().
-
-