当前位置: 首页>>代码示例>>Java>>正文


Java CuratorFramework.close方法代码示例

本文整理汇总了Java中org.apache.curator.framework.CuratorFramework.close方法的典型用法代码示例。如果您正苦于以下问题:Java CuratorFramework.close方法的具体用法?Java CuratorFramework.close怎么用?Java CuratorFramework.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.curator.framework.CuratorFramework的用法示例。


在下文中一共展示了CuratorFramework.close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildConnection

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
private static CuratorFramework buildConnection(String url) {
    CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(url, new ExponentialBackoffRetry(100, 6));

    // start connection
    curatorFramework.start();
    // wait 3 second to establish connect
    try {
        curatorFramework.blockUntilConnected(3, TimeUnit.SECONDS);
        if (curatorFramework.getZookeeperClient().isConnected()) {
            return curatorFramework.usingNamespace("");
        }
    } catch (InterruptedException ignored) {
        Thread.currentThread().interrupt();
    }

    // fail situation
    curatorFramework.close();
    throw new RuntimeException("failed to connect to zookeeper service : " + url);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:20,代码来源:ZktoXmlMain.java

示例2: testServer

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
public void testServer(){
        try {
        TestingServer server=new TestingServer(2181,new File("/"));
        server.start();

        CuratorFramework curatorFramework = CuratorFrameworkFactory.
                builder().
                connectString(server.getConnectString()).
                sessionTimeoutMs(1000).
                retryPolicy(new RetryNTimes(3, 1000)).
                build();
        curatorFramework.start();
        System.out.println(curatorFramework.getChildren().forPath("/"));
        curatorFramework.close();
        server.stop();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
 
开发者ID:mumudemo,项目名称:mumu-zookeeper,代码行数:21,代码来源:CuratorServer.java

示例3: createConnection

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
private static CuratorFramework createConnection() {
       String url= ZkConfig.getInstance().getZkURL();

    CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(url, new ExponentialBackoffRetry(100, 6));

    // start connection
    curatorFramework.start();
    // wait 3 second to establish connect
    try {
        curatorFramework.blockUntilConnected(3, TimeUnit.SECONDS);
        if (curatorFramework.getZookeeperClient().isConnected()) {
            return curatorFramework;
        }
    } catch (InterruptedException ignored) {
        Thread.currentThread().interrupt();
    }

    // fail situation
    curatorFramework.close();
    throw new RuntimeException("failed to connect to zookeeper service : " + url);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:22,代码来源:ZKUtils.java

示例4: getFlumeConfiguration

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
@Override
protected FlumeConfiguration getFlumeConfiguration() {
  try {
    CuratorFramework cf = createClient();
    cf.start();
    try {
      byte[] data = cf.getData().forPath(basePath + "/" + getAgentName());
      return configFromBytes(data);
    } finally {
      cf.close();
    }
  } catch (Exception e) {
    LOGGER.error("Error getting configuration info from Zookeeper", e);
    throw new FlumeException(e);
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:17,代码来源:StaticZooKeeperConfigurationProvider.java

示例5: createConnection

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
private static CuratorFramework createConnection() {
    String url = ZkConfig.getInstance().getZkURL();
    CuratorFramework framework = CuratorFrameworkFactory.newClient(url, new ExponentialBackoffRetry(100, 6));
    // start connection
    framework.start();
    // wait 3 second to establish connect
    try {
        framework.blockUntilConnected(3, TimeUnit.SECONDS);
        if (framework.getZookeeperClient().isConnected()) {
            LOGGER.info("CuratorFramework createConnection success");
            return framework;
        }
    } catch (InterruptedException ignored) {
        LOGGER.info("CuratorFramework createConnection error", ignored);
        Thread.currentThread().interrupt();
    }
    // fail situation
    framework.close();
    throw new RuntimeException("failed to connect to zookeeper service : " + url);
}
 
开发者ID:actiontech,项目名称:dble,代码行数:21,代码来源:ZKUtils.java

示例6: DistributedClusterStat

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
public DistributedClusterStat(Map<Object,Object> _conf ) throws Exception
{
	this.conf = _conf;
	CuratorFramework _zk = mkZk();//创建Zookeeper连接及重试策略
	String path = String.valueOf(conf.get(Config.LEAF_ZOOKEEPER_ROOT));
	zkobj.mkdirs(_zk,path);// 创建一个永久目录
	_zk.close();

	active = new AtomicBoolean(true);



	watcher = new WatcherCallBack() {
		@Override
		public void execute(KeeperState state, EventType type, String path) {
			if ( active.get())
			{
				if(!(state.equals(KeeperState.SyncConnected)))
				{
					LOG.warn("Received event " + state + ": " + type + ": " + path + "with disconnected  from Zookeeper.");
					//System.out.println("Received event " + state + ":" + type + ":" + path + "with disconnected Zookeeper.");
				}
				else
				{
					LOG.info("Received event " + state + ":" + type + ":" + path);
					//System.out.println("Received event " + state + ":" + type + ":" + path);
					if(type.equals(EventType.NodeChildrenChanged)) //leaf 的临时node节点发生了变化(server上线或者下线)
					{
						LOG.info("Node childrens changed at path: " + path);
						//重新注册watcher事件
						try {
							List<String> children = get_childern(path,true);
							LOG.info("children list at path : " + path + " is " + children);
						} catch (Exception e)
						{
							LOG.warn("faild to get children in path: " + path,e);
						}
					}
				}

				if (!type.equals(EventType.None))
				{
					//System.out.println("Received event " + state + ":" + type + ":" + path);
					LOG.info("Received event " + state + ":" + type + ":" + path);
					for (Map.Entry<UUID,ClusterStateCallback> e: callbacks.entrySet())
					{
						ClusterStateCallback fn = e.getValue();
						fn.execute(type,path);
					}
				}

			}
		}
	};
	zk = null;
	try {
		zk = mkZk(watcher);
	}
	catch (Exception e)
	{
		LOG.error(e.getMessage(),e);
	}
}
 
开发者ID:weizhenyi,项目名称:leaf-snowflake,代码行数:64,代码来源:DistributedClusterStat.java

示例7: main

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);

        //use chroot so all subsequent paths are below /stroom-stats to avoid conflicts with hbase/zookeeper/kafka etc.
        CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181/stroom-stats", retryPolicy);
        client.start();

        Stat stat = client.checkExists().forPath("/");
        if (stat == null) {
            LOGGER.info("Creating root node");
            client.create().forPath("/");
        }

        Stat testNode = client.checkExists().creatingParentContainersIfNeeded().forPath("/my/test/path");

//        dumpChildren(client, "/");
//        dumpChildren(client, "/propertyService");

        checkTreeCache(client, "/propertyService");


//        client.create().forPath("/testNode", Bytes.toBytes("MyStringVal"));

        byte[] bVal = client.getData().forPath("/testNode");
        LOGGER.info(Bytes.toString(bVal));


        client.close();
    }
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:31,代码来源:CuratorTest.java


注:本文中的org.apache.curator.framework.CuratorFramework.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。