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[]
args
protected R
result
protected 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 R
eval(A... args)
Implementation may compute variableargs
list and returns a result.R
getResult()
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)
Invokesfunc
on the currentThread
.static <U,V>
FunctionTask<U,V>invokeOnNewThread(ThreadGroup tg, String threadName, boolean waitUntilDone, Function<U,V> func, V... args)
Invokesfunc
on a newInterruptSource.Thread
, seeThread(ThreadGroup, Runnable, String)
for details.void
run()
void
setArgs(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 untilrunnable
execution is completed, ornull
if waiting is not desired.catchExceptions
- Influence an occurring exception duringrunnable
execution. 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)
Invokesfunc
on the currentThread
.The result can be retrieved via
getResult()
, using the returned instance.- Parameters:
func
- theFunction
to execute.args
- theFunction
arguments- 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)
Invokesfunc
on a newInterruptSource.Thread
, seeThread(ThreadGroup, Runnable, String)
for details.The result can be retrieved via
getResult()
, using the returned instance.- Parameters:
tg
- theThreadGroup
for the new thread, maybenull
threadName
- the name for the new thread, maybenull
waitUntilDone
- iftrue
, waits untilfunc
execution is completed, otherwise returns immediately.func
- theFunction
to execute.args
- theFunction
arguments- 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()
.
-
-