Ejemplo n.º 1
0
 void removeSubscriber(Subscriber<E> subscriber) {
   for (Subscription<E> subscription : subscriptions)
     if (subscription.getSubscriber().equals(subscriber)) {
       subscriptions.remove(subscription);
       for (Map.Entry<Topic, SubscriptionList<E>> entry : mappedSubscriptions.entrySet())
         if (subscription.getTopicMatcher().matches(entry.getKey()))
           entry.getValue().remove(subscription);
     }
 }
Ejemplo n.º 2
0
  Iterator<Subscription<E>> getSubscriptions(final Event<E> event) {
    final Topic topic = event.getTopic();
    SubscriptionList<E> subscriptionList = mappedSubscriptions.get(topic);
    if (subscriptionList == null) {
      subscriptionList = new SubscriptionList<E>();
      for (Subscription<E> subscription : this.subscriptions)
        if (subscription.getTopicMatcher().matches(topic)) subscriptionList.add(subscription);
      final SubscriptionList<E> old = mappedSubscriptions.putIfAbsent(topic, subscriptionList);
      if (old != null) subscriptionList = old;
    }
    return new FilterIterator<Subscription<E>, Subscription<E>>(subscriptionList.iterator()) {
      final Class<?> eventType = event.getSource().getClass();

      @Override
      protected Subscription<E> filter(Subscription<E> subscription) {
        return subscription.getEventType().isAssignableFrom(eventType) ? subscription : null;
      }
    };
  }
Ejemplo n.º 3
0
 void addSubscription(Subscription<E> subscription) {
   subscriptions.add(subscription);
   for (Map.Entry<Topic, SubscriptionList<E>> entry : mappedSubscriptions.entrySet())
     if (subscription.getTopicMatcher().matches(entry.getKey()))
       entry.getValue().add(subscription);
 }