當前位置: 首頁>>代碼示例>>Java>>正文


Java ZkClient.create方法代碼示例

本文整理匯總了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();
	}
	
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:25,代碼來源:SafeZclient.java

示例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");
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:17,代碼來源:ZclientServerPub.java

示例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 + "]");
            });
        }
    });



}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:23,代碼來源:ServerManagerMonitor.java

示例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) {

  }
}
 
開發者ID:linkedin,項目名稱:li-apache-kafka-clients,代碼行數:29,代碼來源:EmbeddedZookeeperTest.java

示例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"));
	}
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:9,代碼來源:SafeZclient.java

示例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();
	}
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:16,代碼來源:SafeZclient.java

示例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");
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:34,代碼來源:ZclientNormal.java

示例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();
    }
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:11,代碼來源:ClientB.java

示例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();
        }
    }
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:12,代碼來源:ClientA.java


注:本文中的org.I0Itec.zkclient.ZkClient.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。