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


Java ZkClient.exists方法代碼示例

本文整理匯總了Java中org.I0Itec.zkclient.ZkClient.exists方法的典型用法代碼示例。如果您正苦於以下問題:Java ZkClient.exists方法的具體用法?Java ZkClient.exists怎麽用?Java ZkClient.exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.I0Itec.zkclient.ZkClient的用法示例。


在下文中一共展示了ZkClient.exists方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: nextId

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
/**
 * 利用zookeeper
 * @return
 */
@Override
public String nextId() {
    String app = this.registerDto.getApp();
    String host = this.registerDto.getHost();
    ZkClient zkClient = this.registerDto.getZkClient();
    String path = Constants.ZK_REGISTRY_ID_ROOT_PATH + Constants.SLASH + app + Constants.SLASH + host;
    if (zkClient.exists(path)) {
        // 如果已經有該節點,表示已經為當前的host上部署的該app分配的編號(應對某個服務重啟之後編號不變的問題),直接獲取該id,而無需生成
        return zkClient.readData(Constants.ZK_REGISTRY_ID_ROOT_PATH + Constants.SLASH + app + Constants.SLASH + host);
    } else {
        // 節點不存在,那麽需要生成id,利用zk節點的版本號每寫一次就自增的機製來實現
        Stat stat = zkClient.writeDataReturnStat(Constants.ZK_REGISTRY_SEQ, new byte[0], -1);
        // 生成id
        String id = String.valueOf(stat.getVersion());
        // 將數據寫入節點
        zkClient.createPersistent(path, true);
        zkClient.writeData(path, id);
        return id;
    }
}
 
開發者ID:JThink,項目名稱:SkyEye,代碼行數:25,代碼來源:IncrementIdGen.java

示例2: makeSure

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public static void makeSure(ZkClient client, final String dataPath) {
	int start = 0, index;
	while (true) {
		index = dataPath.indexOf("/", start + 1);

		if (index == start + 1) {
			return;
		}
		String path = dataPath;
		if (index > 0) {
			path = dataPath.substring(0, index);
			start = index;
		}
		if (!client.exists(path)) {
			client.createPersistent(path);
		}

		if (index < 0 || index == dataPath.length() - 1) {
			return;
		}
	}
}
 
開發者ID:youtongluan,項目名稱:sumk,代碼行數:23,代碼來源:ZkClientHolder.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: exists

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public boolean exists(String cluster, String path) {
    ZkClient zkClient = ZkPool.getZkClient(cluster);
    try {
        if (zkClient == null) {
            return false;
        }
        return zkClient.exists(path);
    } finally {
        ZkPool.releaseZkClient(cluster, zkClient);
    }
}
 
開發者ID:XiaoMi,項目名稱:shepher,代碼行數:12,代碼來源:NodeDAO.java

示例5: SendCounterHandler

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public SendCounterHandler(String producerGroup, String zkServers) {
    this.producerGroup = producerGroup;
    int sessionTimeoutMs = 10000;
    int connectionTimeoutMs = 10000;
    zkClient = new ZkClient(zkServers, sessionTimeoutMs, connectionTimeoutMs,
        ZKStringSerializer$.MODULE$);
    //
    groupPath = ROOT + "/" + producerGroup;
    if (!zkClient.exists(groupPath)) {
        zkClient.createPersistent(groupPath, true);
    }
    initCollectionTimer();
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:14,代碼來源:SendCounterHandler.java

示例6: ZkConfigDb

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public ZkConfigDb ( String zkServers, String rootZkNode )
{
	fZkConnection = new ZkConnection ( zkServers );
	zkClient = new ZkClient ( fZkConnection );
	zkRoot = rootZkNode == null ? "" : rootZkNode;

	if ( rootZkNode.length() > 0 && !zkClient.exists(zkRoot) )
	{
		zkClient.createPersistent ( zkRoot, true );
	}
}
 
開發者ID:att,項目名稱:dmaap-framework,代碼行數:12,代碼來源:ZkConfigDb.java

示例7: readAndListen

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public static NamePairs readAndListen(String zkUrl, String path, IZkDataListener listener) {
	ZkClient client = ZkClientHolder.getZkClient(zkUrl);
	if (!client.exists(path)) {
		return null;
	}
	String data = ZkClientHolder.data2String(client.readData(path));
	if (listener != null) {
		client.subscribeDataChanges(path, listener);
	}
	return new NamePairs(data);
}
 
開發者ID:youtongluan,項目名稱:sumk,代碼行數:12,代碼來源:ZKConfigHandler.java

示例8: 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

示例9: 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

示例10: SendCounterHandler

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public SendCounterHandler(String producerGroup, ZkClient zkClient) {
	this.zkClient = zkClient;
	this.producerGroup =producerGroup;
	//
	groupPath = ROOT + "/" + producerGroup;
	if(!zkClient.exists(groupPath)){
		zkClient.createPersistent(groupPath, true);
	}
	initCollectionTimer();
}
 
開發者ID:vakinge,項目名稱:jeesuite-libs,代碼行數:11,代碼來源:SendCounterHandler.java

示例11: start

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public synchronized void start(String name) {
    List<String> list = addressMap.get(name);
    if (null != list) {
        return;
    }
    list = new ArrayList<>();
    // 創建 ZooKeeper 客戶端
    ZkClient zkClient = new ZkClient(zkAddress, Constant.ZK_SESSION_TIMEOUT, Constant.ZK_CONNECTION_TIMEOUT);
    LOGGER.info("connect zookeeper={}", zkAddress);
    // 獲取 service 節點
    String servicePath = Constant.ZK_REGISTRY_PATH + "/" + name;
    if (!zkClient.exists(servicePath)) {
        throw new RpcFrameworkException(RpcErrorMsgConstant.FRAMEWORK_REGISTER_ERROR,
                String.format("can not find any service node on path: %s", servicePath));
    }
    List<String> addressList = zkClient.getChildren(servicePath);
    if (CollectionUtil.isEmpty(addressList)) {
        throw new RpcFrameworkException(RpcErrorMsgConstant.FRAMEWORK_REGISTER_ERROR,
                String.format("can not find any address node on path: %s", servicePath));
    }
    for (String path : addressList) {
        String addressPath = servicePath + "/" + path;
        String ipPort = zkClient.readData(addressPath);
        list.add(ipPort);
    }
    addressMap.put(name, list);
}
 
開發者ID:netboynb,項目名稱:coco,代碼行數:28,代碼來源:ZooKeeperServiceDiscovery.java

示例12: checkPath

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public boolean checkPath(ZkClient zkClient, String path){
	boolean isExists = zkClient.exists(path);
	if(!isExists){
		logger.error("invalid zk path:{}", path);
		return false;
	}
	
	return true;
}
 
開發者ID:DTStack,項目名稱:jlogstash-input-plugin,代碼行數:10,代碼來源:MonitorCluster.java

示例13: init

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
private void init(){
    zkClient = new ZkClient(zkConnects);
    if(!zkClient.exists(Constants.ZK_ROOT)){
        zkClient.createPersistent(Constants.ZK_ROOT);
    }
}
 
開發者ID:dubboclub,項目名稱:reloud,代碼行數:7,代碼來源:RegistryClient.java


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