public interface ZooKeeperSupportThriftClient
Example of use:
final GrizzlyThriftClientManager.Builder managerBuilder = new GrizzlyThriftClientManager.Builder();
// setup zookeeper server
final ZooKeeperConfig zkConfig = ZooKeeperConfig.create("thrift-client-manager", DEFAULT_ZOOKEEPER_ADDRESS);
zkConfig.setRootPath(ROOT);
zkConfig.setConnectTimeoutInMillis(3000);
zkConfig.setSessionTimeoutInMillis(30000);
zkConfig.setCommitDelayTimeInSecs(2);
managerBuilder.zooKeeperConfig(zkConfig);
// create a thrift client manager
final GrizzlyThriftClientManager manager = managerBuilder.build();
final GrizzlyThriftClient.Builder<String, String> thriftClientBuilder = manager.createThriftClientBuilder("user");
// setup thrift servers
final Set<SocketAddress> thriftServers = new HashSet<SocketAddress>();
thriftServers.add(THRIFT_SERVER_ADDRESS1);
thriftServers.add(THRIFT_SERVER_ADDRESS2);
thriftClientBuilder.servers(thriftServers);
// create a user thrift
final GrizzlyThriftClient<String, String> thriftClient = thriftClientBuilder.build();
// ZooKeeperSupportThriftClient's basic operations
if (thriftClient.isZooKeeperSupported()) {
final String serverListPath = thriftClient.getZooKeeperServerListPath();
final String serverList = thriftClient.getCurrentServerListFromZooKeeper();
thriftClient.setCurrentServerListOfZooKeeper("localhost:11211,localhost:11212");
}
// ...
// clean
manager.removeThriftClient("user");
manager.shutdown();
| Modifier and Type | Method and Description |
|---|---|
void |
addZooKeeperListener(BarrierListener listener)
Add the custom
BarrierListener
The given listener will be called after thrift client's default listener will be completed. |
String |
getCurrentServerListFromZooKeeper()
Return the current thrift server list string from the ZooKeeper server
|
String |
getZooKeeperServerListPath()
Return the path of the thrift server list which has been registered in the ZooKeeper server
|
boolean |
isZooKeeperSupported()
Check if this thrift client supports the ZooKeeper for synchronizing the thrift server list
|
void |
removeZooKeeperListener(BarrierListener listener)
Remove the custom
BarrierListener
The given listener will be called after thrift client's default listener will be completed. |
boolean |
setCurrentServerListOfZooKeeper(String thriftServerList)
Set the current thrift server list string with the given
thriftServerList |
boolean isZooKeeperSupported()
String getZooKeeperServerListPath()
String getCurrentServerListFromZooKeeper()
boolean setCurrentServerListOfZooKeeper(String thriftServerList)
thriftServerList
thriftServerList could be comma separated host:port pairs, each corresponding to a thrift server.
e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
Be careful that this operation will propagate thriftServerList to thrift clients which has joinned the same thrift client name(scope)
because the thrift server list of ZooKeeper server will be changed.
thriftServerList - the thrift server list stringvoid addZooKeeperListener(BarrierListener listener)
BarrierListener
The given listener will be called after thrift client's default listener will be completed.
BarrierListener.onInit(java.lang.String, java.lang.String, byte[]) will be called when this thrift client will be registered in the ZooKeeper.
BarrierListener.onCommit(java.lang.String, java.lang.String, byte[]) will be called when this thrift client's server list will be changed in the ZooKeeper.
BarrierListener.onDestroy(java.lang.String) will be called when this thrift client will be unregistered in the ZooKeeper.listener - the custom listenervoid removeZooKeeperListener(BarrierListener listener)
BarrierListener
The given listener will be called after thrift client's default listener will be completed.
BarrierListener.onInit(java.lang.String, java.lang.String, byte[]) will be called when this thrift client will be registered in the ZooKeeper.
BarrierListener.onCommit(java.lang.String, java.lang.String, byte[]) will be called when this thrift client's server list will be changed in the ZooKeeper.
BarrierListener.onDestroy(java.lang.String) will be called when this thrift client will be unregistered in the ZooKeeper.listener - the custom listener which was given by addZooKeeperListener(org.glassfish.grizzly.thrift.client.zookeeper.BarrierListener)Copyright © 2017-2019 Oracle Corporation. All Rights Reserved.