- Timestamp:
- 07/16/13 23:31:35 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/util/dispatching/Dispatching.java
r101 r102 3 3 import java.util.Timer; 4 4 5 import org.apache.logging.log4j.Level; 5 6 import org.apache.logging.log4j.Logger; 6 7 import org.apache.logging.log4j.LogManager; 7 8 8 9 import com.framsticks.util.FramsticksException; 10 import com.framsticks.util.Misc; 9 11 10 12 /** … … 32 34 } 33 35 36 public static <C> void dispatch(Dispatcher<C> dispatcher, RunAt<? extends C> runnable) { 37 dispatcher.dispatch(runnable); 38 } 39 34 40 // public static boolean assertInvokeLater(Dispatcher dispatcher, RunAt runnable) { 35 41 // dispatcher.invokeLater(runnable); … … 66 72 67 73 public static void use(final Joinable joinable, final JoinableParent owner) { 74 Misc.throwIfNull(joinable); 68 75 log.debug("using {} by {}", joinable, owner); 69 76 if (joinable.use(owner)) { … … 75 82 76 83 public static void drop(final Joinable joinable, final JoinableParent owner) { 84 Misc.throwIfNull(joinable); 77 85 log.debug("droping {} by {}", joinable, owner); 78 86 if (joinable.drop(owner)) { … … 84 92 85 93 public static void join(Joinable joinable) throws InterruptedException { 94 Misc.throwIfNull(joinable); 86 95 log.debug("joining {}", joinable); 87 96 try { … … 95 104 96 105 public static void childChangedState(final JoinableParent parent, final Joinable joinable, final JoinableState state) { 97 if (state.ordinal() < =JoinableState.RUNNING.ordinal()) {106 if (state.ordinal() < JoinableState.RUNNING.ordinal()) { 98 107 return; 99 108 } … … 113 122 } 114 123 } catch (InterruptedException e) { 124 log.debug("failed to wait on {} because of: {}", object, e.getMessage()); 115 125 } 116 126 } … … 123 133 return; 124 134 } catch (InterruptedException e) { 135 log.debug("failed to join {} because of: {}", joinable, e.getMessage()); 125 136 // throw new FramsticksException().msg("failed to join").arg("dispatcher", dispatcher).cause(e); 126 137 } … … 192 203 193 204 // public static class DispatcherWaiter<C, T extends Dispatcher<C> & Joinable> implements Dispatcher<C> { 194 // 195 // 196 // 197 198 // 199 // 200 // 201 // 202 // 203 // 204 205 // 206 // 207 // 208 // 209 // 210 // 211 // 212 // 213 // 214 // 215 216 // 217 218 // 219 // 220 // 221 // 222 223 // 224 // 225 // 226 // 227 // 205 // // protected boolean done = false; 206 // protected final T dispatcher; 207 // protected RunAt<? extends C> runnable; 208 209 // /** 210 // * @param joinable 211 // */ 212 // public DispatcherWaiter(T dispatcher) { 213 // this.dispatcher = dispatcher; 214 // } 215 216 // public synchronized void waitFor() { 217 // while ((runnable == null) && (dispatcher.getState().ordinal() <= JoinableState.RUNNING.ordinal())) { 218 // try { 219 // this.wait(); 220 // } catch (InterruptedException e) { 221 // } 222 // } 223 // if (runnable != null) { 224 // runnable.run(); 225 // } 226 227 // } 228 229 // @Override 230 // public boolean isActive() { 231 // return dispatcher.isActive(); 232 // } 233 234 // @Override 235 // public synchronized void dispatch(RunAt<? extends C> runnable) { 236 // this.runnable = runnable; 237 // this.notifyAll(); 238 // } 228 239 229 240 // } … … 284 295 } 285 296 297 public static <C> void dispatchLog(final Dispatcher<C> dispatcher, final Logger logger, final Level level, final Object text) { 298 dispatcher.dispatch(new RunAt<C>(ThrowExceptionHandler.getInstance()) { 299 300 @Override 301 protected void runAt() { 302 logger.log(level, "message dispatched into {}: {}", dispatcher, text); 303 } 304 }); 305 306 } 307 286 308 }
Note: See TracChangeset
for help on using the changeset viewer.