package com.hammurapi.common.concurrent;

import java.util.List;
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.TimeUnit;

public class NonBlockingExecutorService extends AbstractExecutorService {
	
	private ExecutorService master;
	
	public NonBlockingExecutorService(ExecutorService master) {
		this.master = master;
	}
	
	@Override
	protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
		return new NonBlockingFutureTask<T>(callable);
	}
	
	protected <T extends Object> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
		return new NonBlockingFutureTask<T>(runnable, value);
	}

	@Override
	public void shutdown() {
		master.shutdown();
	}

	@Override
	public List<Runnable> shutdownNow() {		
		return master.shutdownNow();
	}

	@Override
	public boolean isShutdown() {
		return master.isShutdown();
	}

	@Override
	public boolean isTerminated() {
		return master.isTerminated();
	}

	@Override
	public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
		return master.awaitTermination(timeout, unit);
	}

	@Override
	public void execute(Runnable command) {
		master.execute(command);
	}

}
