本文整理汇总了Java中org.apache.curator.utils.ZKPaths类的典型用法代码示例。如果您正苦于以下问题:Java ZKPaths类的具体用法?Java ZKPaths怎么用?Java ZKPaths使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ZKPaths类属于org.apache.curator.utils包,在下文中一共展示了ZKPaths类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: notifyClusterDDL
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
public void notifyClusterDDL(String schema, String table, String sql, DDLInfo.DDLStatus ddlStatus, boolean needNotifyOther) throws Exception {
CuratorFramework zkConn = ZKUtils.getConnection();
DDLInfo ddlInfo = new DDLInfo(schema, sql, ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_MYID), ddlStatus);
String nodeName = StringUtil.getFullName(schema, table);
String nodePath = ZKPaths.makePath(KVPathUtil.getDDLPath(), nodeName);
if (zkConn.checkExists().forPath(nodePath) == null) {
zkConn.create().forPath(nodePath, ddlInfo.toString().getBytes(StandardCharsets.UTF_8));
} else {
String instancePath = ZKPaths.makePath(nodePath, KVPathUtil.DDL_INSTANCE);
String thisNode = ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_MYID);
ZKUtils.createTempNode(instancePath, thisNode);
if (needNotifyOther) {
//this node is ddl sender
zkConn.setData().forPath(nodePath, ddlInfo.toString().getBytes(StandardCharsets.UTF_8));
while (true) {
List<String> preparedList = zkConn.getChildren().forPath(instancePath);
List<String> onlineList = zkConn.getChildren().forPath(KVPathUtil.getOnlinePath());
if (preparedList.size() >= onlineList.size()) {
zkConn.delete().deletingChildrenIfNeeded().forPath(nodePath);
break;
}
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100));
}
}
}
}
示例2: getMarkerData
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
@Override
CompletableFuture<Data<Integer>> getMarkerData(int segmentNumber) {
final CompletableFuture<Data<Integer>> result = new CompletableFuture<>();
final String path = ZKPaths.makePath(markerPath, String.format("%d", segmentNumber));
cache.getCachedData(path)
.whenComplete((res, ex) -> {
if (ex != null) {
Throwable cause = Exceptions.unwrap(ex);
if (cause instanceof StoreException.DataNotFoundException) {
result.complete(null);
} else {
result.completeExceptionally(cause);
}
} else {
result.complete(res);
}
});
return result;
}
示例3: addPartner
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
public void addPartner(String key, Partner partner) {
String partnerPath = ZKPaths.makePath(partnerStorePath, key);
RetryRunner.create().onFinalError(e -> {
LOGGER.error("addPartner.error", e);
ReporterHolder.incException(e);
throw new ServiceErrorException(ErrorCode.SYSTEM_ERROR);
}).run((Callable<Void>) () -> {
if (client.checkExists().creatingParentsIfNeeded().forPath(partnerPath) != null) {
client.setData()
.forPath(partnerPath, JSONObject.toJSONBytes(partner));
} else {
client.create()
.creatingParentsIfNeeded()
.withMode(CreateMode.PERSISTENT)
.forPath(partnerPath, JSONObject.toJSONBytes(partner));
}
return null;
});
}
示例4: removePartner
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
public void removePartner(String key) {
RetryRunner.create()
.excludeExceptions(KeeperException.NoNodeException.class)
.includeExceptions(KeeperException.class)
.onFinalError(e -> {
if (e instanceof KeeperException.NoNodeException) {
} else {
ReporterHolder.incException(e);
LOGGER.error("removePartner.error", e);
throw new ServiceErrorException(ErrorCode.SYSTEM_ERROR);
}
})
.run((Callable<Void>) () -> {
client.delete()
.forPath(ZKPaths.makePath(partnerStorePath, key));
return null;
});
}
示例5: getZkRangeStore
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
public ZkRangeStore getZkRangeStore(int clientIndex) {
String lockPath = "/snowflake/locks";
String storePath = "/snowflake/idstore";
CuratorFramework curatorFramework = ZkUtils.create("127.0.0.1:2181", 1000, 10000);
curatorFramework.start();
for (String client : clients) {
try {
curatorFramework.setData().forPath(ZKPaths.makePath(storePath, client), "0".getBytes());
} catch (Exception e) {
if (e instanceof KeeperException.NoNodeException) {
try {
curatorFramework.create().creatingParentsIfNeeded().forPath(storePath, "0".getBytes());
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
return new ZkRangeStore(clients.get(clientIndex), curatorFramework, lockPath, storePath, 1, TimeUnit.SECONDS, 0, 10);
}
示例6: doWork
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
private void doWork()
{
for ( String path : paths )
{
try
{
List<String> children = client.getChildren().forPath(path);
for ( String name : children )
{
String thisPath = ZKPaths.makePath(path, name);
Stat stat = client.checkExists().forPath(thisPath);
if ( (stat != null) && (stat.getNumChildren() == 0) )
{
reaper.addPath(thisPath, mode);
}
}
}
catch ( Exception e )
{
log.error("Could not get children for path: " + path, e);
}
}
}
示例7: createPath
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
/**
* 创建配制信息
* 方法描述
* @param configKey 配制的当前路径名称信息
* @param filterInnerMap 最终的信息是否为map
* @param configDirectory 配制的目录
* @param restDirectory 子目录信息
* @创建日期 2016年9月11日
*/
public boolean createPath(String path) {
// 得到当前的目录信息
LOGGER.trace("createPath child path is {}", path);
boolean result = true;
try {
// 进行目录的创建操作
ZKPaths.mkdirs(curator.getZookeeperClient().getZooKeeper(), path);
} catch (Exception e) {
LOGGER.error(" createPath error", e);
result = false;
}
return result;
}
示例8: readTargetChildsData
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
/**
* 读取指定节点的子菜单的值
*
* @param path
* @return
*/
public Map<String, String> readTargetChildsData(String path) {
if (!ObjectUtils.allNotNull(zkClient, path)) {
return null;
}
Map<String, String> map = null;
try {
Stat stat = exists(path);
if (stat != null) {
List<String> childrens = zkClient.getChildren().forPath(path);
GetDataBuilder dataBuilder = zkClient.getData();
if (childrens != null) {
map = childrens.stream().collect(Collectors.toMap(Function.identity(), (child) -> {
try {
return new String(dataBuilder.forPath(ZKPaths.makePath(path, child)), Charsets.UTF_8);
} catch (Exception e1) {
return null;
}
}));
}
}
} catch (Exception e) {
log.error("get target childs data fail!, path:{} , error:{}", path, e);
}
return map;
}
示例9: startInitialTasks
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
private void startInitialTasks()
{
if( !startedInitialTasks )
{
List<ChildData> currentData = taskCache.getCurrentData();
List<String> taskIds = Lists.newArrayList();
for( ChildData task : currentData )
{
String taskId = ZKPaths.getNodeFromPath(task.getPath());
LOGGER.debug("Task added " + taskId);
taskIds.add(taskId);
addRunner(taskId);
}
requestFullStatus(taskIds);
startedInitialTasks = true;
}
}
示例10: should_load_agent_config
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
@Test
public void should_load_agent_config() throws IOException, InterruptedException {
// given:
String wsUrl = "ws://localhost:8080/logging";
String cmdStatusUrl = "http://localhost:8080/cmd/report";
String cmdLogUrl = "http://localhost:8080/cmd/log/upload";
AgentSettings config = new AgentSettings(wsUrl, cmdStatusUrl, cmdLogUrl);
// when: create zone with agent config
String zonePath = ZKPaths.makePath(ROOT_PATH, "ali");
zkClient.createEphemeral(zonePath, config.toBytes());
// then:
Config.AGENT_SETTINGS = Config.loadAgentConfig(server.getConnectString(), "ali", 5);
Assert.assertNotNull(Config.agentSettings());
Assert.assertEquals(wsUrl, Config.agentSettings().getWebSocketUrl());
Assert.assertEquals(cmdStatusUrl, Config.agentSettings().getCmdStatusUrl());
Assert.assertEquals(cmdLogUrl, Config.agentSettings().getCmdLogUrl());
}
示例11: should_create_and_delete_zk_node_for_children
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
@Test
public void should_create_and_delete_zk_node_for_children() throws Throwable {
// init:
String rootPath = ZKPaths.makePath("/", "flow-test");
String childPath = ZKPaths.makePath(rootPath, "child-node");
// when: create root and child
zkClient.create(rootPath, null);
zkClient.create(childPath, null);
// then:
Assert.assertEquals(true, zkClient.exist(rootPath));
Assert.assertEquals(true, zkClient.exist(childPath));
// when: delete node with children
zkClient.delete(rootPath, true);
// then:
Assert.assertEquals(false, zkClient.exist(rootPath));
Assert.assertEquals(false, zkClient.exist(childPath));
}
示例12: should_listen_node_change_event
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
@Test
public void should_listen_node_change_event() throws Throwable {
// init: create node and watch it
String path = ZKPaths.makePath("/", "flow-test");
zkClient.create(path, null);
Assert.assertEquals(true, zkClient.exist(path));
final CountDownLatch latch = new CountDownLatch(1);
zkClient.watchNode(path, latch::countDown);
// when:
zkClient.setData(path, "hello".getBytes());
// then:
latch.await(10L, TimeUnit.SECONDS);
Assert.assertEquals("hello", new String(zkClient.getData(path)));
}
示例13: after
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
@After
public void after() throws Throwable {
String rootPath = "/";
for (String nodeName : zkClient.getChildren(rootPath)) {
if (nodeName.equals("zookeeper")) {
return;
}
String path = ZKPaths.makePath(rootPath, nodeName);
zkClient.delete(path, false);
}
Assert.assertEquals(1, zkClient.getChildren(rootPath).size());
zkClient.close();
}
示例14: deRegisterServiceInstance
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
public void deRegisterServiceInstance(String region,
String availabilityZone,
String flavor,
String serviceName,
int servicePort, String serviceAddress) throws Exception {
String regPath = new StringBuilder().append(registrationPath).append("/").append(region).append("/")
.append(availabilityZone).append("/").append(flavor).toString();
ServiceInstance<MetaData> service = getServiceInstance(serviceName, servicePort, serviceAddress, Collections.emptyMap());
String path = ZKPaths.makePath(ZKPaths.makePath(regPath, service.getName()), service.getId());
if (connector.isPathExists(path)) {
log.info("Deleting key={}", path);
connector.delete(path);
}
}
示例15: getConsumerHostInfos
import org.apache.curator.utils.ZKPaths; //导入依赖的package包/类
public static ArrayList<HostInfo> getConsumerHostInfos(String serviceName)
{
ArrayList<HostInfo> consumerHostInfos=new ArrayList<HostInfo>();
String consumerDirPath="/"+serviceName+"/consumers";
try {
if(client.checkExists().forPath(consumerDirPath)==null)
{
return consumerHostInfos;
}
for(String childNode:ZKPaths.getSortedChildren(client.getZookeeperClient().getZooKeeper(), "/registor"+consumerDirPath))
{
consumerHostInfos.add(HostInfoFormatter.fromFormatString(childNode));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return consumerHostInfos;
}