Example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

List of usage examples for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

Introduction

In this page you can find the example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList.

Prototype

public CopyOnWriteArrayList() 

Source Link

Document

Creates an empty list.

Usage

From source file:pzalejko.iot.hardware.home.core.service.DefaultTaskExecutor.java

protected DefaultTaskExecutor(ScheduledExecutorService ex, ExecutorService cachedThreadPool) {
    this.scheduleExecutor = checkNotNull(ex);
    this.cachedThreadPool = checkNotNull(cachedThreadPool);
    tasks = new CopyOnWriteArrayList<>();
}

From source file:org.mqnaas.core.impl.slicing.UnitManagment.java

@Override
public void activate() throws ApplicationActivationException {
    log.info("Initializing UnitManagment capability for resource " + resource.getId());
    units = new CopyOnWriteArrayList<UnitResource>();
    log.info("Initialized UnitManagment capability for resource " + resource.getId());

}

From source file:Tree.java

public Tree() {
    subtrees = new CopyOnWriteArrayList<T>();
}

From source file:com.cisco.oss.foundation.message.AbstractMessageDispatcher.java

public AbstractMessageDispatcher(ConcurrentMessageHandler concurrentMessageHandler) {
    this.concurrentMessageHandler = concurrentMessageHandler;

    Configuration configuration = ConfigurationFactory.getConfiguration();
    int maxThreadPoolSize = configuration.getInt(MessageConstants.QUEUE_SIZE_PROPERTY);
    int waitingQueueSize = configuration.getInt(MessageConstants.WAITING_QUEUE_SIZE_PROPERTY);

    waitingList = new CopyOnWriteArrayList<Message>();
    try {/*from ww w .j ava 2 s  .  c  o m*/
        if (waitingQueueSize > 0) {
            blockingWaitingQueue = new CapacityEnsurableLinkedBlockingQueue<Runnable>(waitingQueueSize);
        } else {
            blockingWaitingQueue = new CapacityEnsurableLinkedBlockingQueue<Runnable>();
        }
    } catch (Exception ex) {
        LOGGER.error("Failed to create message dispatcher", ex);
    }
    executorService = new ThreadPoolExecutor(maxThreadPoolSize, maxThreadPoolSize, 0L, TimeUnit.MILLISECONDS,
            blockingWaitingQueue); //Executors.newFixedThreadPool(maxThreadPoolSize);
}

From source file:com.netflix.curator.framework.recipes.shared.TestSharedCount.java

@Test
public void testMultiClients() throws Exception {
    final int CLIENT_QTY = 5;

    List<Future<List<Integer>>> futures = Lists.newArrayList();
    final List<CuratorFramework> clients = new CopyOnWriteArrayList<CuratorFramework>();
    try {//from   w  w w .j  a  v a  2 s . co m
        final CountDownLatch startLatch = new CountDownLatch(CLIENT_QTY);
        final Semaphore semaphore = new Semaphore(0);
        ExecutorService service = Executors
                .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("Test-%d").build());
        for (int i = 0; i < CLIENT_QTY; ++i) {
            Future<List<Integer>> future = service.submit(new Callable<List<Integer>>() {
                @Override
                public List<Integer> call() throws Exception {
                    final List<Integer> countList = Lists.newArrayList();
                    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
                            new RetryOneTime(1));
                    clients.add(client);
                    client.start();

                    SharedCount count = new SharedCount(client, "/count", 10);

                    final CountDownLatch latch = new CountDownLatch(1);
                    count.addListener(new SharedCountListener() {
                        @Override
                        public void countHasChanged(SharedCountReader sharedCount, int newCount)
                                throws Exception {
                            if (newCount < 0) {
                                latch.countDown();
                            } else {
                                countList.add(newCount);
                            }

                            semaphore.release();
                        }

                        @Override
                        public void stateChanged(CuratorFramework client, ConnectionState newState) {
                        }
                    });
                    count.start();
                    startLatch.countDown();
                    latch.await();
                    return countList;
                }
            });
            futures.add(future);
        }

        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
                new RetryOneTime(1));
        clients.add(client);
        client.start();

        Assert.assertTrue(startLatch.await(10, TimeUnit.SECONDS));

        SharedCount count = new SharedCount(client, "/count", 10);
        count.start();

        List<Integer> countList = Lists.newArrayList();
        Random random = new Random();
        for (int i = 0; i < 100; ++i) {
            Thread.sleep(random.nextInt(10));

            int next = random.nextInt(100);
            countList.add(next);
            count.setCount(next);

            Assert.assertTrue(semaphore.tryAcquire(CLIENT_QTY, 10, TimeUnit.SECONDS));
        }
        count.setCount(-1);

        for (Future<List<Integer>> future : futures) {
            List<Integer> thisCountList = future.get();
            Assert.assertEquals(thisCountList, countList);
        }
    } finally {
        for (CuratorFramework client : clients) {
            IOUtils.closeQuietly(client);
        }
    }
}

From source file:com.couchbase.client.dcp.state.PartitionState.java

/**
 * Initialize a new partition state.
 */
public PartitionState() {
    failoverLog = new CopyOnWriteArrayList<FailoverLogEntry>();
}

From source file:objenome.solver.evolve.Population.java

/**
 * Constructs an empty <code>Population</code>.
 */// w ww . j  ava  2  s .  c  o  m
public Population(GPContainer config) {
    this.config = config;
    //individuals = new ArrayList<>(/*config.get(SIZE)*/);
    individuals = new CopyOnWriteArrayList();
    //new FastList().asSynchronized();
}

From source file:org.reficio.cougar.impl.MockServer.java

public MockServer() {
    this.wireFormat = new WireFormatImpl();
    this.receivedFrames = new CopyOnWriteArrayList<Frame>();

    this.typeHandlers = new HashMap<Command, IMockMessageHandler>();
    this.idHandlers = new HashMap<String, IMockMessageHandler>();
}

From source file:org.wso2.carbon.event.processor.storm.internal.stream.EventJunction.java

public EventJunction(StreamDefinition streamDefinition) {
    this.streamDefinition = streamDefinition;
    this.producers = new CopyOnWriteArrayList<EventProducer>();
    this.consumers = new CopyOnWriteArrayList<EventConsumer>();
}

From source file:org.mqnaas.network.impl.NetworkRootResourceProvider.java

@Override
public void activate() throws ApplicationActivationException {
    resources = new CopyOnWriteArrayList<IRootResource>();
}