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:de.dfki.asr.compass.model.PrefabSet.java

public PrefabSet(final String name) {
    this.name = name;
    this.children = new CopyOnWriteArrayList<>();
    this.prefabs = new CopyOnWriteArrayList<>();
}

From source file:org.apache.stratos.autoscaler.TestObsoletedMemberRule.java

@Test
public void testOneObsoletedMemberCase() {

    // reset helper class
    TestDelegator.setObsoletedMembers(new ArrayList<String>());

    if (kbase == null) {
        throw new IllegalArgumentException("Knowledge base is null.");
    }//from w  w  w.j  av  a 2s  .  co  m
    ksession = kbase.newStatefulKnowledgeSession();
    PartitionContext p = new PartitionContext(conf.getLong("autoscaler.member.expiryTimeout", 900000));
    p.setObsoletedMembers(new CopyOnWriteArrayList<String>());
    String memberId = "member1";
    p.addObsoleteMember(memberId);
    ksession.insert(p);
    ksession.fireAllRules();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    assertEquals(1, TestDelegator.getObsoletedMembers().size());
    assertEquals(memberId, TestDelegator.getObsoletedMembers().get(0));

}

From source file:edu.temple.cis3238.wiki.vo.TopicVO.java

/**
 *
 * @param tagsCollection/*from   w w  w  .  j  a  va 2  s  . c  om*/
 */
public void setTagsCollection(CopyOnWriteArrayList<TagsVO> tagsCollection) {
    if (tagsCollection != null && !tagsCollection.isEmpty()) {
        this.tagsCollection = new CopyOnWriteArrayList<TagsVO>();
        tagsCollection.sort(new TagsVO());
        this.tagsCollection.addAll(tagsCollection);
    }
}

From source file:com.chinamobile.bcbsp.workermanager.WorkerManagerStatus.java

/**
 * Constructor.// w  ww .  ja  v  a2s  . co m
 * Init the list of StaffStatus and Fault.
 */
public WorkerManagerStatus() {
    this.staffReports = new CopyOnWriteArrayList<StaffStatus>();
    this.workerFaultList = new ArrayList<Fault>();
}

From source file:org.mybatis.spring.batch.MyBatisPagingItemReader.java

@Override
protected void doReadPage() {
    Map<String, Object> parameters = new HashMap<String, Object>();
    if (parameterValues != null) {
        parameters.putAll(parameterValues);
    }/* w  w  w .ja  va 2 s  .c o  m*/
    parameters.put("_page", getPage());
    parameters.put("_pagesize", getPageSize());
    parameters.put("_skiprows", getPage() * getPageSize());
    if (results == null) {
        results = new CopyOnWriteArrayList<T>();
    } else {
        results.clear();
    }
    results.addAll(sqlSessionTemplate.<T>selectList(queryId, parameters));
}

From source file:com.impetus.client.cassandra.service.CassandraHostConfiguration.java

protected void buildHosts(String hosts, String portAsString, List<Host> hostsList) {
    String[] hostVals = hosts.split(",");
    List<CassandraHost> cassandraHosts = new CopyOnWriteArrayList<CassandraHost>();
    for (int x = 0; x < hostVals.length; x++) {
        String host = hostVals[x].trim();
        portAsString = portAsString.trim();
        onValidation(host, portAsString);
        int port = Integer.parseInt(portAsString);
        CassandraHost cassandraHost = port == CassandraHost.DEFAULT_PORT ? new CassandraHost(host)
                : new CassandraHost(host, port);
        setConfig(cassandraHost, persistenceUnitMetadata.getProperties(), externalProperties);
        cassandraHosts.add(cassandraHost);
        hostsList.add(cassandraHost);//from   w  w  w .  j  a v a 2  s. c  om
    }
}

From source file:com.mmnaseri.dragonfly.runtime.analysis.ApplicationDesignAdvisor.java

@Override
public List<DesignIssue> analyze() {
    final List<DesignIssue> issues = new CopyOnWriteArrayList<DesignIssue>();
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from  w ww. ja v  a 2 s. c o  m*/
    log.info("Starting design advisor on " + applicationContext.getDisplayName());
    final TaskManager taskManager = new ThreadPoolTaskManager(Runtime.getRuntime().availableProcessors(), true);
    final Thread analyzerThread = new Thread(taskManager);
    final SessionPreparator sessionPreparator = applicationContext.getBean(SessionPreparator.class);
    with(getAnalyzers(sessionPreparator)).each(new Processor<ApplicationDesignAnalyzer>() {
        @Override
        public void process(ApplicationDesignAnalyzer applicationDesignAnalyzer) {
            taskManager.schedule(new AnalyzerTask(applicationDesignAnalyzer, issues));
        }
    });
    try {
        analyzerThread.start();
        analyzerThread.join();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    stopWatch.stop();
    log.info("Finished analysis of " + applicationContext.getDisplayName() + " in "
            + stopWatch.getLastTaskTimeMillis() + "ms");
    return issues;
}

From source file:com.amitupadhyay.aboutexample.ui.widget.BottomSheet.java

public void registerCallback(Callbacks callback) {
    if (callbacks == null) {
        callbacks = new CopyOnWriteArrayList<>();
    }/* w  ww .  j ava2 s.c  om*/
    callbacks.add(callback);
}

From source file:com.netflix.curator.framework.recipes.queue.TestBoundedDistributedQueue.java

@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Test//from   w  ww . ja v a2  s  .co m
public void testMulti() throws Exception {
    final String PATH = "/queue";
    final int CLIENT_QTY = 4;
    final int MAX_ITEMS = 10;
    final int ADD_ITEMS = MAX_ITEMS * 100;
    final int SLOP_FACTOR = 2;

    final QueueConsumer<String> consumer = new QueueConsumer<String>() {
        @Override
        public void consumeMessage(String message) throws Exception {
            Thread.sleep(10);
        }

        @Override
        public void stateChanged(CuratorFramework client, ConnectionState newState) {
        }
    };

    final Timing timing = new Timing();
    final ExecutorService executor = Executors.newCachedThreadPool();
    ExecutorCompletionService<Void> completionService = new ExecutorCompletionService<Void>(executor);

    final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
            timing.session(), timing.connection(), new RetryOneTime(1));
    try {
        client.start();
        client.create().forPath(PATH);

        final CountDownLatch isWaitingLatch = new CountDownLatch(1);
        final AtomicBoolean isDone = new AtomicBoolean(false);
        final List<Integer> counts = new CopyOnWriteArrayList<Integer>();
        final Object lock = new Object();
        executor.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                Watcher watcher = new Watcher() {
                    @Override
                    public void process(WatchedEvent event) {
                        synchronized (lock) {
                            lock.notifyAll();
                        }
                    }
                };

                while (!Thread.currentThread().isInterrupted() && client.isStarted() && !isDone.get()) {
                    synchronized (lock) {
                        int size = client.getChildren().usingWatcher(watcher).forPath(PATH).size();
                        counts.add(size);
                        isWaitingLatch.countDown();
                        lock.wait();
                    }
                }
                return null;
            }
        });
        isWaitingLatch.await();

        for (int i = 0; i < CLIENT_QTY; ++i) {
            final int index = i;
            completionService.submit(new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    CuratorFramework client = null;
                    DistributedQueue<String> queue = null;

                    try {
                        client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(),
                                timing.connection(), new RetryOneTime(1));
                        client.start();
                        queue = QueueBuilder.builder(client, consumer, serializer, PATH).executor(executor)
                                .maxItems(MAX_ITEMS).putInBackground(false).lockPath("/locks").buildQueue();
                        queue.start();

                        for (int i = 0; i < ADD_ITEMS; ++i) {
                            queue.put("" + index + "-" + i);
                        }
                    } finally {
                        IOUtils.closeQuietly(queue);
                        IOUtils.closeQuietly(client);
                    }
                    return null;
                }
            });
        }

        for (int i = 0; i < CLIENT_QTY; ++i) {
            completionService.take().get();
        }

        isDone.set(true);
        synchronized (lock) {
            lock.notifyAll();
        }

        for (int count : counts) {
            Assert.assertTrue(counts.toString(), count <= (MAX_ITEMS * SLOP_FACTOR));
        }
    } finally {
        executor.shutdownNow();
        IOUtils.closeQuietly(client);
    }
}

From source file:org.mule.tck.functional.FunctionalTestComponent.java

@Override
public void initialise() {
    if (enableMessageHistory) {
        messageHistory = new CopyOnWriteArrayList<Object>();
    }//w w w .ja  va2s . com
    for (LifecycleCallback callback : lifecycleCallbacks) {
        callback.onTransition(id, Initialisable.PHASE_NAME);
    }
}