@Override
  public <ET extends Event> void push(ET event) {
    List<Subscriber<ET>> subscribers;

    synchronized (registeredSubscribers) {
      if (!registeredSubscribers.containsKey(event.getClass())) return;

      // Inspection disabled because all inserts in to registeredSubscribers are type insured
      // due to type erasure, we can not have per-pair types.
      // noinspection unchecked
      subscribers =
          (List<Subscriber<ET>>) new ArrayList(registeredSubscribers.get(event.getClass()));
    }

    for (Subscriber<ET> subscriber : subscribers) {
      boolean txDeterminate = true;
      for (ListenerFilter filter : subscriber.getFilters()) {
        // This can only occur if someone f***s something up in an annotation, as listeners should
        // be typesafe when passed to subscribers
        // noinspection unchecked
        txDeterminate = txDeterminate && filter.shouldSend(event);
      }

      if (txDeterminate) subscriber.eventReceived(event);
    }
  }
Beispiel #2
0
 /** Factory method for constructing resolver that maps from Enum.toString() into Enum value */
 public static <ET extends Enum<ET>> EnumResolver<ET> constructUsingToString(Class<ET> enumCls) {
   ET[] enumValues = enumCls.getEnumConstants();
   HashMap<String, ET> map = new HashMap<String, ET>();
   // from last to first, so that in case of duplicate values, first wins
   for (int i = enumValues.length; --i >= 0; ) {
     ET e = enumValues[i];
     map.put(e.toString(), e);
   }
   return new EnumResolver<ET>(enumCls, enumValues, map);
 }