当前位置: 首页>>代码示例>>Java>>正文


Java CopyOnWriteArraySet.removeAll方法代码示例

本文整理汇总了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
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:25,代码来源:SubscriberRegistry.java

示例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
    }
  }
 
开发者ID:antlr,项目名称:codebuff,代码行数:25,代码来源:SubscriberRegistry.java

示例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
  }
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:26,代码来源:SubscriberRegistry.java

示例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
  }
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:25,代码来源:SubscriberRegistry.java

示例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);
    }
  }
}
 
开发者ID:BiaoWu,项目名称:Broadcast,代码行数:16,代码来源:SubscriberRegistry.java

示例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);
        }
    }
}
 
开发者ID:PGSSoft,项目名称:gimBUS,代码行数:38,代码来源:EventBus.java


注:本文中的java.util.concurrent.CopyOnWriteArraySet.removeAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。