Example usage for java.util.concurrent CopyOnWriteArraySet forEach

List of usage examples for java.util.concurrent CopyOnWriteArraySet forEach

Introduction

In this page you can find the example usage for java.util.concurrent CopyOnWriteArraySet forEach.

Prototype

public void forEach(Consumer<? super E> action) 

Source Link

Usage

From source file:com.devicehive.eventbus.SubscriberRegistry.java

/**
 * Unregisters subscriber from registry maps:
 *  - gets all subscriber's subscriptions from {@link SubscriberRegistry#subscriberSubscriptions}
 *  - removes subscriber from each subscription's list in {@link SubscriberRegistry#subscriptions}
 *  - removes entry from {@link SubscriberRegistry#subscriberSubscriptions}
 *
 * @param subscriber - subscriber//w  w  w .j a  va2 s.  c  om
 */
void unregister(Subscriber subscriber) {
    CopyOnWriteArraySet<Subscription> subs = subscriberSubscriptions.getOrDefault(subscriber.getId(),
            new CopyOnWriteArraySet<>());
    subs.forEach(s -> {
        CopyOnWriteArraySet<Subscriber> subscribers = this.subscriptions.get(s);
        if (subscribers != null) {
            subscribers.remove(subscriber);
        }
    });
}