Ejemplo n.º 1
0
 public void event(Handler handler, Event event) {
   try {
     eventQueue.put(Pair.<Handler, Message>of(handler, event));
   } catch (InterruptedException e) {
     throw Util.newError(e, "Exception while executing " + event);
   }
 }
Ejemplo n.º 2
0
 <T> T execute(Handler handler, Command<T> command) {
   try {
     eventQueue.put(Pair.<Handler, Message>of(handler, command));
   } catch (InterruptedException e) {
     throw Util.newError(e, "Exception while executing " + command);
   }
   try {
     final Pair<Object, Throwable> pair = responseQueue.take(command);
     if (pair.right != null) {
       if (pair.right instanceof RuntimeException) {
         throw (RuntimeException) pair.right;
       } else if (pair.right instanceof Error) {
         throw (Error) pair.right;
       } else {
         throw new RuntimeException(pair.right);
       }
     } else {
       return (T) pair.left;
     }
   } catch (InterruptedException e) {
     throw Util.newError(e, "Exception while executing " + command);
   }
 }