Exemplo n.º 1
0
 public void run() {
   try {
     for (; ; ) {
       try {
         final Pair<Handler, Message> entry = eventQueue.take();
         final Handler handler = entry.left;
         final Message message = entry.right;
         final Object result = message.accept(handler);
         if (message instanceof Command) {
           responseMap.put((Command) message, result);
         } else {
           // Broadcast the event to anyone who is interested.
           RolapUtil.MONITOR_LOGGER.debug(message);
         }
         if (message instanceof ShutdownCommand) {
           LOGGER.debug("ShutdownCommand received. Monitor thread is shutting down.");
           return;
         }
       } catch (InterruptedException e) {
         Thread.currentThread().interrupt();
         LOGGER.warn("Monitor thread interrupted.", e);
         return;
       } catch (Throwable t) {
         LOGGER.error("Runtime error on the monitor thread.", t);
       }
     }
   } finally {
     running = false;
   }
 }
Exemplo n.º 2
0
 Object execute(Handler handler, Command command) {
   try {
     eventQueue.put(Pair.<Handler, Message>of(handler, command));
   } catch (InterruptedException e) {
     throw Util.newError(e, "Interrupted while sending " + command);
   }
   try {
     return responseMap.get(command);
   } catch (InterruptedException e) {
     throw Util.newError(e, "Interrupted while awaiting " + command);
   }
 }