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


Java ZKPaths.makePath方法代码示例

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


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

示例1: 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;
	});
}
 
开发者ID:mm23504570,项目名称:snowflake,代码行数:20,代码来源:PartnerStore.java

示例2: 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);
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:ChildReaper.java

示例3: 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();
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:18,代码来源:ZkClientTest.java

示例4: addTableMetaLock

import org.apache.curator.utils.ZKPaths; //导入方法依赖的package包/类
private void addTableMetaLock(RouteResultset rrs) throws SQLNonTransientException {
    String schema = rrs.getSchema();
    String table = rrs.getTable();
    try {
        DbleServer.getInstance().getTmManager().addMetaLock(schema, table);
        if (DbleServer.getInstance().isUseZK()) {
            String nodeName = StringUtil.getFullName(schema, table);
            String ddlPath = KVPathUtil.getDDLPath();
            String nodePth = ZKPaths.makePath(ddlPath, nodeName);
            CuratorFramework zkConn = ZKUtils.getConnection();
            int times = 0;
            while (zkConn.checkExists().forPath(KVPathUtil.getSyncMetaLockPath()) != null || zkConn.checkExists().forPath(nodePth) != null) {
                LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1000));
                if (times % 60 == 0) {
                    LOGGER.info("waiting for syncMeta.lock or metaLock about " + nodeName + " in " + ddlPath);
                    times = 0;
                }
                times++;
            }
            DbleServer.getInstance().getTmManager().notifyClusterDDL(schema, table, rrs.getStatement(), DDLInfo.DDLStatus.INIT, true);
        }
    } catch (Exception e) {
        DbleServer.getInstance().getTmManager().removeMetaLock(schema, table);
        throw new SQLNonTransientException(e.toString() + ",sql:" + rrs.getStatement());
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:27,代码来源:ServerConnection.java

示例5: 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());
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:20,代码来源:ConfigTest.java

示例6: 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);
    }
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:17,代码来源:TestServiceUtil.java

示例7: createNode

import org.apache.curator.utils.ZKPaths; //导入方法依赖的package包/类
/**
 * 创建新的配置组
 */
public void createNode() {
    String newPropertyGroupName = (String) newPropertyGroup.getValue();
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Create new node: {}", newPropertyGroupName);
    }
    String authedNode = ZKPaths.makePath(nodeAuth.getAuthedNode(), versionMB.getSelectedVersion());
    boolean created = nodeService.createProperty(ZKPaths.makePath(authedNode, newPropertyGroupName), null);
    if (created) {
        FacesContext.getCurrentInstance().addMessage(null,
            new FacesMessage("Property group created.", newPropertyGroupName));
        refreshGroup();
        newPropertyGroup.setValue(null);
        nodeData.refreshNodeProperties(null);
    }
    else {
        FacesContext.getCurrentInstance().addMessage(null,
            new FacesMessage(FacesMessage.SEVERITY_ERROR, "Property group creation failed.", newPropertyGroupName));
    }
}
 
开发者ID:ErinDavid,项目名称:elastic-config,代码行数:23,代码来源:PropertyGroupManagedBean.java

示例8: create

import org.apache.curator.utils.ZKPaths; //导入方法依赖的package包/类
private Service create(final String name, final EventSource eventSource, final boolean replicateOutbound, final Duration sleepWhenIdle) {
    final Function<Multimap<String, ByteBuffer>, Void> eventSink = new Function<Multimap<String, ByteBuffer>, Void>() {
        @Override
        public Void apply(@Nullable Multimap<String, ByteBuffer> eventsByChannel) {
            _eventStore.addAll(eventsByChannel);
            return null;
        }
    };
    final Supplier<Iterable<OwnedSubscription>> subscriptionsSupplier = () -> _subscriptionDao.getAllSubscriptions();

    LeaderService leaderService = new LeaderService(
            _curator, ZKPaths.makePath("/leader/fanout", name), _selfId, "LeaderSelector-" + name, 1, TimeUnit.MINUTES,
            new Supplier<Service>() {
                @Override
                public Service get() {
                    return new DefaultFanout(name, eventSource, eventSink, replicateOutbound, sleepWhenIdle,
                            subscriptionsSupplier, _dataCenters.getSelf(), _logFactory, _subscriptionEvaluator,
                            _metricRegistry, _clock);
                }
            });
    ServiceFailureListener.listenTo(leaderService, _metricRegistry);
    _dropwizardTask.register("databus-fanout-" + name, leaderService);
    return leaderService;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:25,代码来源:DefaultFanoutManager.java

示例9: takeBucketOwnership

import org.apache.curator.utils.ZKPaths; //导入方法依赖的package包/类
@Override
public CompletableFuture<Boolean> takeBucketOwnership(int bucket, String processId, Executor executor) {
    Preconditions.checkArgument(bucket < bucketCount);

    // try creating an ephemeral node
    String bucketPath = ZKPaths.makePath(ZKStoreHelper.BUCKET_OWNERSHIP_PATH, String.valueOf(bucket));

    return storeHelper.createEphemeralZNode(bucketPath, SerializationUtils.serialize(processId))
            .thenCompose(created -> {
                if (!created) {
                    // Note: data may disappear by the time we do a getData. Let exception be thrown from here
                    // so that caller may retry.
                    return storeHelper.getData(bucketPath)
                            .thenApply(data -> (SerializationUtils.deserialize(data.getData())).equals(processId));
                } else {
                    return CompletableFuture.completedFuture(true);
                }
            });
}
 
开发者ID:pravega,项目名称:pravega,代码行数:20,代码来源:ZKStreamMetadataStore.java

示例10: ZkRangeStore

import org.apache.curator.utils.ZKPaths; //导入方法依赖的package包/类
public ZkRangeStore(String clientName, CuratorFramework client, String lockPath, String sequencePath, long time, TimeUnit unit,
                    long initialValue, int rangeSize) {
	this.clientName = clientName;
	this.client = client;
	this.initialValue = initialValue;
	this.rangeSize = rangeSize;
	lockPath = ZKPaths.makePath(lockPath, clientName);
	this.sequencePath = ZKPaths.makePath(sequencePath, clientName);
	this.time = time;
	this.unit = unit;
	this.lock = new InterProcessMutex(client, lockPath);
}
 
开发者ID:mm23504570,项目名称:snowflake,代码行数:13,代码来源:ZkRangeStore.java

示例11: getFullPath

import org.apache.curator.utils.ZKPaths; //导入方法依赖的package包/类
@Override
public String getFullPath(String type, String... extras)
{
	String path = getParentPath(type);
	for( String child : extras )
	{
		path = ZKPaths.makePath(path, child);
	}
	return path;
}
 
开发者ID:equella,项目名称:Equella,代码行数:11,代码来源:ZookeeperServiceImpl.java

示例12: AgentManager

import org.apache.curator.utils.ZKPaths; //导入方法依赖的package包/类
public AgentManager(String zkHost, int zkTimeout, String zone, String name) throws IOException {
    this.zkHost = zkHost;
    this.zkTimeout = zkTimeout;

    this.zkClient = new ZKClient(zkHost, ZK_RETRY_PERIOD, ZK_RECONNECT_TIME);
    this.zone = zone;
    this.name = name;
    this.zonePath = ZKPaths.makePath(Config.ZK_ROOT, this.zone);
    this.nodePath = ZKPaths.makePath(this.zonePath, this.name);
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:11,代码来源:AgentManager.java

示例13: loadAgentConfig

import org.apache.curator.utils.ZKPaths; //导入方法依赖的package包/类
/**
 * connect to zk server to load config from zone data
 */
public static AgentSettings loadAgentConfig(String zkHost, String zoneName, int retry) {
    try (ZKClient zkClient = new ZKClient(zkHost, 1000, retry)) {
        zkClient.start();

        String zonePath = ZKPaths.makePath(ZK_ROOT, zoneName);
        byte[] raw = zkClient.getData(zonePath);
        return Jsonable.parse(raw, AgentSettings.class);

    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:16,代码来源:Config.java

示例14: should_agent_registered

import org.apache.curator.utils.ZKPaths; //导入方法依赖的package包/类
@Test
public void should_agent_registered() throws Throwable {
    // when: start agent in thread
    AgentManager agent = new AgentManager(server.getConnectString(), 20000, ZONE, MACHINE);
    new Thread(agent).start();
    Thread.sleep(5000); // wait for agent registration

    // when:
    String agentNodePath = ZKPaths.makePath(ZK_ROOT, ZONE, MACHINE);
    Assert.assertEquals(true, zkClient.exist(agentNodePath));
    agent.stop();
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:13,代码来源:AgentManagerTest.java

示例15: registerServiceInstance

import org.apache.curator.utils.ZKPaths; //导入方法依赖的package包/类
public void registerServiceInstance(String region,
                                    String availabilityZone,
                                    String flavor,
                                    String serviceName,
                                    int servicePort,
                                    String serviceAddress,
                                    String serviceAddressV6,
                                    String weight) 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, new HashMap<String, String>() {{
        put("ipv4Address", serviceAddress);
        put("ipv6Address", serviceAddressV6);
        if (weight != null) {
            put("weight", weight);
        }
    }});

    try {
        JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<>(MetaData.class);
        byte[] bytes = serializer.serialize(service);
        String path = ZKPaths.makePath(ZKPaths.makePath(regPath, service.getName()), service.getId());

        if ( ! connector.isPathExists(path)) {
            connector.createEphemeral(path);
            connector.save(new String(bytes), path);
        } else {
            log.warn("Node " + path + " already exists");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:35,代码来源:TestServiceUtil.java


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