/******************************************************************************* * Copyright (c) 2014 BestSolution.at and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation *******************************************************************************/ package at.bestsolution.persistence; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; public class BasicFuture<V> implements Future<V> { static class CustomFuture<T> extends FutureTask<T> { public CustomFuture() { super(new Callable<T>() { @Override public T call() throws Exception { throw new UnsupportedOperationException(); } }); } @Override public void set(T v) { super.set(v); } @Override public void setException(Throwable t) { super.setException(t); } } private CustomFuture<V> future = new CustomFuture<V>(); @Override public boolean cancel(boolean mayInterruptIfRunning) { return future.cancel(mayInterruptIfRunning); } @Override public boolean isCancelled() { return future.isCancelled(); } @Override public boolean isDone() { return future.isDone(); } @Override public V get() throws InterruptedException, ExecutionException { return future.get(); } @Override public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return future.get(timeout, unit); } protected void complete(V value) { future.set(value); } protected void throwExecutionException(Throwable t) { future.setException(t); } }