| 1 | package com.hammurapi.common.concurrent; |
| 2 | |
| 3 | import java.util.List; |
| 4 | import java.util.concurrent.AbstractExecutorService; |
| 5 | import java.util.concurrent.Callable; |
| 6 | import java.util.concurrent.ExecutorService; |
| 7 | import java.util.concurrent.RunnableFuture; |
| 8 | import java.util.concurrent.TimeUnit; |
| 9 | |
| 10 | public class NonBlockingExecutorService extends AbstractExecutorService { |
| 11 | |
| 12 | private ExecutorService master; |
| 13 | |
| 14 | public NonBlockingExecutorService(ExecutorService master) { |
| 15 | this.master = master; |
| 16 | } |
| 17 | |
| 18 | @Override |
| 19 | protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) { |
| 20 | return new NonBlockingFutureTask<T>(callable); |
| 21 | } |
| 22 | |
| 23 | protected <T extends Object> RunnableFuture<T> newTaskFor(Runnable runnable, T value) { |
| 24 | return new NonBlockingFutureTask<T>(runnable, value); |
| 25 | } |
| 26 | |
| 27 | @Override |
| 28 | public void shutdown() { |
| 29 | master.shutdown(); |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public List<Runnable> shutdownNow() { |
| 34 | return master.shutdownNow(); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public boolean isShutdown() { |
| 39 | return master.isShutdown(); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public boolean isTerminated() { |
| 44 | return master.isTerminated(); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { |
| 49 | return master.awaitTermination(timeout, unit); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public void execute(Runnable command) { |
| 54 | master.execute(command); |
| 55 | } |
| 56 | |
| 57 | } |