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

org.zodiac.sentinel.base.datasource.model.SentinelRedisDataSourceInfo Maven / Gradle / Ivy

The newest version!
package org.zodiac.sentinel.base.datasource.model;

import java.time.Duration;
import java.util.List;
import java.util.Objects;

import org.zodiac.sdk.toolkit.util.lang.StrUtil;
import org.zodiac.sentinel.base.datasource.DataSourceType;
import org.zodiac.sentinel.base.datasource.factory.SentinelRedisDataSourceFactoryBean;

public class SentinelRedisDataSourceInfo extends AbstractDataSourceInfo {

    /**
     * redis server host.
     */
    private String host = "localhost";

    /**
     * redis server port.
     */
    private int port = 6379;

    /**
     * redis server password.
     */
    private String password;

    /**
     * redis server default select database.
     */
    private int database;

    /**
     * redis server timeout.
     */
    private Duration timeout;

    /**
     * Comma-separated list of "host:port" pairs.
     */
    private List nodes;

    /**
     * data key in Redis.
     */
    private String ruleKey;

    /**
     * channel to subscribe in Redis.
     */
    private String channel;

    /**
     * redis sentinel model.
     */
    private String masterId;

    public SentinelRedisDataSourceInfo() {
        super(DataSourceType.redis, SentinelRedisDataSourceFactoryBean.class.getName());
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getDatabase() {
        return database;
    }

    public void setDatabase(int database) {
        this.database = database;
    }

    public Duration getTimeout() {
        return timeout;
    }

    public void setTimeout(Duration timeout) {
        this.timeout = timeout;
    }

    public List getNodes() {
        return nodes;
    }

    public void setNodes(List nodes) {
        this.nodes = nodes;
    }

    public String getRuleKey() {
        return ruleKey;
    }

    public void setRuleKey(String ruleKey) {
        this.ruleKey = ruleKey;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public String getMasterId() {
        return masterId;
    }

    public void setMasterId(String masterId) {
        this.masterId = masterId;
    }

    @Override
    public SentinelRedisDataSourceInfo preCheck(String dataSourceName) {
        super.preCheck(dataSourceName);
        if (StrUtil.isEmpty(ruleKey)) {
            throw new IllegalArgumentException("RedisDataSource  ruleKey can not be empty");
        }

        if (StrUtil.isEmpty(channel)) {
            throw new IllegalArgumentException("RedisDataSource  channel can not be empty");
        }

        if (StrUtil.isEmpty(masterId)) {
            throw new IllegalArgumentException("RedisDataSource  sentinel model,masterId can not be empty");
        }
        return this;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result =
            prime * result + Objects.hash(channel, database, host, masterId, nodes, password, port, ruleKey, timeout);
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!super.equals(obj))
            return false;
        if (getClass() != obj.getClass())
            return false;
        SentinelRedisDataSourceInfo other = (SentinelRedisDataSourceInfo)obj;
        return Objects.equals(channel, other.channel) && database == other.database && Objects.equals(host, other.host)
            && Objects.equals(masterId, other.masterId) && Objects.equals(nodes, other.nodes)
            && Objects.equals(password, other.password) && port == other.port && Objects.equals(ruleKey, other.ruleKey)
            && Objects.equals(timeout, other.timeout);
    }

    @Override
    public String toString() {
        return "[host=" + host + ", port=" + port + ", password=" + password + ", database="
            + database + ", timeout=" + timeout + ", nodes=" + nodes + ", ruleKey=" + ruleKey + ", channel=" + channel
            + ", masterId=" + masterId + ", getDataType()=" + getDataType() + ", getConverterClass()="
            + getConverterClass() + "]";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy