Example usage for java.lang Iterable forEach

List of usage examples for java.lang Iterable forEach

Introduction

In this page you can find the example usage for java.lang Iterable forEach.

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

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

private void addError(Iterable<Action> actions, Throwable error, ServerName serverName) {
    actions.forEach(action -> addError(action, error, serverName));
}

From source file:org.apache.pulsar.client.impl.ConsumerImpl.java

@Override
public void redeliverUnacknowledgedMessages(Set<MessageId> messageIds) {
    checkArgument(messageIds.stream().findFirst().get() instanceof MessageIdImpl);

    if (conf.getSubscriptionType() != SubscriptionType.Shared) {
        // We cannot redeliver single messages if subscription type is not Shared
        redeliverUnacknowledgedMessages();
        return;//from  w  ww.  j av a  2  s  . c  o m
    }
    ClientCnx cnx = cnx();
    if (isConnected() && cnx.getRemoteEndpointProtocolVersion() >= ProtocolVersion.v2.getNumber()) {
        int messagesFromQueue = removeExpiredMessagesFromQueue(messageIds);
        Iterable<List<MessageIdImpl>> batches = Iterables.partition(
                messageIds.stream().map(messageId -> (MessageIdImpl) messageId).collect(Collectors.toSet()),
                MAX_REDELIVER_UNACKNOWLEDGED);
        MessageIdData.Builder builder = MessageIdData.newBuilder();
        batches.forEach(ids -> {
            List<MessageIdData> messageIdDatas = ids.stream().map(messageId -> {
                // process message possible to dead letter topic
                processPossibleToDLQ(messageId);
                // attempt to remove message from batchMessageAckTracker
                builder.setPartition(messageId.getPartitionIndex());
                builder.setLedgerId(messageId.getLedgerId());
                builder.setEntryId(messageId.getEntryId());
                return builder.build();
            }).collect(Collectors.toList());
            ByteBuf cmd = Commands.newRedeliverUnacknowledgedMessages(consumerId, messageIdDatas);
            cnx.ctx().writeAndFlush(cmd, cnx.ctx().voidPromise());
            messageIdDatas.forEach(MessageIdData::recycle);
        });
        if (messagesFromQueue > 0) {
            increaseAvailablePermits(cnx, messagesFromQueue);
        }
        builder.recycle();
        if (log.isDebugEnabled()) {
            log.debug("[{}] [{}] [{}] Redeliver unacked messages and increase {} permits", subscription, topic,
                    consumerName, messagesFromQueue);
        }
        return;
    }
    if (cnx == null || (getState() == State.Connecting)) {
        log.warn("[{}] Client Connection needs to be established for redelivery of unacknowledged messages",
                this);
    } else {
        log.warn("[{}] Reconnecting the client to redeliver the messages.", this);
        cnx.ctx().close();
    }
}

From source file:org.ballerinalang.composer.service.fs.LocalFileSystem.java

@Override
public JsonArray listRoots(List<String> extensionList) throws IOException {
    final Iterable<Path> rootDirs = FileSystems.getDefault().getRootDirectories();
    List<Path> rootDirsList = new ArrayList<>();
    rootDirs.forEach(rootDirsList::add);
    return getJsonArrayForDirs(rootDirsList, extensionList);
}

From source file:org.ballerinalang.composer.service.workspace.local.LocalFSWorkspace.java

@Override
public JsonArray listRoots() throws IOException {
    final Iterable<Path> rootDirs = FileSystems.getDefault().getRootDirectories();
    List<Path> rootDirsList = new ArrayList<>();
    rootDirs.forEach(rootDirsList::add);
    return getJsonArrayForDirs(rootDirsList);
}

From source file:org.bonej.wrapperPlugins.FractalDimensionWrapper.java

private double getRSquared(final Iterable<ValuePair<DoubleType, DoubleType>> pairs) {
    final SimpleRegression regression = new SimpleRegression();
    pairs.forEach(pair -> regression.addData(pair.a.get(), pair.b.get()));
    return regression.getRSquare();
}

From source file:org.bonej.wrapperPlugins.FractalDimensionWrapper.java

private WeightedObservedPoints toWeightedObservedPoints(
        final Iterable<ValuePair<DoubleType, DoubleType>> pairs) {
    final WeightedObservedPoints points = new WeightedObservedPoints();
    pairs.forEach(pair -> points.add(pair.a.get(), pair.b.get()));
    return points;
}

From source file:org.commonjava.indy.pkg.maven.content.group.MavenMetadataMerger.java

public MavenMetadataMerger(Iterable<MavenMetadataProvider> providers) {
    metadataProviders = new ArrayList<>();
    providers.forEach(provider -> metadataProviders.add(provider));
}

From source file:org.commonjava.indy.pkg.npm.content.group.PackageMetadataMerger.java

public PackageMetadataMerger(Iterable<PackageMetadataProvider> providers) {
    metadataProviders = new ArrayList<>();
    providers.forEach(provider -> metadataProviders.add(provider));
}

From source file:org.diorite.cfg.messages.Message.java

/**
 * Try broadcast this message to selected comamnd senders, if message is disabled method will just return false.
 *
 * @param targets targets of message./*  w  w w  . j av  a 2 s .  co m*/
 * @param lang    language to use if possible.
 * @param data    placeholder objects to use.
 *
 * @return true if message was send.
 */
public boolean broadcastStaticMessage(final Iterable<? extends CommandSender> targets, final Locale lang,
        final MessageData... data) {
    final BaseComponent msg = this.get(lang, data);
    if (msg == null) {
        return false;
    }
    targets.forEach(s -> s.sendMessage(msg));
    return true;
}