com.jogamp.common.util
Class FunctionTask<R,A>

java.lang.Object
  extended by com.jogamp.common.util.TaskBase
      extended by 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 Summary
protected  A[] args
           
protected  R result
           
protected  Function<R,A> runnable
           
 
Fields inherited from class com.jogamp.common.util.TaskBase
attachment, catchExceptions, isFlushed, runnableException, syncObject, tCreated, tExecuted, tStarted
 
Constructor Summary
FunctionTask(Function<R,A> runnable, Object syncObject, boolean catchExceptions)
          Create a RunnableTask object w/ synchronization, ie.
 
Method Summary
 R eval(A... args)
          Implementation may compute variable args list and returns a result.
 R getResult()
          Retrieves the cached result of run() and is cleared within this method.
 Function<R,A> getRunnable()
          Return the user action
static
<U,V> U
invoke(boolean waitUntilDone, Function<U,V> func, V... args)
          Invokes func.
 void run()
          
 void setArgs(A... args)
          Sets the arguments for run().
 
Methods inherited from class com.jogamp.common.util.TaskBase
flush, getAttachment, getDurationInExec, getDurationInQueue, getDurationTotal, getSyncObject, getThrowable, getTimestampAfterExec, getTimestampBeforeExec, getTimestampCreate, hasWaiter, isExecuted, isFlushed, isInQueue, setAttachment, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

runnable

protected Function<R,A> runnable

result

protected R result

args

protected A[] args
Constructor Detail

FunctionTask

public FunctionTask(Function<R,A> runnable,
                    Object syncObject,
                    boolean catchExceptions)
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 - if true, exception during runnable execution are catched, otherwise not. Use TaskBase.getThrowable() to determine whether an exception has been catched.
Method Detail

invoke

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

Parameters:
waitUntilDone - if true, waits until func execution is completed, otherwise returns immediately.
func - the Function to execute.
args - the Function arguments
Returns:
the Function return value

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.