1 46 package net.jforum.util.concurrent.executor; 47 48 import net.jforum.util.concurrent.Result; 49 50 53 class ReadyResult implements Result 54 { 55 final Object result; 56 final Exception exception; 57 58 public ReadyResult(final Object result, final Exception exception) 59 { 60 this.result = result; 61 this.exception = exception; 62 } 63 64 public boolean hasThrown() throws IllegalStateException 65 { 66 return exception != null; 67 } 68 69 public Object getResult() throws IllegalStateException 70 { 71 if(hasThrown()) { 72 throw new IllegalStateException ("task has thrown an exception"); 73 } 74 75 return result; 76 } 77 78 public Exception getException() throws IllegalStateException 79 { 80 if(!hasThrown()) { 81 throw new IllegalStateException ("task has not thrown an exception"); 82 } 83 84 return exception; 85 } 86 87 public void waitResult() throws InterruptedException 88 { 89 if(Thread.interrupted()) { 90 throw new InterruptedException (); 91 } 92 } 93 94 public boolean poolResult(long timeout) throws InterruptedException 95 { 96 if(Thread.interrupted()) { 97 throw new InterruptedException (); 98 } 99 100 return true; 101 } 102 } | Popular Tags |