下面列出了怎么用org.apache.zookeeper.client.ZKClientConfig的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Generates the TLS configuration for Zookeeper.
*
* @return
*/
private ZKClientConfig getClientConfig() {
ZKClientConfig clientConfig = new ZKClientConfig();
clientConfig.setProperty("zookeeper.clientCnxnSocket", "org.apache.zookeeper.ClientCnxnSocketNetty");
clientConfig.setProperty("zookeeper.client.secure", "true");
clientConfig.setProperty("zookeeper.ssl.trustStore.location", trustStoreFile.getAbsolutePath());
clientConfig.setProperty("zookeeper.ssl.trustStore.password", trustStorePassword);
clientConfig.setProperty("zookeeper.ssl.trustStore.type", "PKCS12");
clientConfig.setProperty("zookeeper.ssl.keyStore.location", keyStoreFile.getAbsolutePath());
clientConfig.setProperty("zookeeper.ssl.keyStore.password", keyStorePassword);
clientConfig.setProperty("zookeeper.ssl.keyStore.type", "PKCS12");
return clientConfig;
}
private static ZKClientConfig createClientConfig(Optional<File> clientConfigFile) {
if (clientConfigFile.isPresent()) {
boolean useSecureClient = Boolean.parseBoolean(getEnvironmentVariable("VESPA_USE_TLS_FOR_ZOOKEEPER_CLIENT").orElse("false"));
String config = "zookeeper.client.secure=" + useSecureClient + "\n";
clientConfigFile.get().getParentFile().mkdirs();
IOUtils.writeFile(clientConfigFile.get(), Utf8.toBytes(config));
try {
return new ZKClientConfig(clientConfigFile.get());
} catch (QuorumPeerConfig.ConfigException e) {
throw new RuntimeException("Unable to create ZooKeeper client config file " + clientConfigFile.get());
}
} else {
return new ZKClientConfig();
}
}
/**
* @throws IOException If failed.
*/
public ZkTestClientCnxnSocketNIO(ZKClientConfig clientCfg) throws IOException {
super(clientCfg);
String threadName = Thread.currentThread().getName();
nodeName = threadName.substring(threadName.indexOf('-') + 1);
if (DEBUG)
log.info("ZkTestClientCnxnSocketNIO created for node: " + nodeName);
}
VespaZooKeeperFactory(ZKClientConfig zkClientConfig) {
this.zkClientConfig = zkClientConfig;
}
/**
* Creates an instance of ZooKeeperAdmin
*
* @throws IOException might be thrown
*
* @param connectString Connection String used to connect to Zookeeper
* @param sessionTimeout Session timeout
* @param watcher Watcher which will be notified about watches and connection changes
* @param conf Zookeeper client configuration
*
* @return ZooKeeperAdmin instance
*/
ZooKeeperAdmin createZookeeperAdmin(String connectString, int sessionTimeout, Watcher watcher, ZKClientConfig conf) throws IOException;
/**
* Creates an instance of ZooKeeperAdmin
*
* @param connectString Connection String used to connect to Zookeeper
* @param sessionTimeout Session timeout
* @param watcher Watcher which will be notified about watches and connection changes
* @param conf Zookeeper client configuration
*
* @return ZooKeeperAdmin instance
*/
@Override
public ZooKeeperAdmin createZookeeperAdmin(String connectString, int sessionTimeout, Watcher watcher, ZKClientConfig conf) throws IOException {
return new ZooKeeperAdmin(connectString, sessionTimeout, watcher, conf);
}