- Timestamp:
- 07/04/13 20:29:50 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/util/dispatching/Dispatching.java
r90 r96 3 3 import org.apache.log4j.Logger; 4 4 5 import com.framsticks.util.FramsticksException; 5 6 import com.framsticks.util.StateFunctor; 6 7 … … 28 29 @Override 29 30 public void run() { 30 stateFunctor.call( null);31 stateFunctor.call(); 31 32 } 32 33 }); … … 170 171 } 171 172 172 173 public static class Waiter { 174 protected boolean done = false; 175 176 protected final double timeOut; 177 178 /** 179 * @param timeOut 180 */ 181 public Waiter(double timeOut) { 182 this.timeOut = timeOut; 183 } 184 185 public synchronized void pass() { 186 done = true; 187 this.notify(); 188 } 189 190 public synchronized void waitFor() { 191 long end = System.currentTimeMillis() + (int)(timeOut * 1000); 192 while ((!done) && System.currentTimeMillis() < end) { 193 try { 194 this.wait(end - System.currentTimeMillis()); 195 } catch (InterruptedException e) { 196 break; 197 } 198 } 199 if (!done) { 200 throw new FramsticksException().msg("waiter timed out"); 201 } 202 } 203 } 204 205 206 public static <C> void synchronize(Dispatcher<C> dispatcher, double seconds) { 207 final Waiter waiter = new Waiter(seconds); 208 dispatcher.dispatch(new RunAt<C>() { 209 @Override 210 public void run() { 211 waiter.pass(); 212 } 213 }); 214 waiter.waitFor(); 215 } 173 216 174 217 }
Note: See TracChangeset
for help on using the changeset viewer.