本文整理汇总了Java中java.util.concurrent.CopyOnWriteArraySet.removeAll方法的典型用法代码示例。如果您正苦于以下问题:Java CopyOnWriteArraySet.removeAll方法的具体用法?Java CopyOnWriteArraySet.removeAll怎么用?Java CopyOnWriteArraySet.removeAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.CopyOnWriteArraySet
的用法示例。
在下文中一共展示了CopyOnWriteArraySet.removeAll方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unregister
import java.util.concurrent.CopyOnWriteArraySet; //导入方法依赖的package包/类
/**
* Unregisters all subscribers on the given listener object.
*/
void unregister(Object listener) {
Multimap<Class<?>, Subscriber> listenerMethods = findAllSubscribers(listener);
for (Map.Entry<Class<?>, Collection<Subscriber>> entry : listenerMethods.asMap().entrySet()) {
Class<?> eventType = entry.getKey();
Collection<Subscriber> listenerMethodsForType = entry.getValue();
CopyOnWriteArraySet<Subscriber> currentSubscribers = subscribers.get(eventType);
if (currentSubscribers == null || !currentSubscribers.removeAll(listenerMethodsForType)) {
// if removeAll returns true, all we really know is that at least one subscriber was
// removed... however, barring something very strange we can assume that if at least one
// subscriber was removed, all subscribers on listener for that event type were... after
// all, the definition of subscribers on a particular class is totally static
throw new IllegalArgumentException(
"missing event subscriber for an annotated method. Is " + listener + " registered?");
}
// don't try to remove the set if it's empty; that can't be done safely without a lock
// anyway, if the set is empty it'll just be wrapping an array of length 0
}
}
示例2: unregister
import java.util.concurrent.CopyOnWriteArraySet; //导入方法依赖的package包/类
/**
* Unregisters all subscribers on the given listener object.
*/
void unregister(Object listener) {
Multimap<Class<?>, Subscriber> listenerMethods = findAllSubscribers(listener);
for (Map.Entry<Class<?>, Collection<Subscriber>> entry : listenerMethods.asMap().entrySet()) {
Class<?> eventType = entry.getKey();
Collection<Subscriber> listenerMethodsForType = entry.getValue();
CopyOnWriteArraySet<Subscriber> currentSubscribers = subscribers.get(eventType);
if (currentSubscribers == null
|| !currentSubscribers.removeAll(listenerMethodsForType)) {
// if removeAll returns true, all we really know is that at least one subscriber was
// removed... however, barring something very strange we can assume that if at least one
// subscriber was removed, all subscribers on listener for that event type were... after
// all, the definition of subscribers on a particular class is totally static
throw new IllegalArgumentException("missing event subscriber for an annotated method. Is " + listener
+ " registered?");
}
// don't try to remove the set if it's empty; that can't be done safely without a lock
// anyway, if the set is empty it'll just be wrapping an array of length 0
}
}
示例3: unregister
import java.util.concurrent.CopyOnWriteArraySet; //导入方法依赖的package包/类
/**
* Unregisters all subscribers on the given listener object.
*/
void unregister(Object listener) {
Multimap<Class<?>, Subscriber> listenerMethods = findAllSubscribers(listener);
for (Map.Entry<Class<?>, Collection<Subscriber>> entry : listenerMethods.asMap().entrySet()) {
Class<?> eventType = entry.getKey();
Collection<Subscriber> listenerMethodsForType = entry.getValue();
CopyOnWriteArraySet<Subscriber> currentSubscribers = subscribers.get(eventType);
if (currentSubscribers == null
|| !currentSubscribers.removeAll(listenerMethodsForType)) {
// if removeAll returns true, all we really know is that at least one subscriber was
// removed... however, barring something very strange we can assume that if at least one
// subscriber was removed, all subscribers on listener for that event type were... after
// all, the definition of subscribers on a particular class is totally static
throw new IllegalArgumentException(
"missing event subscriber for an annotated method. Is " + listener
+ " registered?");
}
// don't try to remove the set if it's empty; that can't be done safely without a lock
// anyway, if the set is empty it'll just be wrapping an array of length 0
}
}
示例4: unregister
import java.util.concurrent.CopyOnWriteArraySet; //导入方法依赖的package包/类
/**
* Unregisters all subscribers on the given listener object.
*/
void unregister(Object listener) {
Multimap<Class<?>, Subscriber> listenerMethods = findAllSubscribers(listener);
for (Map.Entry<Class<?>, Collection<Subscriber>> entry : listenerMethods.asMap().entrySet()) {
Class<?> eventType = entry.getKey();
Collection<Subscriber> listenerMethodsForType = entry.getValue();
CopyOnWriteArraySet<Subscriber> currentSubscribers = subscribers.get(eventType);
if (currentSubscribers == null
|| !currentSubscribers.removeAll(listenerMethodsForType)) {
// if removeAll returns true, all we really know is that at least one subscriber was
// removed... however, barring something very strange we can assume that if at least one
// subscriber was removed, all subscribers on listener for that event type were... after
// all, the definition of subscribers on a particular class is totally static
throw new IllegalArgumentException("missing event subscriber for an annotated method. Is " + listener
+ " registered?");
}
// don't try to remove the set if it's empty; that can't be done safely without a lock
// anyway, if the set is empty it'll just be wrapping an array of length 0
}
}
示例5: unregister
import java.util.concurrent.CopyOnWriteArraySet; //导入方法依赖的package包/类
/**
* Unregisters all methods that annotated by {@link Subscribe}.
*/
void unregister(Object listener) {
Map<Class<?>, Set<Subscriber>> allSubscribers = findAllSubscribers(listener);
for (Map.Entry<Class<?>, Set<Subscriber>> entry : allSubscribers.entrySet()) {
Class<?> eventType = entry.getKey();
CopyOnWriteArraySet<Subscriber> currentSubscribers = this.subscribers.get(eventType);
if (currentSubscribers == null || !currentSubscribers.removeAll(entry.getValue())) {
throw new IllegalArgumentException("missing event subscriber in " + listener);
}
}
}
示例6: unregister
import java.util.concurrent.CopyOnWriteArraySet; //导入方法依赖的package包/类
/**
* Unregister all event handler methods for a subscriber.
* By the way this method also removes all subscribers that was already garbage collected.
*
* @param subscriber a @Nullable object whose event handlers methods should be unregistered.
* Pass null to remove old, already garbage collected objects.
*/
public void unregister(@Nullable Object subscriber) {
List<EventHandler> eventHandlersToRemove = new ArrayList<>();
//NOTE: mRegisteredEventHandlersByEventType is a concurrent map, reads are permitted without synchronisation.
//this method does not modify the mRegisteredEventHandlersByEventType, it modify only its values, sets of eventHandlers.
for (CopyOnWriteArraySet<EventHandler> eventHandlers : mRegisteredEventHandlersByEventType.values()) {
for (EventHandler eventHandler : eventHandlers) {
Object eventHandlerSubscriber = eventHandler.mSubscriber.get();
//Note: if the eventHandlerSubscriber is null, it means that object was GCed,
//so it should be unregistered too.
if (eventHandlerSubscriber == null || eventHandlerSubscriber == subscriber) {
//Note: the eventHandlers is a CopyOnWriteArraySet, it is much better performance-wise
//to remove all handlers in one steep, at the end of loop.
eventHandlersToRemove.add(eventHandler);
}
}
eventHandlers.removeAll(eventHandlersToRemove);
eventHandlersToRemove.clear();
}
//remove related default thread handler
for (IdentityWeakReferenceKey<Object> key : mSubscribersDefaultThreads.keySet()) {
Object ref = key.get();
//Note: if the ref is null, it means that object was GCed,
//so it should be removed too.
if (ref == null || ref == subscriber) {
mSubscribersDefaultThreads.remove(key);
}
}
}