uk.co.codera.lang.concurrent.PriorityTaskExecutor Maven / Gradle / Ivy
package uk.co.codera.lang.concurrent;
import java.util.Comparator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
import uk.co.codera.lang.concurrent.Tasks.CancellableTask;
import uk.co.codera.lang.concurrent.Tasks.CancellingTask;
/**
*
* A task executor that will process tasks in priority order. It allows tasks
* that overtake to cancel other tasks in the queue.
*
*
* Currently the implementation only allows for serial execution of tasks, i.e.
* it is single threaded. This is to prevent tasks with the same correlation id
* being processed concurrently. In future an executor that allows multiple
* threads whilst keeping tasks with the same correlation id in order may be
* provided.
*
*
* @author andystewart
*/
public class PriorityTaskExecutor {
private final Executor executor;
private final ConcurrentMap