Skip to content

Package: ZooKeeperConfig

ZooKeeperConfig

nameinstructionbranchcomplexitylinemethod
ZooKeeperConfig(String, String)
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
create(String, String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getCommitDelayTimeInSecs()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getConnectTimeoutInMillis()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getName()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getRootPath()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSessionTimeoutInMillis()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getZooKeeperServerList()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setCommitDelayTimeInSecs(long)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setConnectTimeoutInMillis(long)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setRootPath(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setSessionTimeoutInMillis(long)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
toString()
M: 43 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2012, 2017 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.glassfish.grizzly.thrift.client.zookeeper;
18:
19: import java.io.Serializable;
20:
21: /**
22: * The configuration for ZooKeeper client
23: * <p>
24: * Example of use: {@code
25: * final GrizzlyThriftClientManager.Builder managerBuilder = new GrizzlyThriftClientManager.Builder();
26: * // setup zookeeper server
27: * final ZooKeeperConfig zkConfig = ZooKeeperConfig.create("thrift-client-manager", DEFAULT_ZOOKEEPER_ADDRESS);
28: * zkConfig.setRootPath(ROOT);
29: * zkConfig.setConnectTimeoutInMillis(3000);
30: * zkConfig.setSessionTimeoutInMillis(30000);
31: * zkConfig.setCommitDelayTimeInSecs(2);
32: * managerBuilder.zooKeeperConfig(zkConfig);
33: * // create a thrift client manager
34: * final GrizzlyThriftClientManager manager = managerBuilder.build();
35: * final GrizzlyThriftClient.Builder<String, String> thriftClientBuilder = manager.createThriftClientBuilder("user");
36: * // setup thrift servers
37: * final Set<SocketAddress> thriftServers = new HashSet<SocketAddress>();
38: * thriftServers.add(THRIFT_SERVER_ADDRESS1);
39: * thriftServers.add(THRIFT_SERVER_ADDRESS2);
40: * thriftClientBuilder.servers(thriftServers);
41: * // create a user thrift client
42: * final GrizzlyThriftClient thriftClient = thriftClientBuilder.build();
43: * // ...
44: * // clean
45: * manager.removeThriftClient("user");
46: * manager.shutdown();
47: * }
48: *
49: * @author Bongjae Chang
50: */
51: public class ZooKeeperConfig implements Serializable {
52:
53: private static final long serialVersionUID = -3100430916673953287L;
54:
55: private static final String DEFAULT_ROOT_PATH = "/";
56: private static final long DEFAULT_CONNECT_TIMEOUT_IN_MILLIS = 5000; // 5secs
57: private static final long DEFAULT_SESSION_TIMEOUT_IN_MILLIS = 30000; // 30secs
58: private static final long DEFAULT_COMMIT_DELAY_TIME_IN_SECS = 60; // 60secs
59:
60: private final String name;
61: private final String zooKeeperServerList;
62:
63: private String rootPath = DEFAULT_ROOT_PATH;
64: private long connectTimeoutInMillis = DEFAULT_CONNECT_TIMEOUT_IN_MILLIS;
65: private long sessionTimeoutInMillis = DEFAULT_SESSION_TIMEOUT_IN_MILLIS;
66: private long commitDelayTimeInSecs = DEFAULT_COMMIT_DELAY_TIME_IN_SECS;
67:
68: /**
69: * Create ZKClient's configuration with the specific name or Id
70: *
71: * @param name name or id
72: * @param zooKeeperServerList comma separated host:port pairs, each
73: * corresponding to a zookeeper server. e.g.
74: * "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
75: * @return ZKClient's configuration
76: */
77: public static ZooKeeperConfig create(final String name, final String zooKeeperServerList) {
78: return new ZooKeeperConfig(name, zooKeeperServerList);
79: }
80:
81: private ZooKeeperConfig(final String name, final String zooKeeperServerList) {
82: this.name = name;
83: this.zooKeeperServerList = zooKeeperServerList;
84: }
85:
86: /**
87: * Root path for ZKClient
88: *
89: * @param rootPath root path of the zookeeper. default is "/".
90: */
91: public void setRootPath(final String rootPath) {
92: this.rootPath = rootPath;
93: }
94:
95: /**
96: * Connect timeout in milli-seconds
97: *
98: * @param connectTimeoutInMillis connect timeout. negative value means "never
99: * timed out". default is 5000(5 secs).
100: */
101: public void setConnectTimeoutInMillis(final long connectTimeoutInMillis) {
102: this.connectTimeoutInMillis = connectTimeoutInMillis;
103: }
104:
105: /**
106: * Session timeout in milli-seconds
107: *
108: * @param sessionTimeoutInMillis Zookeeper connection's timeout. default is
109: * 30000(30 secs).
110: */
111: public void setSessionTimeoutInMillis(final long sessionTimeoutInMillis) {
112: this.sessionTimeoutInMillis = sessionTimeoutInMillis;
113: }
114:
115: /**
116: * Delay time in seconds for committing
117: *
118: * @param commitDelayTimeInSecs delay time before committing. default is
119: * 60(60secs).
120: */
121: public void setCommitDelayTimeInSecs(final long commitDelayTimeInSecs) {
122: this.commitDelayTimeInSecs = commitDelayTimeInSecs;
123: }
124:
125: public String getName() {
126: return name;
127: }
128:
129: public String getZooKeeperServerList() {
130: return zooKeeperServerList;
131: }
132:
133: public String getRootPath() {
134: return rootPath;
135: }
136:
137: public long getConnectTimeoutInMillis() {
138: return connectTimeoutInMillis;
139: }
140:
141: public long getSessionTimeoutInMillis() {
142: return sessionTimeoutInMillis;
143: }
144:
145: public long getCommitDelayTimeInSecs() {
146: return commitDelayTimeInSecs;
147: }
148:
149: @Override
150: public String toString() {
151: return "ZooKeeperConfig{" + "name='" + name + '\'' + ", zooKeeperServerList='" + zooKeeperServerList + '\'' + ", rootPath='"
152: + rootPath + '\'' + ", connectTimeoutInMillis=" + connectTimeoutInMillis + ", sessionTimeoutInMillis="
153: + sessionTimeoutInMillis + ", commitDelayTimeInSecs=" + commitDelayTimeInSecs + '}';
154: }
155: }