当前位置: 首页>>代码示例>>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;未经允许,请勿转载。