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

tech.ydb.topic.write.impl.AsyncWriterImpl Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package tech.ydb.topic.write.impl;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.Executor;

import tech.ydb.topic.TopicRpc;
import tech.ydb.topic.settings.SendSettings;
import tech.ydb.topic.settings.WriterSettings;
import tech.ydb.topic.write.AsyncWriter;
import tech.ydb.topic.write.InitResult;
import tech.ydb.topic.write.Message;
import tech.ydb.topic.write.QueueOverflowException;
import tech.ydb.topic.write.WriteAck;

/**
 * @author Nikolay Perfilov
 */
public class AsyncWriterImpl extends WriterImpl implements AsyncWriter {

    public AsyncWriterImpl(TopicRpc topicRpc, WriterSettings settings, Executor compressionExecutor) {
        super(topicRpc, settings, compressionExecutor);
    }

    @Override
    public CompletableFuture init() {
        return initImpl();
    }

    @Override
    public CompletableFuture send(Message message, SendSettings settings) throws QueueOverflowException {
        try {
            return sendImpl(message, settings, true).join();
        } catch (CompletionException e) {
            if (e.getCause() instanceof QueueOverflowException) {
                throw (QueueOverflowException) e.getCause();
            } else {
                throw new RuntimeException(e);
            }
        }
    }

    @Override
    public CompletableFuture send(Message message) throws QueueOverflowException {
        return send(message, null);
    }

    @Override
    public CompletableFuture shutdown() {
        return shutdownImpl();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy