mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-03 21:44:40 +01:00
Allow AsynchronousExecutor.getSkipQueue() to pull tasks from the queue
This commit is contained in:
parent
842962530a
commit
4a6a81e724
1 changed files with 12 additions and 6 deletions
|
@ -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 <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 <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
|
* @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> {
|
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.
|
* Adds a callback to the parameter provided, adding parameter to the queue if needed.
|
||||||
|
* <p>
|
||||||
* This should always be synchronous.
|
* This should always be synchronous.
|
||||||
*/
|
*/
|
||||||
public void add(P parameter, C callback) {
|
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.
|
* This method attempts to skip the waiting period for said parameter.
|
||||||
|
* <p>
|
||||||
* This should always be synchronous.
|
* This should always be synchronous.
|
||||||
* @throws IllegalStateException if the parameter is not in the queue anymore, or sometimes if called from asynchronous thread
|
* @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.
|
* Processes a parameter as if it was in the queue, without ever passing to another thread.
|
||||||
*/
|
*/
|
||||||
public T getSkipQueue(P parameter) throws E {
|
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.
|
* 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 {
|
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);
|
provider.callStage3(parameter, object, callback);
|
||||||
return object;
|
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 {
|
public T getSkipQueue(P parameter, C...callbacks) throws E {
|
||||||
final CallBackProvider<P, T, C, E> provider = this.provider;
|
final CallBackProvider<P, T, C, E> provider = this.provider;
|
||||||
final T object = skipQueue(provider, parameter);
|
final T object = skipQueue(parameter);
|
||||||
for (C callback : callbacks) {
|
for (C callback : callbacks) {
|
||||||
provider.callStage3(parameter, object, callback);
|
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 {
|
public T getSkipQueue(P parameter, Iterable<C> callbacks) throws E {
|
||||||
final CallBackProvider<P, T, C, E> provider = this.provider;
|
final CallBackProvider<P, T, C, E> provider = this.provider;
|
||||||
final T object = skipQueue(provider, parameter);
|
final T object = skipQueue(parameter);
|
||||||
for (C callback : callbacks) {
|
for (C callback : callbacks) {
|
||||||
provider.callStage3(parameter, object, callback);
|
provider.callStage3(parameter, object, callback);
|
||||||
}
|
}
|
||||||
return object;
|
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);
|
T object = provider.callStage1(parameter);
|
||||||
provider.callStage2(parameter, object);
|
provider.callStage2(parameter, object);
|
||||||
return object;
|
return object;
|
||||||
|
|
Loading…
Reference in a new issue