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.memcached.zookeeper;
18:
19: import java.io.Serializable;
20:
21: /**
22: * The configuration for ZooKeeper client
23: * <p>
24: * Example of use:
25: * {@code
26: * final GrizzlyMemcachedCacheManager.Builder managerBuilder = new GrizzlyMemcachedCacheManager.Builder();
27: * // setup zookeeper server
28: * final ZooKeeperConfig zkConfig = ZooKeeperConfig.create("cache-manager", DEFAULT_ZOOKEEPER_ADDRESS);
29: * zkConfig.setRootPath(ROOT);
30: * zkConfig.setConnectTimeoutInMillis(3000);
31: * zkConfig.setSessionTimeoutInMillis(30000);
32: * zkConfig.setCommitDelayTimeInSecs(2);
33: * managerBuilder.zooKeeperConfig(zkConfig);
34: * // create a cache manager
35: * final GrizzlyMemcachedCacheManager manager = managerBuilder.build();
36: * final GrizzlyMemcachedCache.Builder<String, String> cacheBuilder = manager.createCacheBuilder("user");
37: * // setup memcached servers
38: * final Set<SocketAddress> memcachedServers = new HashSet<SocketAddress>();
39: * memcachedServers.add(MEMCACHED_ADDRESS1);
40: * memcachedServers.add(MEMCACHED_ADDRESS2);
41: * cacheBuilder.servers(memcachedServers);
42: * // create a user cache
43: * final GrizzlyMemcachedCache<String, String> cache = cacheBuilder.build();
44: * // ...
45: * // clean
46: * manager.removeCache("user");
47: * manager.shutdown();
48: * }
49: *
50: * @author Bongjae Chang
51: */
52: public class ZooKeeperConfig implements Serializable {
53:
54: private static final long serialVersionUID = -3100430916673953287L;
55:
56: private static final String DEFAULT_ROOT_PATH = "/";
57: private static final long DEFAULT_CONNECT_TIMEOUT_IN_MILLIS = 5000; // 5secs
58: private static final long DEFAULT_SESSION_TIMEOUT_IN_MILLIS = 30000; // 30secs
59: private static final long DEFAULT_COMMIT_DELAY_TIME_IN_SECS = 60; // 60secs
60:
61: private final String name;
62: private final String zooKeeperServerList;
63:
64: private String rootPath = DEFAULT_ROOT_PATH;
65: private long connectTimeoutInMillis = DEFAULT_CONNECT_TIMEOUT_IN_MILLIS;
66: private long sessionTimeoutInMillis = DEFAULT_SESSION_TIMEOUT_IN_MILLIS;
67: private long commitDelayTimeInSecs = DEFAULT_COMMIT_DELAY_TIME_IN_SECS;
68:
69: /**
70: * Create ZKClient's configuration with the specific name or Id
71: *
72: * @param name name or id
73: * @param zooKeeperServerList comma separated host:port pairs, each corresponding to a zookeeper server.
74: * e.g. "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:
82: private ZooKeeperConfig(final String name, final String zooKeeperServerList) {
83: this.name = name;
84: this.zooKeeperServerList = zooKeeperServerList;
85: }
86:
87: /**
88: * Root path for ZKClient
89: *
90: * @param rootPath root path of the zookeeper. default is "/".
91: */
92: public void setRootPath(final String rootPath) {
93: this.rootPath = rootPath;
94: }
95:
96: /**
97: * Connect timeout in milli-seconds
98: *
99: * @param connectTimeoutInMillis connect timeout. negative value means "never 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 30000(30 secs).
109: */
110: public void setSessionTimeoutInMillis(final long sessionTimeoutInMillis) {
111: this.sessionTimeoutInMillis = sessionTimeoutInMillis;
112: }
113:
114: /**
115: * Delay time in seconds for committing
116: *
117: * @param commitDelayTimeInSecs delay time before committing. default is 60(60secs).
118: */
119: public void setCommitDelayTimeInSecs(final long commitDelayTimeInSecs) {
120: this.commitDelayTimeInSecs = commitDelayTimeInSecs;
121: }
122:
123: public String getName() {
124: return name;
125: }
126:
127: public String getZooKeeperServerList() {
128: return zooKeeperServerList;
129: }
130:
131: public String getRootPath() {
132: return rootPath;
133: }
134:
135: public long getConnectTimeoutInMillis() {
136: return connectTimeoutInMillis;
137: }
138:
139: public long getSessionTimeoutInMillis() {
140: return sessionTimeoutInMillis;
141: }
142:
143: public long getCommitDelayTimeInSecs() {
144: return commitDelayTimeInSecs;
145: }
146:
147: @Override
148: public String toString() {
149: return "ZooKeeperConfig{" +
150: "name='" + name + '\'' +
151: ", zooKeeperServerList='" + zooKeeperServerList + '\'' +
152: ", rootPath='" + rootPath + '\'' +
153: ", connectTimeoutInMillis=" + connectTimeoutInMillis +
154: ", sessionTimeoutInMillis=" + sessionTimeoutInMillis +
155: ", commitDelayTimeInSecs=" + commitDelayTimeInSecs +
156: '}';
157: }
158: }