本文整理匯總了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();
}