當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。