1 22 package org.jboss.aspects.asynch; 23 24 import java.lang.reflect.InvocationTargetException ; 25 26 32 public class FutureProxy implements Future 33 { 34 private Future delegate; 35 private boolean released = false; 36 37 public void setDelegate(Future delegate) 38 { 39 synchronized (this) 40 { 41 this.delegate = delegate; 42 if (released) delegate.release(); 43 this.notifyAll(); 44 } 45 } 46 47 public void release() 48 { 49 synchronized (this) 50 { 51 if (delegate == null) 52 { 53 released = true; 54 return; 55 } 56 } 57 delegate.release(); 58 } 59 60 public Object get() throws InterruptedException , InvocationTargetException 61 { 62 synchronized (this) 63 { 64 if (delegate == null) 65 this.wait(); 66 if (delegate == null) throw new RuntimeException ("Failed to get delegate and timed out"); 67 return delegate.get(); 68 } 69 } 70 71 public Object get(long milliseconds) throws TimeoutException, InterruptedException , InvocationTargetException 72 { 73 synchronized (this) 74 { 75 if (delegate == null) 76 { 77 this.wait(milliseconds); 78 if (delegate == null) throw new TimeoutException("Failed to get delegate and timed out"); 79 } 80 } 81 return delegate.get(milliseconds); 82 } 83 84 public boolean isDone() 85 { 86 return delegate == null || delegate.isDone(); 87 } 88 89 } 90 | Popular Tags |