@SuppressWarnings("unchecked")
 @Override
 public void register(Class<? extends Enum> eventType, EventHandler handler) {
   /* check to see if we have a listener registered */
   EventHandler<Event> registeredHandler = (EventHandler<Event>) eventDispatchers.get(eventType);
   LOG.info("Registering " + eventType + " for " + handler.getClass());
   if (registeredHandler == null) {
     eventDispatchers.put(eventType, handler);
   } else if (!(registeredHandler instanceof MultiListenerHandler)) {
     /* for multiple listeners of an event add the multiple listener handler */
     MultiListenerHandler multiHandler = new MultiListenerHandler();
     multiHandler.addHandler(registeredHandler);
     multiHandler.addHandler(handler);
     eventDispatchers.put(eventType, multiHandler);
   } else {
     /* already a multilistener, just add to it */
     MultiListenerHandler multiHandler = (MultiListenerHandler) registeredHandler;
     multiHandler.addHandler(handler);
   }
 }
Exemple #2
0
  /** {@link java.lang.Thread#run()} */
  @Override
  public void run() {

    while (!(isExit())) {

      try {
        log.debug("trying to take from queue...");
        EventHandler h = handlersQueue.take();
        log.debug("took from the queue. executing " + h.getClass().getSimpleName());

        h.handle();

      } catch (InterruptedException ie) {
        log.fatal("EXCEPTION: Module Interrupted " + ie.getMessage());

      } catch (ClassCastException cce) {
        log.fatal("EXCEPTION: " + cce.getMessage());
        cce.printStackTrace();
      }
    }
  }