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

tech.ydb.topic.read.impl.events.DataReceivedEventImpl Maven / Gradle / Ivy

The newest version!
package tech.ydb.topic.read.impl.events;

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

import tech.ydb.topic.description.OffsetsRange;
import tech.ydb.topic.read.Message;
import tech.ydb.topic.read.PartitionOffsets;
import tech.ydb.topic.read.PartitionSession;
import tech.ydb.topic.read.events.DataReceivedEvent;
import tech.ydb.topic.read.impl.CommitterImpl;
import tech.ydb.topic.read.impl.PartitionSessionImpl;

/**
 * @author Nikolay Perfilov
 */
public class DataReceivedEventImpl implements DataReceivedEvent {
    private final List messages;
    private final PartitionSessionImpl partitionSession;
    private final OffsetsRange offsetsToCommit;
    private final CommitterImpl committer;

    public DataReceivedEventImpl(PartitionSessionImpl partitionSession, List messages,
                                 OffsetsRange offsetsToCommit) {
        this.messages = messages;
        this.partitionSession = partitionSession;
        this.offsetsToCommit = offsetsToCommit;
        this.committer = new CommitterImpl(partitionSession, messages.size(), offsetsToCommit);
    }

    @Override
    public List getMessages() {
        return messages;
    }

    @Override
    public PartitionOffsets getPartitionOffsets() {
        return new PartitionOffsets(partitionSession.getSessionInfo(), Collections.singletonList(offsetsToCommit));
    }

    @Override
    public PartitionSession getPartitionSession() {
        return partitionSession.getSessionInfo();
    }

    public PartitionSessionImpl getPartitionSessionImpl() {
        return partitionSession;
    }

    @Override
    public CompletableFuture commit() {
        return committer.commitImpl(false);
    }

    public OffsetsRange getOffsetsToCommit() {
        return offsetsToCommit;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy