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); } }
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; } }; }
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); }