Skip to content

Package: ZooKeeperSupportThriftClient

ZooKeeperSupportThriftClient

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: /**
20: * The interface using the ZooKeeper for synchronizing thrift server list
21: * <p>
22: * Example of use: {@code
23: * final GrizzlyThriftClientManager.Builder managerBuilder = new GrizzlyThriftClientManager.Builder();
24: * // setup zookeeper server
25: * final ZooKeeperConfig zkConfig = ZooKeeperConfig.create("thrift-client-manager", DEFAULT_ZOOKEEPER_ADDRESS);
26: * zkConfig.setRootPath(ROOT);
27: * zkConfig.setConnectTimeoutInMillis(3000);
28: * zkConfig.setSessionTimeoutInMillis(30000);
29: * zkConfig.setCommitDelayTimeInSecs(2);
30: * managerBuilder.zooKeeperConfig(zkConfig);
31: * // create a thrift client manager
32: * final GrizzlyThriftClientManager manager = managerBuilder.build();
33: * final GrizzlyThriftClient.Builder<String, String> thriftClientBuilder = manager.createThriftClientBuilder("user");
34: * // setup thrift servers
35: * final Set<SocketAddress> thriftServers = new HashSet<SocketAddress>();
36: * thriftServers.add(THRIFT_SERVER_ADDRESS1);
37: * thriftServers.add(THRIFT_SERVER_ADDRESS2);
38: * thriftClientBuilder.servers(thriftServers);
39: * // create a user thrift
40: * final GrizzlyThriftClient<String, String> thriftClient = thriftClientBuilder.build();
41: * // ZooKeeperSupportThriftClient's basic operations
42: * if (thriftClient.isZooKeeperSupported()) {
43: * final String serverListPath = thriftClient.getZooKeeperServerListPath();
44: * final String serverList = thriftClient.getCurrentServerListFromZooKeeper();
45: * thriftClient.setCurrentServerListOfZooKeeper("localhost:11211,localhost:11212");
46: * } // ... // clean manager.removeThriftClient("user"); manager.shutdown(); }
47: *
48: * @author Bongjae Chang
49: */
50: public interface ZooKeeperSupportThriftClient {
51:
52: /**
53: * Check if this thrift client supports the ZooKeeper for synchronizing the
54: * thrift server list
55: *
56: * @return true if this thrift client supports it
57: */
58: boolean isZooKeeperSupported();
59:
60: /**
61: * Return the path of the thrift server list which has been registered in the
62: * ZooKeeper server
63: *
64: * @return the path of the thrift server list in the ZooKeeper server. "null"
65: * means this thrift client doesn't support the ZooKeeper or this thrift client
66: * is not started yet
67: */
68: String getZooKeeperServerListPath();
69:
70: /**
71: * Return the current thrift server list string from the ZooKeeper server
72: *
73: * @return the current server list string
74: */
75: String getCurrentServerListFromZooKeeper();
76:
77: /**
78: * Set the current thrift server list string with the given
79: * {@code thriftServerList}
80: * <p>
81: * {@code thriftServerList} could be comma separated host:port pairs, each
82: * corresponding to a thrift server. e.g.
83: * "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" Be careful that this operation
84: * will propagate {@code thriftServerList} to thrift clients which has joinned
85: * the same thrift client name(scope) because the thrift server list of
86: * ZooKeeper server will be changed.
87: *
88: * @param thriftServerList the thrift server list string
89: * @return true if this thrift server list is set successfully
90: */
91: boolean setCurrentServerListOfZooKeeper(final String thriftServerList);
92:
93: /**
94: * Add the custom {@link BarrierListener}
95: *
96: * The given {@code listener} will be called after thrift client's default
97: * listener will be completed. {@link BarrierListener#onInit} will be called
98: * when this thrift client will be registered in the ZooKeeper.
99: * {@link BarrierListener#onCommit} will be called when this thrift client's
100: * server list will be changed in the ZooKeeper.
101: * {@link BarrierListener#onDestroy} will be called when this thrift client will
102: * be unregistered in the ZooKeeper.
103: *
104: * @param listener the custom listener
105: */
106: void addZooKeeperListener(final BarrierListener listener);
107:
108: /**
109: * Remove the custom {@link BarrierListener}
110: *
111: * The given {@code listener} will be called after thrift client's default
112: * listener will be completed. {@link BarrierListener#onInit} will be called
113: * when this thrift client will be registered in the ZooKeeper.
114: * {@link BarrierListener#onCommit} will be called when this thrift client's
115: * server list will be changed in the ZooKeeper.
116: * {@link BarrierListener#onDestroy} will be called when this thrift client will
117: * be unregistered in the ZooKeeper.
118: *
119: * @param listener the custom listener which was given by
120: * {@link #addZooKeeperListener}
121: */
122: void removeZooKeeperListener(final BarrierListener listener);
123: }