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


Java ZkClient.createPersistent方法代码示例

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


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

示例1: beforeTest

import org.apache.helix.manager.zk.ZkClient; //导入方法依赖的package包/类
@BeforeTest
public void beforeTest() {
  ZkStarter.startLocalZkServer();

  _zkClient =
      new ZkClient(StringUtil.join("/", StringUtils.chomp(ZkStarter.DEFAULT_ZK_STR, "/")),
          ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
  String helixClusterName = "TestTimeBoundaryService";
  _zkClient.deleteRecursive("/" + helixClusterName + "/PROPERTYSTORE");
  _zkClient.createPersistent("/" + helixClusterName + "/PROPERTYSTORE", true);
  _propertyStore =
      new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_zkClient), "/" + helixClusterName
          + "/PROPERTYSTORE", null);

}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:16,代码来源:TimeBoundaryServiceTest.java

示例2: post

import org.apache.helix.manager.zk.ZkClient; //导入方法依赖的package包/类
public void post(String zkServer, Message message, String clusterName, String instanceName) {
  ZkClient client = new ZkClient(zkServer);
  client.setZkSerializer(new ZNRecordSerializer());
  String path = PropertyPathBuilder.instanceMessage(clusterName, instanceName, message.getId());
  client.delete(path);
  ZNRecord record = client.readData(PropertyPathBuilder.liveInstance(clusterName, instanceName));
  message.setTgtSessionId(record.getSimpleField(LiveInstanceProperty.SESSION_ID.toString()));
  message.setTgtName(record.getId());
  // System.out.println(message);
  client.createPersistent(path, message.getRecord());
}
 
开发者ID:apache,项目名称:helix,代码行数:12,代码来源:MessagePoster.java

示例3: setNodes

import org.apache.helix.manager.zk.ZkClient; //导入方法依赖的package包/类
private void setNodes(ZkClient zkClient, String root, char c, boolean needTimestamp) {
  char[] data = new char[bufSize];

  for (int i = 0; i < bufSize; i++) {
    data[i] = c;
  }

  Map<String, String> map = new TreeMap<String, String>();
  for (int i = 0; i < mapNr; i++) {
    map.put("key_" + i, new String(data));
  }

  for (int i = 0; i < firstLevelNr; i++) {
    String firstLevelKey = getFirstLevelKey(i);

    for (int j = 0; j < secondLevelNr; j++) {
      String nodeId = getNodeId(i, j);
      ZNRecord record = new ZNRecord(nodeId);
      record.setSimpleFields(map);
      if (needTimestamp) {
        long now = System.currentTimeMillis();
        record.setSimpleField("SetTimestamp", Long.toString(now));
      }
      String key = getSecondLevelKey(i, j);
      try {
        zkClient.writeData(root + key, record);
      } catch (ZkNoNodeException e) {
        zkClient.createPersistent(root + firstLevelKey, true);
        zkClient.createPersistent(root + key, record);
      }
    }
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:34,代码来源:TestZkHelixPropertyStore.java

示例4: beforeTest

import org.apache.helix.manager.zk.ZkClient; //导入方法依赖的package包/类
@BeforeTest
public void beforeTest() {
  _zookeeperInstance = ZkStarter.startLocalZkServer();

  _zkClient = new ZkClient(StringUtil.join("/", StringUtils.chomp(ZkStarter.DEFAULT_ZK_STR, "/")),
      ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
  String helixClusterName = "TestTimeBoundaryService";
  _zkClient.deleteRecursive("/" + helixClusterName + "/PROPERTYSTORE");
  _zkClient.createPersistent("/" + helixClusterName + "/PROPERTYSTORE", true);
  _propertyStore = new ZkHelixPropertyStore<>(new ZkBaseDataAccessor<ZNRecord>(_zkClient),
      "/" + helixClusterName + "/PROPERTYSTORE", null);
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:13,代码来源:TimeBoundaryServiceTest.java

示例5: testWatchRemove

import org.apache.helix.manager.zk.ZkClient; //导入方法依赖的package包/类
/**
 * after calling zkclient#unsubscribeXXXListener()
 * an already registered watch will not be removed from ZooKeeper#watchManager#XXXWatches
 * immediately.
 * the watch will get removed on the following conditions:
 * 1) there is a set/delete on the listening path via the zkclient
 * 2) session expiry on the zkclient (i.e. the watch will not be renewed after session expiry)
 * @throws Exception
 */
@Test
public void testWatchRemove() throws Exception {
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String testName = className + "_" + methodName;

  final ZkClient client =
      new ZkClient(ZK_ADDR, ZkClient.DEFAULT_SESSION_TIMEOUT,
          ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
  // make sure "/testName/test" doesn't exist
  final String path = "/" + testName + "/test";
  client.createPersistent(path, true);

  ZkListener listener = new ZkListener();
  client.subscribeDataChanges(path, listener);
  client.subscribeChildChanges(path, listener);

  // listener should be in both ZkClient#_dataListener and ZkClient#_childListener set
  Map<String, Set<IZkDataListener>> dataListenerMap = ZkTestHelper.getZkDataListener(client);
  Assert.assertEquals(dataListenerMap.size(), 1, "ZkClient#_dataListener should have 1 listener");
  Set<IZkDataListener> dataListenerSet = dataListenerMap.get(path);
  Assert.assertNotNull(dataListenerSet, "ZkClient#_dataListener should have 1 listener on path: "
      + path);
  Assert.assertEquals(dataListenerSet.size(), 1,
      "ZkClient#_dataListener should have 1 listener on path: " + path);

  Map<String, Set<IZkChildListener>> childListenerMap = ZkTestHelper.getZkChildListener(client);
  Assert.assertEquals(childListenerMap.size(), 1,
      "ZkClient#_childListener should have 1 listener");
  Set<IZkChildListener> childListenerSet = childListenerMap.get(path);
  Assert.assertNotNull(childListenerSet,
      "ZkClient#_childListener should have 1 listener on path: " + path);
  Assert.assertEquals(childListenerSet.size(), 1,
      "ZkClient#_childListener should have 1 listener on path: " + path);

  // watch should be in ZooKeeper#watchManager#XXXWatches
  Map<String, List<String>> watchMap = ZkTestHelper.getZkWatch(client);
  // System.out.println("watchMap1: " + watchMap);
  List<String> dataWatch = watchMap.get("dataWatches");
  Assert.assertNotNull(dataWatch,
      "ZooKeeper#watchManager#dataWatches should have 1 data watch on path: " + path);
  Assert.assertEquals(dataWatch.size(), 1,
      "ZooKeeper#watchManager#dataWatches should have 1 data watch on path: " + path);
  Assert.assertEquals(dataWatch.get(0), path,
      "ZooKeeper#watchManager#dataWatches should have 1 data watch on path: " + path);

  List<String> childWatch = watchMap.get("childWatches");
  Assert.assertNotNull(childWatch,
      "ZooKeeper#watchManager#childWatches should have 1 child watch on path: " + path);
  Assert.assertEquals(childWatch.size(), 1,
      "ZooKeeper#watchManager#childWatches should have 1 child watch on path: " + path);
  Assert.assertEquals(childWatch.get(0), path,
      "ZooKeeper#watchManager#childWatches should have 1 child watch on path: " + path);

  client.unsubscribeDataChanges(path, listener);
  client.unsubscribeChildChanges(path, listener);
  // System.out.println("watchMap2: " + watchMap);
  ZkTestHelper.expireSession(client);

  // after session expiry, those watches should be removed
  watchMap = ZkTestHelper.getZkWatch(client);
  // System.out.println("watchMap3: " + watchMap);
  dataWatch = watchMap.get("dataWatches");
  Assert.assertTrue(dataWatch.isEmpty(), "ZooKeeper#watchManager#dataWatches should be empty");
  childWatch = watchMap.get("childWatches");
  Assert.assertTrue(childWatch.isEmpty(), "ZooKeeper#watchManager#childWatches should be empty");

  client.close();
}
 
开发者ID:apache,项目名称:helix,代码行数:79,代码来源:TestZkBasis.java


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