ZookeeperConfig.java 1.5 KB
Newer Older
wu-sheng's avatar
wu-sheng 已提交
1
package com.a.eye.skywalking.registry.impl.zookeeper;
2

3 4
import com.a.eye.skywalking.logging.api.ILog;
import com.a.eye.skywalking.logging.api.LogManager;
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

import java.util.Properties;

/**
 * Created by xin on 2016/11/10.
 */
public class ZookeeperConfig {
    private static      ILog   logger      = LogManager.getLogger(ZookeeperConfig.class);
    public static final String CONNECT_URL = "CONNECT_URL";
    public static final String AUTH_SCHEMA = "AUTH_SCHEMA";
    public static final String AUTH_INFO   = "AUTH_INFO";

    private String connectURL;
    private String autSchema;
    private byte[] auth;

    public ZookeeperConfig(Properties config) {
        this.connectURL = config.getProperty(CONNECT_URL);
        if (this.connectURL == null || this.connectURL.length() == 0) {
            throw new IllegalArgumentException("Connect url cannot be null");
        }

        this.autSchema = config.getProperty(AUTH_SCHEMA);
        String authString = config.getProperty(AUTH_INFO);
        if (authString != null) {
            this.auth = authString.getBytes();
        }
        logger.info("connection url: {} \n auth schema : {} \n auth info : {} ", connectURL, autSchema, authString);
    }

    public boolean hasAuthInfo() {
        return (this.autSchema != null && this.autSchema.length() > 0) && (this.auth != null && this.auth.length > 0);
    }

    public String getConnectURL() {
        return connectURL;
    }

    public String getAutSchema() {
        return autSchema;
    }

    public byte[] getAuth() {
        return auth;
    }
}