1 package hudson.remoting; 2 3 import java.io.IOException ; 4 import java.util.concurrent.ExecutionException ; 5 import java.util.concurrent.ExecutorService ; 6 import java.util.concurrent.TimeUnit ; 7 import java.util.concurrent.TimeoutException ; 8 9 14 public class LocalChannel implements VirtualChannel { 15 private final ExecutorService executor; 16 17 public LocalChannel(ExecutorService executor) { 18 this.executor = executor; 19 } 20 21 public <V, T extends Throwable > V call(Callable<V,T> callable) throws T { 22 return callable.call(); 23 } 24 25 public <V, T extends Throwable > Future<V> callAsync(final Callable<V,T> callable) throws IOException { 26 final java.util.concurrent.Future <V> f = executor.submit(new java.util.concurrent.Callable <V>() { 27 public V call() throws Exception { 28 try { 29 return callable.call(); 30 } catch (Exception t) { 31 throw t; 32 } catch (Error t) { 33 throw t; 34 } catch (Throwable t) { 35 throw new ExecutionException (t); 36 } 37 } 38 }); 39 40 return new Future<V>() { 41 public boolean cancel(boolean mayInterruptIfRunning) { 42 return f.cancel(mayInterruptIfRunning); 43 } 44 45 public boolean isCancelled() { 46 return f.isCancelled(); 47 } 48 49 public boolean isDone() { 50 return f.isDone(); 51 } 52 53 public V get() throws InterruptedException , ExecutionException { 54 return f.get(); 55 } 56 57 public V get(long timeout, TimeUnit unit) throws InterruptedException , ExecutionException , TimeoutException { 58 return f.get(timeout,unit); 59 } 60 }; 61 } 62 63 public void close() { 64 } 66 67 public <T> T export(Class <T> intf, T instance) { 68 return instance; 69 } 70 } 71 | Popular Tags |