All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.nosqlbench.driver.pulsar.ops.PulsarBatchProducerEndOp Maven / Gradle / Ivy

Go to download

A Pulsar driver for nosqlbench. This provides the ability to inject synthetic data into a pulsar system.

There is a newer version: 4.15.102
Show newest version
package io.nosqlbench.driver.pulsar.ops;

import io.nosqlbench.nb.api.errors.BasicError;
import org.apache.pulsar.client.api.MessageId;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.common.util.FutureUtil;

import java.util.List;
import java.util.concurrent.CompletableFuture;

public class PulsarBatchProducerEndOp extends SyncPulsarOp {
    @Override
    public void run() {
        List> container = PulsarBatchProducerStartOp.threadLocalBatchMsgContainer.get();
        Producer producer = PulsarBatchProducerStartOp.threadLocalProducer.get();

        if ((container != null) && (!container.isEmpty())) {
            try {
                // producer.flushAsync().get();
                FutureUtil.waitForAll(container).get();
            } catch (Exception e) {
                throw new RuntimeException("Batch Producer:: failed to send (some of) the batched messages!");
            }

            container.clear();
            PulsarBatchProducerStartOp.threadLocalBatchMsgContainer.set(null);
        }
        else {
            throw new BasicError("You tried to end an empty batch message container. This means you" +
                " did initiate the batch container properly, or there is an error in your" +
                " pulsar op sequencing and ratios.");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy