本文整理汇总了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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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();
}