Example usage for java.util.concurrent CopyOnWriteArraySet remove

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

Introduction

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

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the specified element from this set if it is present.

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//  ww  w. j  a  va2  s. c o m
 */
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);
        }
    });
}