summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java b/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java
index 8f3e80e5..7e9efb80 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java
@@ -24,7 +24,7 @@ import org.apache.commons.lang.Validate;
* @param <T> The type of object you provide. This is created in stage 1, and passed to stage 2, 3, and returned if get() is called.
* @param <C> The type of callback you provide. You may register many of these to be passed to the provider in stage 3, one at a time.
* @param <E> A type of exception you may throw and expect to be handled by the main thread
- * @author Wesley Wolfe (c) 2012
+ * @author Wesley Wolfe (c) 2012, 2014
*/
public final class AsynchronousExecutor<P, T, C, E extends Throwable> {
@@ -208,6 +208,7 @@ public final class AsynchronousExecutor<P, T, C, E extends Throwable> {
/**
* Adds a callback to the parameter provided, adding parameter to the queue if needed.
+ * <p>
* This should always be synchronous.
*/
public void add(P parameter, C callback) {
@@ -221,6 +222,7 @@ public final class AsynchronousExecutor<P, T, C, E extends Throwable> {
/**
* This method attempts to skip the waiting period for said parameter.
+ * <p>
* This should always be synchronous.
* @throws IllegalStateException if the parameter is not in the queue anymore, or sometimes if called from asynchronous thread
*/
@@ -236,14 +238,14 @@ public final class AsynchronousExecutor<P, T, C, E extends Throwable> {
* Processes a parameter as if it was in the queue, without ever passing to another thread.
*/
public T getSkipQueue(P parameter) throws E {
- return skipQueue(provider, parameter);
+ return skipQueue(parameter);
}
/**
* Processes a parameter as if it was in the queue, without ever passing to another thread.
*/
public T getSkipQueue(P parameter, C callback) throws E {
- final T object = skipQueue(provider, parameter);
+ final T object = skipQueue(parameter);
provider.callStage3(parameter, object, callback);
return object;
}
@@ -253,7 +255,7 @@ public final class AsynchronousExecutor<P, T, C, E extends Throwable> {
*/
public T getSkipQueue(P parameter, C...callbacks) throws E {
final CallBackProvider<P, T, C, E> provider = this.provider;
- final T object = skipQueue(provider, parameter);
+ final T object = skipQueue(parameter);
for (C callback : callbacks) {
provider.callStage3(parameter, object, callback);
}
@@ -265,14 +267,18 @@ public final class AsynchronousExecutor<P, T, C, E extends Throwable> {
*/
public T getSkipQueue(P parameter, Iterable<C> callbacks) throws E {
final CallBackProvider<P, T, C, E> provider = this.provider;
- final T object = skipQueue(provider, parameter);
+ final T object = skipQueue(parameter);
for (C callback : callbacks) {
provider.callStage3(parameter, object, callback);
}
return object;
}
- private static <T, P, E extends Throwable> T skipQueue(CallBackProvider<P, T, ?, E> provider, P parameter) throws E {
+ private T skipQueue(P parameter) throws E {
+ Task task = tasks.get(parameter);
+ if (task != null) {
+ return task.get();
+ }
T object = provider.callStage1(parameter);
provider.callStage2(parameter, object);
return object;