| | |
| | | |
| | | package com.gitblit.utils; |
| | | |
| | | import com.google.common.collect.Lists; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.lang.Thread.UncaughtExceptionHandler; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import javax.inject.Inject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import com.google.common.collect.Lists; |
| | | |
| | | /** Delayed execution of tasks using a background thread pool. */ |
| | | public class WorkQueue { |
| | |
| | | private final IdGenerator idGenerator; |
| | | private final CopyOnWriteArrayList<Executor> queues; |
| | | |
| | | @Inject |
| | | public WorkQueue(final IdGenerator idGenerator) { |
| | | this.idGenerator = idGenerator; |
| | | this.queues = new CopyOnWriteArrayList<Executor>(); |
| | |
| | | return startTime; |
| | | } |
| | | |
| | | @Override |
| | | public boolean cancel(boolean mayInterruptIfRunning) { |
| | | if (task.cancel(mayInterruptIfRunning)) { |
| | | // Tiny abuse of running: if the task needs to know it was |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int compareTo(Delayed o) { |
| | | return task.compareTo(o); |
| | | } |
| | | |
| | | @Override |
| | | public V get() throws InterruptedException, ExecutionException { |
| | | return task.get(); |
| | | } |
| | | |
| | | @Override |
| | | public V get(long timeout, TimeUnit unit) throws InterruptedException, |
| | | ExecutionException, TimeoutException { |
| | | return task.get(timeout, unit); |
| | | } |
| | | |
| | | @Override |
| | | public long getDelay(TimeUnit unit) { |
| | | return task.getDelay(unit); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isCancelled() { |
| | | return task.isCancelled(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isDone() { |
| | | return task.isDone(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isPeriodic() { |
| | | return task.isPeriodic(); |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | if (running.compareAndSet(false, true)) { |
| | | try { |