/* * (C) Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Contributors: * ohun@live.cn (夜色) */ package com.mpush.zk; import com.mpush.tools.config.CC.mp.zk; public class ZKConfig { public static final int ZK_MAX_RETRY = 3; public static final int ZK_MIN_TIME = 5000; public static final int ZK_MAX_TIME = 5000; public static final int ZK_SESSION_TIMEOUT = 5000; public static final int ZK_CONNECTION_TIMEOUT = 5000; public static final String ZK_DEFAULT_CACHE_PATH = "/"; private String hosts; private String digest; private String namespace; private int maxRetries = ZK_MAX_RETRY; private int baseSleepTimeMs = ZK_MIN_TIME; private int maxSleepMs = ZK_MAX_TIME; private int sessionTimeout = ZK_SESSION_TIMEOUT; private int connectionTimeout = ZK_CONNECTION_TIMEOUT; private String watchPath = ZK_DEFAULT_CACHE_PATH; public ZKConfig(String hosts) { this.hosts = hosts; } public static ZKConfig build() { return new ZKConfig(zk.server_address) .setConnectionTimeout(zk.connectionTimeoutMs) .setDigest(zk.digest) .setWatchPath(zk.watch_path) .setMaxRetries(zk.retry.maxRetries) .setMaxSleepMs(zk.retry.maxSleepMs) .setBaseSleepTimeMs(zk.retry.baseSleepTimeMs) .setNamespace(zk.namespace) .setSessionTimeout(zk.sessionTimeoutMs) ; } public String getHosts() { return hosts; } public ZKConfig setHosts(String hosts) { this.hosts = hosts; return this; } public String getNamespace() { return namespace; } public ZKConfig setNamespace(String namespace) { this.namespace = namespace; return this; } public int getMaxRetries() { return maxRetries; } public ZKConfig setMaxRetries(int maxRetries) { this.maxRetries = maxRetries; return this; } public int getBaseSleepTimeMs() { return baseSleepTimeMs; } public ZKConfig setBaseSleepTimeMs(int baseSleepTimeMs) { this.baseSleepTimeMs = baseSleepTimeMs; return this; } public int getMaxSleepMs() { return maxSleepMs; } public ZKConfig setMaxSleepMs(int maxSleepMs) { this.maxSleepMs = maxSleepMs; return this; } public int getSessionTimeout() { return sessionTimeout; } public ZKConfig setSessionTimeout(int sessionTimeout) { this.sessionTimeout = sessionTimeout; return this; } public int getConnectionTimeout() { return connectionTimeout; } public ZKConfig setConnectionTimeout(int connectionTimeout) { this.connectionTimeout = connectionTimeout; return this; } public String getDigest() { return digest; } public ZKConfig setDigest(String digest) { this.digest = digest; return this; } public String getWatchPath() { return watchPath; } public ZKConfig setWatchPath(String watchPath) { this.watchPath = watchPath; return this; } @Override public String toString() { return "ZKConfig{" + "hosts='" + hosts + '\'' + ", digest='" + digest + '\'' + ", namespace='" + namespace + '\'' + ", maxRetries=" + maxRetries + ", baseSleepTimeMs=" + baseSleepTimeMs + ", maxSleepMs=" + maxSleepMs + ", sessionTimeout=" + sessionTimeout + ", connectionTimeout=" + connectionTimeout + ", watchPath='" + watchPath + '\'' + '}'; } }