- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中com.github.zkclient.ZkClient
类的一些代码示例,展示了ZkClient
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkClient
类的具体详情如下:
包路径:com.github.zkclient.ZkClient
类名称:ZkClient
[英]Zookeeper client
The client is thread-safety
[中]动物园管理员客户
客户端是线程安全的
代码示例来源:origin: adyliu/jafka
static void tryCleanupZookeeper(String zkConnect, String groupId) {
try {
String dir = "/consumers/" + groupId;
ZkClient zk = new ZkClient(zkConnect, 30 * 1000, 30 * 1000);
zk.deleteRecursive(dir);
zk.close();
} catch (ZkInterruptedException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: adyliu/jafka
public static void makeSurePersistentPathExists(ZkClient zkClient, String path) {
if (!zkClient.exists(path)) {
zkClient.createPersistent(path, true);
}
}
代码示例来源:origin: adyliu/jafka
public static void deletePath(ZkClient zkClient, String path) {
try {
zkClient.delete(path);
} catch (ZkNoNodeException e) {
}
}
代码示例来源:origin: adyliu/jafka
public static void updatePersistentPath(ZkClient zkClient, String path, String data) {
try {
zkClient.writeData(path, Utils.getBytes(data));
} catch (ZkNoNodeException e) {
createParentPath(zkClient, path);
try {
zkClient.createPersistent(path, Utils.getBytes(data));
} catch (ZkNodeExistsException e2) {
zkClient.writeData(path, Utils.getBytes(data));
}
}
}
代码示例来源:origin: com.github.adyliu/zkclient
public boolean deleteRecursive(String path) {
List<String> children;
try {
children = getChildren(path, false);
} catch (ZkNoNodeException e) {
return true;
}
if (children != null){
for (String subPath : children) {
if (!deleteRecursive(path + "/" + subPath)) {
return false;
}
}
}
return delete(path);
}
代码示例来源:origin: com.github.adyliu/zkclient
@Override
public List<String> call() throws Exception {
exists(path, true);
try {
return getChildren(path, true);
} catch (ZkNoNodeException e) {
// ignore, the "exists" watch will listen for the parent node to appear
}
return null;
}
});
代码示例来源:origin: adyliu/zkclient
public synchronized void connect(final long maxMsToWaitUntilConnected, Watcher watcher) {
if (_eventThread != null) {
return;
}
boolean started = false;
try {
getEventLock().lockInterruptibly();
setShutdownTrigger(false);
_eventThread = new ZkEventThread(_connection.getServers());
_eventThread.start();
_connection.connect(watcher);
LOG.debug("Awaiting connection to Zookeeper server: " + maxMsToWaitUntilConnected);
if (!waitUntilConnected(maxMsToWaitUntilConnected, TimeUnit.MILLISECONDS)) {
throw new ZkTimeoutException(String.format(
"Unable to connect to zookeeper server[%s] within timeout %dms", _connection.getServers(), maxMsToWaitUntilConnected));
}
started = true;
} catch (InterruptedException e) {
States state = _connection.getZookeeperState();
throw new IllegalStateException("Not connected with zookeeper server yet. Current state is " + state);
} finally {
getEventLock().unlock();
// we should close the zookeeper instance, otherwise it would keep
// on trying to connect
if (!started) {
close();
}
}
}
代码示例来源:origin: adyliu/jafka
public static String readData(ZkClient zkClient, String path) {
return Utils.fromBytes(zkClient.readData(path));
}
代码示例来源:origin: com.github.adyliu/zkclient
@Override
public void run() throws Exception {
// reinstall watch
exists(path, true);
try {
byte[] data = readData(path, null, true);
listener.handleDataChange(path, data);
} catch (ZkNoNodeException e) {
listener.handleDataDeleted(path);
}
}
});
代码示例来源:origin: com.github.adyliu/zkclient
public void cas(String path, DataUpdater updater) {
Stat stat = new Stat();
boolean retry;
do {
retry = false;
try {
byte[] oldData = readData(path, stat);
byte[] newData = updater.update(oldData);
writeData(path, newData, stat.getVersion());
} catch (ZkBadVersionException e) {
retry = true;
}
} while (retry);
}
代码示例来源:origin: com.github.adyliu/zkclient
public boolean waitUntilExists(String path, TimeUnit timeUnit, long time) throws ZkInterruptedException {
Date timeout = new Date(System.currentTimeMillis() + timeUnit.toMillis(time));
LOG.debug("Waiting until znode '" + path + "' becomes available.");
if (exists(path)) {
return true;
}
acquireEventLock();
try {
while (!exists(path, true)) {
boolean gotSignal = getEventLock().getZNodeEventCondition().awaitUntil(timeout);
if (!gotSignal) {
return false;
}
}
return true;
} catch (InterruptedException e) {
throw new ZkInterruptedException(e);
} finally {
getEventLock().unlock();
}
}
代码示例来源:origin: adyliu/jafka
public void close() {
this.zkClient.close();
}
代码示例来源:origin: adyliu/jafka
public ZKBrokerPartitionInfo(ZKConfig zkConfig, Callback callback) {
this.zkConfig = zkConfig;
this.callback = callback;
//
this.zkClient = new ZkClient(zkConfig.getZkConnect(), //
zkConfig.getZkSessionTimeoutMs(), //
zkConfig.getZkConnectionTimeoutMs());
//
this.allBrokers = getZKBrokerInfo();
this.topicBrokerPartitions = getZKTopicPartitionInfo(this.allBrokers);
//use just the brokerTopicsListener for all watchers
this.brokerTopicsListener = new BrokerTopicsListener(this.topicBrokerPartitions, this.allBrokers);
//register listener for change of topics to keep topicsBrokerPartitions updated
zkClient.subscribeChildChanges(ZkUtils.BrokerTopicsPath, brokerTopicsListener);
//register listener for change of brokers for each topic to keep topicsBrokerPartitions updated
for (String topic : this.topicBrokerPartitions.keySet()) {
zkClient.subscribeChildChanges(ZkUtils.BrokerTopicsPath + "/" + topic, this.brokerTopicsListener);
}
// register listener for new broker
zkClient.subscribeChildChanges(ZkUtils.BrokerIdsPath, this.brokerTopicsListener);
//
// register listener for session expired event
zkClient.subscribeStateChanges(new ZKSessionExpirationListener());
}
代码示例来源:origin: com.github.adyliu/zkclient
public byte[] readData(String path, Stat stat) {
return readData(path, stat, hasListeners(path));
}
代码示例来源:origin: com.github.adyliu/zkclient
public boolean exists(final String path) {
return exists(path, hasListeners(path));
}
代码示例来源:origin: adyliu/zkclient
public List<String> getChildren(String path) {
return getChildren(path, hasListeners(path));
}
代码示例来源:origin: com.github.adyliu/zkclient
public void createPersistent(String path, boolean createParents) {
try {
create(path, null, CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
if (!createParents) {
throw e;
}
} catch (ZkNoNodeException e) {
if (!createParents) {
throw e;
}
String parentDir = path.substring(0, path.lastIndexOf('/'));
createPersistent(parentDir, createParents);
createPersistent(path, createParents);
}
}
代码示例来源:origin: adyliu/jafka
private void connectZk() {
logger.debug("Connecting to zookeeper instance at " + config.getZkConnect());
this.zkClient = new ZkClient(config.getZkConnect(), config.getZkSessionTimeoutMs(),
config.getZkConnectionTimeoutMs());
logger.debug("Connected to zookeeper at " + config.getZkConnect());
}
代码示例来源:origin: adyliu/jafka
public void startup() {
logger.info("connecting to zookeeper: " + config.getZkConnect());
zkClient = new ZkClient(config.getZkConnect(), config.getZkSessionTimeoutMs(),
config.getZkConnectionTimeoutMs());
zkClient.subscribeStateChanges(this);
}
代码示例来源:origin: adyliu/jafka
private static void createParentPath(ZkClient zkClient, String path) {
String parentDir = path.substring(0, path.lastIndexOf('/'));
if (parentDir.length() != 0) {
zkClient.createPersistent(parentDir, true);
}
}
本文整理了Java中org.I0Itec.zkclient.ZkClient.fireDataChangedEvents()方法的一些代码示例,展示了ZkClient.fireDataChangedE
本文整理了Java中org.I0Itec.zkclient.ZkClient.fireAllEvents()方法的一些代码示例,展示了ZkClient.fireAllEvents()的具体用法。这些代
本文整理了Java中org.I0Itec.zkclient.ZkClient.serialize()方法的一些代码示例,展示了ZkClient.serialize()的具体用法。这些代码示例主要来源于
本文整理了Java中org.I0Itec.zkclient.ZkClient.fireStateChangedEvent()方法的一些代码示例,展示了ZkClient.fireStateChanged
本文整理了Java中org.I0Itec.zkclient.ZkClient.processStateChanged()方法的一些代码示例,展示了ZkClient.processStateChange
本文整理了Java中org.I0Itec.zkclient.ZkClient.getEventLock()方法的一些代码示例,展示了ZkClient.getEventLock()的具体用法。这些代码示
本文整理了Java中org.I0Itec.zkclient.ZkClient.waitForKeeperState()方法的一些代码示例,展示了ZkClient.waitForKeeperState(
本文整理了Java中org.I0Itec.zkclient.ZkClient.setShutdownTrigger()方法的一些代码示例,展示了ZkClient.setShutdownTrigger(
本文整理了Java中org.I0Itec.zkclient.ZkClient.fireNewSessionEvents()方法的一些代码示例,展示了ZkClient.fireNewSessionEve
本文整理了Java中org.I0Itec.zkclient.ZkClient.retryUntilConnected()方法的一些代码示例,展示了ZkClient.retryUntilConnecte
本文整理了Java中org.I0Itec.zkclient.ZkClient.watchForChilds()方法的一些代码示例,展示了ZkClient.watchForChilds()的具体用法。这
本文整理了Java中org.I0Itec.zkclient.ZkClient.create()方法的一些代码示例,展示了ZkClient.create()的具体用法。这些代码示例主要来源于Github
本文整理了Java中org.I0Itec.zkclient.ZkClient.unsubscribeAll()方法的一些代码示例,展示了ZkClient.unsubscribeAll()的具体用法。这
本文整理了Java中org.I0Itec.zkclient.ZkClient.hasListeners()方法的一些代码示例,展示了ZkClient.hasListeners()的具体用法。这些代码示
本文整理了Java中org.I0Itec.zkclient.ZkClient.writeDataReturnStat()方法的一些代码示例,展示了ZkClient.writeDataReturnSta
本文整理了Java中org.I0Itec.zkclient.ZkClient.setZkSerializer()方法的一些代码示例,展示了ZkClient.setZkSerializer()的具体用法
本文整理了Java中org.I0Itec.zkclient.ZkClient.waitUntilExists()方法的一些代码示例,展示了ZkClient.waitUntilExists()的具体用法
本文整理了Java中org.I0Itec.zkclient.ZkClient.fireChildChangedEvents()方法的一些代码示例,展示了ZkClient.fireChildChange
本文整理了Java中org.I0Itec.zkclient.ZkClient.setCurrentState()方法的一些代码示例,展示了ZkClient.setCurrentState()的具体用法
本文整理了Java中org.I0Itec.zkclient.ZkClient.getShutdownTrigger()方法的一些代码示例,展示了ZkClient.getShutdownTrigger(
我是一名优秀的程序员,十分优秀!