本文整理匯總了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();
}
}