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


Java CopyOnWriteArraySet类代码示例

本文整理汇总了Java中java.util.concurrent.CopyOnWriteArraySet的典型用法代码示例。如果您正苦于以下问题:Java CopyOnWriteArraySet类的具体用法?Java CopyOnWriteArraySet怎么用?Java CopyOnWriteArraySet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CopyOnWriteArraySet类属于java.util.concurrent包,在下文中一共展示了CopyOnWriteArraySet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: equalsAndHashCode

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
@Test public void equalsAndHashCode() throws Exception {
  ConnectionSpec allCipherSuites = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
      .allEnabledCipherSuites()
      .build();
  ConnectionSpec allTlsVersions = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
      .allEnabledTlsVersions()
      .build();

  Set<Object> set = new CopyOnWriteArraySet<>();
  assertTrue(set.add(ConnectionSpec.MODERN_TLS));
  assertTrue(set.add(ConnectionSpec.COMPATIBLE_TLS));
  assertTrue(set.add(ConnectionSpec.CLEARTEXT));
  assertTrue(set.add(allTlsVersions));
  assertTrue(set.add(allCipherSuites));

  assertTrue(set.remove(ConnectionSpec.MODERN_TLS));
  assertTrue(set.remove(ConnectionSpec.COMPATIBLE_TLS));
  assertTrue(set.remove(ConnectionSpec.CLEARTEXT));
  assertTrue(set.remove(allTlsVersions));
  assertTrue(set.remove(allCipherSuites));
  assertTrue(set.isEmpty());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:ConnectionSpecTest.java

示例2: addSessionChangerListener

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
private void addSessionChangerListener(SessionChanger sc) {
    Set<String> actions = sc.getActions();
    synchronized (sessionChangers) {
        for (String action : actions) {
            Set<SessionChanger> scs = sessionChangers.get(action);
            if (scs == null) {
                sessionChangers.put(action, Collections.singleton(sc));
            } else {
                if (scs.size() == 1) {
                    SessionChanger old = scs.iterator().next();
                    scs = new CopyOnWriteArraySet<SessionChanger>();
                    scs.add(old);
                }
                scs.add(sc);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:SessionBridge.java

示例3: start

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
@Override
public void start() {
    if (!started) {
        startLock.lock();
        try {
            if (!started) {
                this.eventKey = KEY_PREFIX + UUID.randomUUID().toString().replace("-", "").toLowerCase();
                this.segmentMap = new ConcurrentHashMap<>();
                this.statusMap = new ConcurrentHashMap<>();
                this.brokenServerSet = new CopyOnWriteArraySet<>();
                this.commandQueue = new LinkedBlockingQueue<>();
                this.halfOpenLockMap = new ConcurrentHashMap<>(64);
                this.registerEvent();
                this.startTask();
                started = true;
            }
        } finally {
            startLock.unlock();
        }
    }
}
 
开发者ID:darren-fu,项目名称:RestyPass,代码行数:22,代码来源:DefaultCircuitBreaker.java

示例4: ExoPlayerImpl

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
/**
 * Constructs an instance. Must be invoked from a thread that has an associated {@link Looper}.
 *
 * @param rendererCount The number of {@link TrackRenderer}s that will be passed to
 *     {@link #prepare(TrackRenderer[])}.
 * @param minBufferMs A minimum duration of data that must be buffered for playback to start
 *     or resume following a user action such as a seek.
 * @param minRebufferMs A minimum duration of data that must be buffered for playback to resume
 *     after a player invoked rebuffer (i.e. a rebuffer that occurs due to buffer depletion, and
 *     not due to a user action such as starting playback or seeking).
 */
@SuppressLint("HandlerLeak")
public ExoPlayerImpl(int rendererCount, int minBufferMs, int minRebufferMs) {
  Log.i(TAG, "Init " + ExoPlayerLibraryInfo.VERSION);
  this.playWhenReady = false;
  this.playbackState = STATE_IDLE;
  this.listeners = new CopyOnWriteArraySet<>();
  this.trackFormats = new MediaFormat[rendererCount][];
  this.selectedTrackIndices = new int[rendererCount];
  eventHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
      ExoPlayerImpl.this.handleEvent(msg);
    }
  };
  internalPlayer = new ExoPlayerImplInternal(eventHandler, playWhenReady, selectedTrackIndices,
      minBufferMs, minRebufferMs);
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:29,代码来源:ExoPlayerImpl.java

示例5: register

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
/**
 * Registers all subscriber methods on the given listener object.
 */
void register(Object listener) {
  Multimap<Class<?>, Subscriber> listenerMethods = findAllSubscribers(listener);

  for (Map.Entry<Class<?>, Collection<Subscriber>> entry : listenerMethods.asMap().entrySet()) {
    Class<?> eventType = entry.getKey();
    Collection<Subscriber> eventMethodsInListener = entry.getValue();

    CopyOnWriteArraySet<Subscriber> eventSubscribers = subscribers.get(eventType);

    if (eventSubscribers == null) {
      CopyOnWriteArraySet<Subscriber> newSet = new CopyOnWriteArraySet<Subscriber>();
      eventSubscribers =
          MoreObjects.firstNonNull(subscribers.putIfAbsent(eventType, newSet), newSet);
    }

    eventSubscribers.addAll(eventMethodsInListener);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:22,代码来源:SubscriberRegistry.java

示例6: 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

示例7: getSubscribers

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
/**
 * Gets an iterator representing an immutable snapshot of all subscribers to the given event at
 * the time this method is called.
 */
Iterator<Subscriber> getSubscribers(Object event) {
  ImmutableSet<Class<?>> eventTypes = flattenHierarchy(event.getClass());

  List<Iterator<Subscriber>> subscriberIterators =
      Lists.newArrayListWithCapacity(eventTypes.size());

  for (Class<?> eventType : eventTypes) {
    CopyOnWriteArraySet<Subscriber> eventSubscribers = subscribers.get(eventType);
    if (eventSubscribers != null) {
      // eager no-copy snapshot
      subscriberIterators.add(eventSubscribers.iterator());
    }
  }

  return Iterators.concat(subscriberIterators.iterator());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:21,代码来源:SubscriberRegistry.java

示例8: testsForCopyOnWriteArraySet

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
public Test testsForCopyOnWriteArraySet() {
  return SetTestSuiteBuilder.using(
          new TestStringSetGenerator() {
            @Override
            public Set<String> create(String[] elements) {
              return new CopyOnWriteArraySet<String>(MinimalCollection.of(elements));
            }
          })
      .named("CopyOnWriteArraySet")
      .withFeatures(
          CollectionFeature.SUPPORTS_ADD,
          CollectionFeature.SUPPORTS_REMOVE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.KNOWN_ORDER,
          CollectionSize.ANY)
      .suppressing(suppressForCopyOnWriteArraySet())
      .createTestSuite();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:TestsForSetsInJavaUtil.java

示例9: SIPClientTransactionImpl

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
/**
 * Creates a new client transaction.
 * 
 * @param newSIPStack Transaction stack this transaction belongs to.
 * @param newChannelToUse Channel to encapsulate.
 * @return the created client transaction.
 */
protected SIPClientTransactionImpl(SIPTransactionStack newSIPStack, MessageChannel newChannelToUse)
{
  super(newSIPStack, newChannelToUse);
  // Create a random branch parameter for this transaction
  setBranch(Utils.getInstance().generateBranchId());
  this.setEncapsulatedChannel(newChannelToUse);
  this.notifyOnRetransmit = false;
  this.timeoutIfStillInCallingState = false;

  if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
    logger.logDebug("Creating clientTransaction " + this);
    logger.logStackTrace();
  }
  // this.startTransactionTimer();
  this.sipDialogs = new CopyOnWriteArraySet<String>();
}
 
开发者ID:YunlongYang,项目名称:LightSIP,代码行数:24,代码来源:SIPClientTransactionImpl.java

示例10: addRoute

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
public synchronized HostTable addRoute(H host, String virtualHost, String contextPath) {
    Set<Target> hostData = hosts.get(host);
    if(hostData == null) {
        throw UndertowMessages.MESSAGES.hostHasNotBeenRegistered(host);
    }
    hostData.add(new Target(virtualHost, contextPath));
    PathMatcher<Set<H>> paths = targets.get(virtualHost);
    if(paths == null) {
        paths = new PathMatcher<>();
        targets.put(virtualHost, paths);
    }
    Set<H> hostSet = paths.getPrefixPath(contextPath);
    if(hostSet == null) {
        hostSet = new CopyOnWriteArraySet<>();
        paths.addPrefixPath(contextPath, hostSet);
    }
    hostSet.add(host);
    return this;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:HostTable.java

示例11: PendingQuery

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
PendingQuery(
        String dataType,
        byte[] queryMessage,
        long timeoutInMs,
        QueryCallback queryCallback) {
    mDataType = dataType;
    mQueryMessage = queryMessage;
    mTimeoutInMs = timeoutInMs;

    mRespondersById = buildRespondersById();
    mPendingResponses = new CopyOnWriteArraySet<>();
    for (long responderId : mRespondersById.keySet()) {
        mPendingResponses.add(responderId);
    }
    mResponses = new ConcurrentHashMap<>();
    mQueryCallback = queryCallback;
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:18,代码来源:BroadcastQueryClient.java

示例12: addProxyToRepository

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
/**
 * Add the {@link ProxyInfo} into repository for future quick access
 * 
 * @param member Distributed Member
 * @param proxyInfo Proxy Info instance
 */
protected void addProxyToRepository(DistributedMember member, ProxyInfo proxyInfo) {
  ObjectName objectName = proxyInfo.getObjectName();
  if (logger.isTraceEnabled()) {
    logger.trace("ADDED TO PROXY REPO : {}", proxyInfo.getObjectName());
  }

  objectNameIndex.put(objectName, proxyInfo);
  if (memberIndex.get(member) != null) {
    memberIndex.get(member).add(proxyInfo.getObjectName());
  } else {
    Set<ObjectName> proxyInfoSet = new CopyOnWriteArraySet<ObjectName>();
    proxyInfoSet.add(proxyInfo.getObjectName());
    memberIndex.put(member, proxyInfoSet);
  }

}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:MBeanProxyInfoRepository.java

示例13: addClientPartitionAdvisor

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
private void addClientPartitionAdvisor(String regionFullPath, ClientPartitionAdvisor advisor) {
  if (this.cache.isClosed() || this.clientPRAdvisors == null) {
    return;
  }
  try {
    this.clientPRAdvisors.put(regionFullPath, advisor);
    if (advisor.getColocatedWith() != null) {
      String parentRegionPath = advisor.getColocatedWith();
      Set<ClientPartitionAdvisor> colocatedAdvisors =
          this.colocatedPRAdvisors.get(parentRegionPath);
      if (colocatedAdvisors == null) {
        colocatedAdvisors = new CopyOnWriteArraySet<ClientPartitionAdvisor>();
        this.colocatedPRAdvisors.put(parentRegionPath, colocatedAdvisors);
      }
      colocatedAdvisors.add(advisor);
    }
  } catch (Exception npe) {
    // ignore, shutdown case
  }

}
 
开发者ID:ampool,项目名称:monarch,代码行数:22,代码来源:ClientMetadataService.java

示例14: addGatewaySenderId

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
public void addGatewaySenderId(String gatewaySenderId) {
  if (this.gatewaySenderIds == null) {
    this.gatewaySenderIds = new CopyOnWriteArraySet<String>();
    this.gatewaySenderIds.add(gatewaySenderId);
  } else {
    synchronized (this.gatewaySenderIds) { // TODO: revisit this
      // synchronization : added as per
      // above code
      if (this.gatewaySenderIds.contains(gatewaySenderId)) {
        throw new IllegalArgumentException(
            LocalizedStrings.AttributesFactory_GATEWAY_SENDER_ID_0_IS_ALREADY_ADDED
                .toLocalizedString(gatewaySenderId));
      }
      this.gatewaySenderIds.add(gatewaySenderId);
    }
  }
  setHasGatewaySenderIds(true);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:19,代码来源:AttributesFactory.java

示例15: addAsyncEventQueueId

import java.util.concurrent.CopyOnWriteArraySet; //导入依赖的package包/类
public void addAsyncEventQueueId(String asyncEventQueueId) {
  if (this.asyncEventQueueIds == null) {
    this.asyncEventQueueIds = new CopyOnWriteArraySet<String>();
    this.asyncEventQueueIds.add(asyncEventQueueId);
  } else {
    synchronized (this.asyncEventQueueIds) { // TODO: revisit this
      // synchronization : added as per
      // above code
      if (this.asyncEventQueueIds.contains(asyncEventQueueId)) {
        throw new IllegalArgumentException(
            LocalizedStrings.AttributesFactory_ASYNC_EVENT_QUEUE_ID_0_IS_ALREADY_ADDED
                .toLocalizedString(asyncEventQueueId));
      }
      this.asyncEventQueueIds.add(asyncEventQueueId);
    }
  }
  setHasAsyncEventListeners(true);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:19,代码来源:AttributesFactory.java


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