diff options
author | Wesley Wolfe <weswolf@aol.com> | 2014-02-01 17:57:52 -0600 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2014-02-01 17:57:52 -0600 |
commit | 4a6a81e72412d822f6047c0139524203081fad6f (patch) | |
tree | e8c07d8bd008df72c0c129884e9f8d8c80903112 | |
parent | 842962530ac2c603ba63b2f703ddfb623c596dd6 (diff) | |
download | craftbukkit-4a6a81e72412d822f6047c0139524203081fad6f.tar craftbukkit-4a6a81e72412d822f6047c0139524203081fad6f.tar.gz craftbukkit-4a6a81e72412d822f6047c0139524203081fad6f.tar.lz craftbukkit-4a6a81e72412d822f6047c0139524203081fad6f.tar.xz craftbukkit-4a6a81e72412d822f6047c0139524203081fad6f.zip |
Allow AsynchronousExecutor.getSkipQueue() to pull tasks from the queue
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java | 18 |
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; |