summaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java')
-rw-r--r--src/java/com/jogamp/common/util/FunctionTask.java38
-rw-r--r--src/java/com/jogamp/common/util/RunnableTask.java4
-rw-r--r--src/java/com/jogamp/common/util/TaskBase.java30
3 files changed, 38 insertions, 34 deletions
diff --git a/src/java/com/jogamp/common/util/FunctionTask.java b/src/java/com/jogamp/common/util/FunctionTask.java
index 8a1ef44..35720a0 100644
--- a/src/java/com/jogamp/common/util/FunctionTask.java
+++ b/src/java/com/jogamp/common/util/FunctionTask.java
@@ -86,23 +86,23 @@ public class FunctionTask<R,A> extends TaskBase implements Function<R,A> {
}
/** Return the user action */
- public Function<R,A> getRunnable() {
+ public final Function<R,A> getRunnable() {
return runnable;
}
/**
* Sets the arguments for {@link #run()}.
- * They will be cleared afterwards.
+ * They will be cleared after calling {@link #run()} or {@link #eval(Object...)}.
*/
- public void setArgs(A... args) {
+ public final void setArgs(A... args) {
this.args = args;
}
/**
* Retrieves the cached result of {@link #run()}
- * and clears it afterwards.
+ * and is cleared within this method.
*/
- public R getResult() {
+ public final R getResult() {
final R res = result;
result = null;
return res;
@@ -119,18 +119,14 @@ public class FunctionTask<R,A> extends TaskBase implements Function<R,A> {
* </p>
*/
@Override
- public void run() {
- result = eval(args);
- args = null;
- }
-
- @Override
- public R eval(A... args) {
- R res = null;
+ public final void run() {
+ final A[] args = this.args;
+ this.args = null;
+ this.result = null;
tStarted = System.currentTimeMillis();
if(null == syncObject) {
try {
- res = runnable.eval(args);
+ this.result = runnable.eval(args);
} catch (Throwable t) {
runnableException = t;
if(!catchExceptions) {
@@ -142,7 +138,7 @@ public class FunctionTask<R,A> extends TaskBase implements Function<R,A> {
} else {
synchronized (syncObject) {
try {
- res = runnable.eval(args);
+ this.result = runnable.eval(args);
} catch (Throwable t) {
runnableException = t;
if(!catchExceptions) {
@@ -153,8 +149,16 @@ public class FunctionTask<R,A> extends TaskBase implements Function<R,A> {
syncObject.notifyAll();
}
}
- }
+ }
+ }
+
+ @Override
+ public final R eval(A... args) {
+ this.args = args;
+ run();
+ final R res = result;
+ result = null;
return res;
- }
+ }
}
diff --git a/src/java/com/jogamp/common/util/RunnableTask.java b/src/java/com/jogamp/common/util/RunnableTask.java
index 6a4ccb3..5d9441a 100644
--- a/src/java/com/jogamp/common/util/RunnableTask.java
+++ b/src/java/com/jogamp/common/util/RunnableTask.java
@@ -78,12 +78,12 @@ public class RunnableTask extends TaskBase {
}
/** Return the user action */
- public Runnable getRunnable() {
+ public final Runnable getRunnable() {
return runnable;
}
@Override
- public void run() {
+ public final void run() {
tStarted = System.currentTimeMillis();
if(null == syncObject) {
try {
diff --git a/src/java/com/jogamp/common/util/TaskBase.java b/src/java/com/jogamp/common/util/TaskBase.java
index e9366c2..d2a924f 100644
--- a/src/java/com/jogamp/common/util/TaskBase.java
+++ b/src/java/com/jogamp/common/util/TaskBase.java
@@ -55,7 +55,7 @@ public abstract class TaskBase implements Runnable {
* Return the synchronization object if any.
* @see #RunnableTask(Runnable, Object, boolean)
*/
- public Object getSyncObject() {
+ public final Object getSyncObject() {
return syncObject;
}
@@ -63,7 +63,7 @@ public abstract class TaskBase implements Runnable {
* Attach a custom object to this task.
* Useful to piggybag further information, ie tag a task final.
*/
- public void setAttachment(Object o) {
+ public final void setAttachment(Object o) {
attachment = o;
}
@@ -71,7 +71,7 @@ public abstract class TaskBase implements Runnable {
* Return the attachment object if any.
* @see #setAttachment(Object)
*/
- public Object getAttachment() {
+ public final Object getAttachment() {
return attachment;
}
@@ -86,7 +86,7 @@ public abstract class TaskBase implements Runnable {
* @see #isFlushed()
* @see #isInQueue()
*/
- public void flush() {
+ public final void flush() {
if(!isExecuted() && hasWaiter()) {
synchronized (syncObject) {
isFlushed = true;
@@ -98,36 +98,36 @@ public abstract class TaskBase implements Runnable {
/**
* @return !{@link #isExecuted()} && !{@link #isFlushed()}
*/
- public boolean isInQueue() { return 0 != tExecuted && !isFlushed; }
+ public final boolean isInQueue() { return 0 != tExecuted && !isFlushed; }
/**
* @return True if executed, otherwise false;
*/
- public boolean isExecuted() { return 0 != tExecuted ; }
+ public final boolean isExecuted() { return 0 != tExecuted ; }
/**
* @return True if flushed, otherwise false;
*/
- public boolean isFlushed() { return isFlushed; }
+ public final boolean isFlushed() { return isFlushed; }
/**
* @return True if invoking thread waits until done,
* ie a <code>notifyObject</code> was passed, otherwise false;
*/
- public boolean hasWaiter() { return null != syncObject; }
+ public final boolean hasWaiter() { return null != syncObject; }
/**
* @return A thrown exception while execution of the user action, if any and if catched
* @see #RunnableTask(Runnable, Object, boolean)
*/
- public Throwable getThrowable() { return runnableException; }
+ public final Throwable getThrowable() { return runnableException; }
- public long getTimestampCreate() { return tCreated; }
- public long getTimestampBeforeExec() { return tStarted; }
- public long getTimestampAfterExec() { return tExecuted; }
- public long getDurationInQueue() { return tStarted - tCreated; }
- public long getDurationInExec() { return tExecuted - tStarted; }
- public long getDurationTotal() { return tExecuted - tCreated; }
+ public final long getTimestampCreate() { return tCreated; }
+ public final long getTimestampBeforeExec() { return tStarted; }
+ public final long getTimestampAfterExec() { return tExecuted; }
+ public final long getDurationInQueue() { return tStarted - tCreated; }
+ public final long getDurationInExec() { return tExecuted - tStarted; }
+ public final long getDurationTotal() { return tExecuted - tCreated; }
@Override
public String toString() {