Example usage for java.util.concurrent ConcurrentLinkedQueue ConcurrentLinkedQueue

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

Introduction

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

Prototype

public ConcurrentLinkedQueue(Collection<? extends E> c) 

Source Link

Document

Creates a ConcurrentLinkedQueue initially containing the elements of the given collection, added in traversal order of the collection's iterator.

Usage

From source file:Main.java

public static <E> Queue<E> getConcurrentLinkedQueue(Collection<? extends E> collection) {
    return new ConcurrentLinkedQueue<E>(collection);
}

From source file:Main.java

public static <E> ConcurrentLinkedQueue<E> newConcurrentLinkedQueue(final Collection<? extends E> c) {
    return new ConcurrentLinkedQueue<E>(c);
}

From source file:org.apache.streams.amazon.kinesis.KinesisPersistReader.java

public StreamsResultSet readCurrent() {

    StreamsResultSet current;/*  w w w.j a va 2s.  com*/
    synchronized (KinesisPersistReader.class) {
        current = new StreamsResultSet(new ConcurrentLinkedQueue<>(persistQueue));
        persistQueue.clear();
    }
    return current;
}

From source file:org.apache.http.HC4.impl.nio.client.PipeliningClientExchangeHandlerImpl.java

public PipeliningClientExchangeHandlerImpl(final Log log, final HttpHost target,
        final List<? extends HttpAsyncRequestProducer> requestProducers,
        final List<? extends HttpAsyncResponseConsumer<T>> responseConsumers,
        final HttpClientContext localContext, final BasicFuture<List<T>> resultFuture,
        final NHttpClientConnectionManager connmgr, final HttpProcessor httpProcessor,
        final ConnectionReuseStrategy connReuseStrategy, final ConnectionKeepAliveStrategy keepaliveStrategy) {
    super(log, localContext, resultFuture, connmgr, connReuseStrategy, keepaliveStrategy);
    Args.notNull(target, "HTTP target");
    Args.notEmpty(requestProducers, "Request producer list");
    Args.notEmpty(responseConsumers, "Response consumer list");
    Args.check(requestProducers.size() == responseConsumers.size(),
            "Number of request producers does not match that of response consumers");
    this.target = target;
    this.requestProducerQueue = new ConcurrentLinkedQueue<HttpAsyncRequestProducer>(requestProducers);
    this.responseConsumerQueue = new ConcurrentLinkedQueue<HttpAsyncResponseConsumer<T>>(responseConsumers);
    this.requestQueue = new ConcurrentLinkedQueue<HttpRequest>();
    this.resultQueue = new ConcurrentLinkedQueue<T>();
    this.localContext = localContext;
    this.resultFuture = resultFuture;
    this.httpProcessor = httpProcessor;
    this.requestProducerRef = new AtomicReference<HttpAsyncRequestProducer>(null);
    this.responseConsumerRef = new AtomicReference<HttpAsyncResponseConsumer<T>>(null);
}

From source file:cltestgrid.Upload2.java

private void saveBlobsInParallel(List<MyFileItem> items) {
    final int THREAD_COUNT = 20;

    final ConcurrentLinkedQueue<MyFileItem> tasks = new ConcurrentLinkedQueue<MyFileItem>(items);
    final CountDownLatch doneLatch = new CountDownLatch(THREAD_COUNT);

    for (int i = 0; i < THREAD_COUNT; i++) {
        ThreadManager.createThreadForCurrentRequest(new Runnable() {
            public void run() {
                MyFileItem item = null;//from   w ww. ja  va2 s . c o  m
                try {
                    while ((item = tasks.poll()) != null) {
                        try {
                            saveBlob(item.blobName, item.contentType, item.dataCollector.toByteArray());
                            // Saving blob may throw a LockException due to CloudStorage issue
                            // http://code.google.com/p/googleappengine/issues/detail?id=8592
                            // Therefore retry two times in case of LockException:
                        } catch (com.google.appengine.api.files.LockException e) {
                            try {
                                log.log(Level.WARNING, "retry saving blob " + item.blobName
                                        + " because of LockException when saving it first time", e);
                                saveBlob(item.blobName, item.contentType, item.dataCollector.toByteArray());
                            } catch (com.google.appengine.api.files.LockException e2) {
                                log.log(Level.WARNING,
                                        "second retry saving blob " + item.blobName
                                                + " because of LockException when saving it at first retry",
                                        e2);
                                saveBlob(item.blobName, item.contentType, item.dataCollector.toByteArray());
                            }
                        }
                    }
                } catch (Throwable t) {
                    if (item != null) {
                        item.saveError = t;
                    }
                    log.log(Level.SEVERE, "Error while saving blob", t);
                } finally {
                    doneLatch.countDown();
                }
            }
        }).start();
    }

    try {
        doneLatch.await();
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while saving blobs", e);
    }
}

From source file:org.apache.streams.s3.S3PersistReader.java

@Override
public StreamsResultSet readCurrent() {

    StreamsResultSet current;//from w ww. j  a va 2s.  co m

    synchronized (S3PersistReader.class) {
        current = new StreamsResultSet(new ConcurrentLinkedQueue<>(persistQueue));
        current.setCounter(new DatumStatusCounter());
        current.getCounter().add(countersCurrent);
        countersTotal.add(countersCurrent);
        countersCurrent = new DatumStatusCounter();
        persistQueue.clear();
    }
    return current;
}

From source file:org.apache.streams.facebook.provider.FacebookFriendFeedProvider.java

@Override
public StreamsResultSet readCurrent() {

    StreamsResultSet current;//from  ww  w .  ja va2s  . c om

    synchronized (FacebookUserstreamProvider.class) {
        current = new StreamsResultSet(new ConcurrentLinkedQueue<>(providerQueue));
        current.setCounter(new DatumStatusCounter());
        current.getCounter().add(countersCurrent);
        countersTotal.add(countersCurrent);
        countersCurrent = new DatumStatusCounter();
        providerQueue.clear();
    }

    return current;

}

From source file:org.apache.streams.hdfs.WebHdfsPersistReader.java

@Override
public StreamsResultSet readCurrent() {

    StreamsResultSet current;/* w w  w .  j av  a2  s.  co m*/

    synchronized (WebHdfsPersistReader.class) {
        current = new StreamsResultSet(new ConcurrentLinkedQueue<>(persistQueue));
        current.setCounter(new DatumStatusCounter());
        current.getCounter().add(countersCurrent);
        countersTotal.add(countersCurrent);
        countersCurrent = new DatumStatusCounter();
        persistQueue.clear();
    }

    return current;
}

From source file:org.jiemamy.utils.collection.CollectionsUtil.java

/**
 * {@link ConcurrentLinkedQueue}?????/*from   w ww . java 2 s  . c  o  m*/
 * 
 * @param <E> {@link ConcurrentLinkedQueue}??
 * @param c ?????
 * @return {@link ConcurrentLinkedQueue}???
 * @throws IllegalArgumentException ?{@code null}???
 * @see ConcurrentLinkedQueue#ConcurrentLinkedQueue(Collection)
 */
public static <E> ConcurrentLinkedQueue<E> newConcurrentLinkedQueue(Collection<? extends E> c) {
    Validate.notNull(c);
    return new ConcurrentLinkedQueue<E>(c);
}

From source file:io.hops.ha.common.TransactionStateImpl.java

public void addAllRanNodes(RMAppAttempt appAttempt) {
    Map<Integer, RanNode> ranNodeToPersist = new HashMap<Integer, RanNode>();
    Queue<NodeId> ranNodes = new ConcurrentLinkedQueue<NodeId>(appAttempt.getRanNodes());
    for (NodeId nid : ranNodes) {
        RanNode node = new RanNode(appAttempt.getAppAttemptId().toString(), nid.toString());
        ranNodeToPersist.put(node.hashCode(), node);
    }/*from  w w  w.  j a va2  s  .c o m*/

    this.ranNodeToAdd.put(appAttempt.getAppAttemptId(), ranNodeToPersist);
    appIds.add(appAttempt.getAppAttemptId().getApplicationId());
}