Example usage for java.util.concurrent ConcurrentLinkedQueue stream

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

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:org.apache.hadoop.hbase.client.AsyncBatchRpcRetryingCaller.java

private void groupAndSend(Stream<Action> actions, int tries) {
    long locateTimeoutNs;
    if (operationTimeoutNs > 0) {
        locateTimeoutNs = remainingTimeNs();
        if (locateTimeoutNs <= 0) {
            failAll(actions, tries);// w  ww  .ja  v  a2 s.  c o  m
            return;
        }
    } else {
        locateTimeoutNs = -1L;
    }
    ConcurrentMap<ServerName, ServerRequest> actionsByServer = new ConcurrentHashMap<>();
    ConcurrentLinkedQueue<Action> locateFailed = new ConcurrentLinkedQueue<>();
    CompletableFuture.allOf(
            actions.map(action -> conn.getLocator().getRegionLocation(tableName, action.getAction().getRow(),
                    RegionLocateType.CURRENT, locateTimeoutNs).whenComplete((loc, error) -> {
                        if (error != null) {
                            error = translateException(error);
                            if (error instanceof DoNotRetryIOException) {
                                failOne(action, tries, error, EnvironmentEdgeManager.currentTime(), "");
                                return;
                            }
                            addError(action, error, null);
                            locateFailed.add(action);
                        } else {
                            computeIfAbsent(actionsByServer, loc.getServerName(), ServerRequest::new)
                                    .addAction(loc, action);
                        }
                    })).toArray(CompletableFuture[]::new))
            .whenComplete((v, r) -> {
                if (!actionsByServer.isEmpty()) {
                    send(actionsByServer, tries);
                }
                if (!locateFailed.isEmpty()) {
                    tryResubmit(locateFailed.stream(), tries);
                }
            });
}