本文整理汇总了Java中org.I0Itec.zkclient.ZkClient.create方法的典型用法代码示例。如果您正苦于以下问题:Java ZkClient.create方法的具体用法?Java ZkClient.create怎么用?Java ZkClient.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.I0Itec.zkclient.ZkClient
的用法示例。
在下文中一共展示了ZkClient.create方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: client
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
private static void client() {
try {
ZkClient zc = new ZkClient("localhost:2181");
String userTwo = "gao:gao";
zc.addAuthInfo("digest", userTwo.getBytes());
//使用admin就可以创建
// String userOne = "admin:admin";
// zc.addAuthInfo("digest",userOne.getBytes());
String data = zc.readData("/safe");
log.info("只读用户 " + userTwo + "读取safe节点返回数据:" + data);
zc.create("/safe2", "test", CreateMode.EPHEMERAL);
log.info("只读用户创建节点safe2成功:" + zc.readData("/safe2"));
zc.create("/safe/test", "zookeeper加密是针对节点加密的", CreateMode.EPHEMERAL);
log.info("只读用户创建节点失败:" + zc.readData("/safe/test"));
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: test
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
private static void test() throws InterruptedException {
final ZkClient zkClient4subChild = new ZkClient("localhost:2181");
zkClient4subChild.create("/serverroot", "serverroot", Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Thread.sleep(4000);
zkClient4subChild.create("/serverroot/server1", "server1", Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Thread.sleep(4000);
zkClient4subChild.create("/serverroot/server2", "server2", Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Thread.sleep(20000);
zkClient4subChild.delete("/serverroot/server1");
zkClient4subChild.delete("/serverroot/server2");
zkClient4subChild.delete("/serverroot");
}
示例3: monitor
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
private static void monitor() {
ZkClient zc=new ZkClient("localhost:2181",1000);
//创建监控节点
if(!zc.exists("/monitor"))
zc.create("/monitor",null, CreateMode.PERSISTENT);
if(!zc.exists("/monitor/client"))
zc.create("/monitor/client",null, CreateMode.PERSISTENT);
zc.subscribeChildChanges("/monitor/client",new IZkChildListener(){
@Override
public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
System.out.println("------------客户端发生变化---------childPath="+parentPath );
currentChilds.forEach((String childPath)->{
System.out.println("parentPath = [" + parentPath + "], currentChilds = [" + currentChilds + "]");
});
}
});
}
示例4: testSimpleScenario
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
@Test
public void testSimpleScenario() throws Exception {
String connectionString;
String host;
int port;
try (EmbeddedZookeeper zk = new EmbeddedZookeeper()) {
connectionString = zk.getConnectionString();
host = zk.getHostAddress();
port = zk.getPort();
Assert.assertEquals(host + ":" + port, connectionString);
ZkClient client = new ZkClient(connectionString);
try {
String path = "/" + UUID.randomUUID().toString();
client.waitUntilConnected(5, TimeUnit.SECONDS);
client.create(path, "payload", CreateMode.PERSISTENT);
Assert.assertEquals("payload", client.readData(path));
} finally {
client.close();
}
}
//now verify shut down
try {
new Socket(host, port);
Assert.fail("expected to fail");
} catch (ConnectException ignored) {
}
}
示例5: ls
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
private static void ls() {
for (int i = 0; i <20 ; i++) {
ZkClient zc = new ZkClient("127.0.0.1:2181");
if(!zc.exists("/tt"))
zc.create("/tt", "test", CreateMode.EPHEMERAL);
log.info(zc.readData("/tt"));
}
}
示例6: server
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
/**
* server端对safe接点加密
*/
private static void server() {
try {
ZkClient zc = new ZkClient("localhost:2181");
List<ACL> acls = getACL(zc);
if (zc.exists("/safe"))
zc.delete("/safe");
zc.create("/safe", "safe", acls, CreateMode.PERSISTENT);
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: test
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
/**
* @Description: zkClient主要做了两件事情。
* @see:一件是在session loss和session expire时自动创建新的ZooKeeper实例进行重连。
* @see:一件是将一次性watcher包装为持久watcher。
* @see:后者的具体做法是简单的在watcher回调中,重新读取数据的同时再注册相同的watcher实例。
*/
private static void test() {
final ZkClient zc = new ZkClient("123.56.118.135:2181");
// 创建根节点
/* Persistent与Ephemeral 就是持久化保存到本地和不持久化的区别 ,不能再临时节点下面创建子节点 */
zc.createPersistent("/testroot");
// zc.createEphemeral("/testroot");
// 创建子节点
zc.create("/testroot/node1", "node1", CreateMode.EPHEMERAL);
zc.createPersistent("/testroot/node2");
zc.create("/testroot/node2/test", "node1", CreateMode.EPHEMERAL);
List<String> children = zc.getChildren("/");
log.info("根节点下面的字节点个数" + children.size());
// 获得子节点个数
int chidrenNumbers = zc.countChildren("/testroot");
log.info("子节点个数" + chidrenNumbers);
zc.writeData("/testroot/node2/test", "给节点写数据");
// 删除节点
zc.delete("/testroot/node2/test");
zc.delete("/testroot/node2");
zc.delete("/testroot/node1");
zc.delete("/testroot");
}
示例8: main
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
public static void main(String[] args) {
ZkClient zc=new ZkClient("localhost:2181",1000);
//创建监控节点
zc.create("/monitor/client/clientB","clientB", CreateMode.EPHEMERAL);
try {
System.in.read();
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: main
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
public static void main(String[] args) {
ZkClient zc=new ZkClient("localhost:2181",1000);
//创建监控节点
zc.create("/monitor/client/clientA","clientA", CreateMode.EPHEMERAL);
try {
System.in.read();
} catch (Exception e) {
e.printStackTrace();
}
}