Example usage for com.google.common.collect Sets newCopyOnWriteArraySet

List of usage examples for com.google.common.collect Sets newCopyOnWriteArraySet

Introduction

In this page you can find the example usage for com.google.common.collect Sets newCopyOnWriteArraySet.

Prototype

@GwtIncompatible("CopyOnWriteArraySet")
public static <E> CopyOnWriteArraySet<E> newCopyOnWriteArraySet() 

Source Link

Document

Creates an empty CopyOnWriteArraySet instance.

Usage

From source file:co.cask.cdap.watchdog.election.MultiLeaderElection.java

public MultiLeaderElection(ZKClient zkClient, String name, int partitionSize, PartitionChangeHandler handler) {
    this.zkClient = zkClient;
    this.name = name;
    this.partitionSize = partitionSize;
    this.handler = handler;

    this.executor = Executors
            .newSingleThreadExecutor(Threads.createDaemonThreadFactory("multi-leader-election"));
    this.leaderPartitions = Sets.newCopyOnWriteArraySet();
    this.electionCancels = Lists.newArrayList();
    this.prevLeaderPartitions = ImmutableSet.of();
    this.stopLatch = new CountDownLatch(1);
}

From source file:co.cask.cdap.internal.app.runtime.service.InMemoryTwillContext.java

InMemoryTwillContext(RunId runId, RunId applicationRunId, InetAddress host, String[] arguments,
        String[] applicationArguments, TwillRunnableSpecification specification, int instanceId,
        int virtualCores, int maxMemoryMB, DiscoveryServiceClient discoveryServiceClient,
        DiscoveryService discoveryService, int instanceCount, InMemoryElectionRegistry electionRegistry) {
    this.runId = runId;
    this.applicationRunId = applicationRunId;
    this.host = host;
    this.arguments = arguments;
    this.applicationArguments = applicationArguments;
    this.specification = specification;
    this.instanceId = instanceId;
    this.virtualCores = virtualCores;
    this.maxMemoryMB = maxMemoryMB;
    this.discoveryServiceClient = discoveryServiceClient;
    this.discoveryService = discoveryService;
    this.instanceCount = instanceCount;
    this.electionRegistry = electionRegistry;
    this.electionCancels = Sets.newCopyOnWriteArraySet();
}

From source file:silentium.gameserver.model.actor.status.CharStatus.java

/**
 * Return the list of L2Character that must be informed of HP/MP updates of this L2Character.<BR>
 * <BR>/*w  ww  .  j  a v  a2 s  . com*/
 * <B><U> Concept</U> :</B><BR>
 * <BR>
 * Each L2Character owns a list called <B>_statusListener</B> that contains all L2PcInstance to inform of HP/MP updates. Players who must be
 * informed are players that target this L2Character. When a RegenTask is in progress sever just need to go through this list to send
 * Server->Client packet StatusUpdate.<BR>
 * <BR>
 * 
 * @return The list of L2Character to inform or null if empty
 */
public final Set<L2Character> getStatusListener() {
    if (_StatusListener == null)
        _StatusListener = Sets.newCopyOnWriteArraySet();

    return _StatusListener;
}

From source file:io.atomix.core.election.impl.LeaderElectorProxy.java

@Override
public synchronized CompletableFuture<Void> addListener(String topic,
        LeadershipEventListener<byte[]> listener) {
    boolean empty = topicListeners.isEmpty();
    topicListeners.compute(topic, (t, s) -> {
        if (s == null) {
            s = Sets.newCopyOnWriteArraySet();
        }/*from   w w w .j  a va2s.  c  o  m*/
        s.add(listener);
        return s;
    });

    if (empty) {
        return getProxyClient().acceptBy(topic, service -> service.listen());
    }
    return CompletableFuture.completedFuture(null);
}

From source file:org.apache.twill.internal.kafka.client.ZKBrokerService.java

public ZKBrokerService(ZKClient zkClient) {
    this.zkClient = zkClient;
    this.brokerInfos = CacheBuilder.newBuilder().build(createCacheLoader(new CacheInvalidater<BrokerId>() {
        @Override/*from  ww w .  j a  va  2  s .c  o  m*/
        public void invalidate(BrokerId key) {
            brokerInfos.invalidate(key);
        }
    }, BrokerInfo.class));
    this.partitionInfos = CacheBuilder.newBuilder()
            .build(createCacheLoader(new CacheInvalidater<KeyPathTopicPartition>() {
                @Override
                public void invalidate(KeyPathTopicPartition key) {
                    partitionInfos.invalidate(key);
                }
            }, PartitionInfo.class));

    // Use CopyOnWriteArraySet so that it's thread safe and order of listener is maintain as the insertion order.
    this.listeners = Sets.newCopyOnWriteArraySet();
}

From source file:io.atomix.cluster.messaging.impl.NettyBroadcastService.java

@Override
public synchronized void addListener(String subject, Consumer<byte[]> listener) {
    listeners.computeIfAbsent(subject, s -> Sets.newCopyOnWriteArraySet()).add(listener);
}