| 
68
 | 
     1 package fschmidt.util.java;
 | 
| 
 | 
     2 
 | 
| 
 | 
     3 import java.util.concurrent.Callable;
 | 
| 
 | 
     4 import java.util.concurrent.ExecutionException;
 | 
| 
 | 
     5 
 | 
| 
 | 
     6 
 | 
| 
 | 
     7 public abstract class FutureValue<V> {
 | 
| 
 | 
     8 
 | 
| 
 | 
     9 	private final FastFuture<V> ft = new FastFuture<V>(new Callable<V>() {
 | 
| 
 | 
    10 		public V call() throws Exception {
 | 
| 
 | 
    11 			return compute();
 | 
| 
 | 
    12 		}
 | 
| 
 | 
    13 	});
 | 
| 
 | 
    14 
 | 
| 
 | 
    15 	public V get() throws ComputationException {
 | 
| 
 | 
    16 		ft.run();
 | 
| 
 | 
    17 		try {
 | 
| 
 | 
    18 			return ft.get();
 | 
| 
 | 
    19 		} catch(InterruptedException e) {
 | 
| 
 | 
    20 			throw new ComputationException(e);
 | 
| 
 | 
    21 		} catch(ExecutionException e) {
 | 
| 
 | 
    22 			throw ComputationException.newInstance(e);
 | 
| 
 | 
    23 		}
 | 
| 
 | 
    24 	}
 | 
| 
 | 
    25 
 | 
| 
 | 
    26 	protected abstract V compute() throws Exception;
 | 
| 
 | 
    27 }
 |