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

tech.ydb.topic.settings.AlterConsumerSettings Maven / Gradle / Ivy

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

import java.time.Instant;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import tech.ydb.topic.description.SupportedCodecs;

/**
 * @author Nikolay Perfilov
 */
public class AlterConsumerSettings {
    private final String name;
    @Nullable
    private final Boolean important;
    @Nullable
    private final Instant readFrom;
    @Nullable
    private final SupportedCodecs supportedCodecs;
    private final Map alterAttributes;
    private final Set dropAttributes;

    private AlterConsumerSettings(Builder builder) {
        this.name = builder.name;
        this.important = builder.important;
        this.readFrom = builder.readFrom;
        this.supportedCodecs = builder.supportedCodecs;
        this.alterAttributes = builder.alterAttributes;
        this.dropAttributes = builder.dropAttributes;
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getName() {
        return name;
    }

    @Nullable
    public Boolean getImportant() {
        return important;
    }

    @Nullable
    public Instant getReadFrom() {
        return readFrom;
    }

    @Nullable
    public SupportedCodecs getSupportedCodecs() {
        return supportedCodecs;
    }

    public Map getAlterAttributes() {
        return alterAttributes;
    }

    public Set getDropAttributes() {
        return dropAttributes;
    }

    /**
     * BUILDER
     */
    public static class Builder {
        private String name;
        private Boolean important = null;
        private Instant readFrom = null;
        private SupportedCodecs supportedCodecs = null;
        private Map alterAttributes = new HashMap<>();
        private Set dropAttributes = new HashSet<>();

        /**
         * @param name  Consumer name
         * @return settings builder
         */
        public Builder setName(@Nonnull String name) {
            this.name = name;
            return this;
        }

        /**
         * @param important  Flag that this consumer is important. Consumer may be marked as 'important'.
         *                   It means messages for this consumer will never expire due to retention. User should take
         *                   care that such consumer never stalls, to prevent running out of disk space.
         * @return settings builder
         */
        public Builder setImportant(boolean important) {
            this.important = important;
            return this;
        }

        /**
         * @param readFrom  Time to read from. All messages with smaller server written_at timestamp will be skipped.
         * @return settings builder
         */
        public Builder setReadFrom(Instant readFrom) {
            this.readFrom = readFrom;
            return this;
        }

        /**
         * @param supportedCodecs  Codecs supported by this consumer.
         *                         Should contain all codecs, supported by its Topic
         * @return settings builder
         */
        public Builder setSupportedCodecs(SupportedCodecs supportedCodecs) {
            this.supportedCodecs = supportedCodecs;
            return this;
        }

        /**
         * Add consumer attribute to alter.
         * @param name  Attribute name
         * @param value  Attribute value
         * @return settings builder
         */
        public Builder addAlterAttribute(@Nonnull String name, @Nonnull String value) {
            alterAttributes.put(name, value);
            return this;
        }

        /**
         * Set consumer attributes to alter.
         * @param attributes  Consumer attributes to alter.
         * @return settings builder
         */
        public Builder setAlterAttributes(Map attributes) {
            alterAttributes = attributes;
            return this;
        }

        /**
         * Add consumer attribute to drop.
         * @param name  Attribute name
         * @return settings builder
         */
        public Builder addDropAttribute(@Nonnull String name) {
            dropAttributes.add(name);
            return this;
        }

        /**
         * Set consumer attributes to drop.
         * @param attributes  Consumer attributes
         * @return settings builder
         */
        public Builder setDropAttributes(Set attributes) {
            dropAttributes = attributes;
            return this;
        }

        public AlterConsumerSettings build() {
            if (name == null) {
                throw new IllegalArgumentException("Consumer name is not set in AlterConsumerSettings");
            }
            return new AlterConsumerSettings(this);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy