org.I0Itec.zkclient.ZkClient.waitUntilExists()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中org.I0Itec.zkclient.ZkClient.waitUntilExists()方法的一些代码示例,展示了ZkClient.waitUntilExists()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkClient.waitUntilExists()方法的具体详情如下:
包路径:org.I0Itec.zkclient.ZkClient
类名称:ZkClient
方法名:waitUntilExists

ZkClient.waitUntilExists介绍

暂无

代码示例

代码示例来源:origin: apache/samza

@Override
public void await(long timeout, TimeUnit timeUnit) throws TimeoutException {
 // waitUntilExists signals timeout by returning false as opposed to throwing exception. We internally need to map
 // the non-existence to a TimeoutException in order to respect the contract defined in Latch interface
 boolean targetPathExists = zkUtils.getZkClient().waitUntilExists(targetPath, timeUnit, timeout);
 if (!targetPathExists) {
  throw new TimeoutException("Timed out waiting for the targetPath");
 }
}

代码示例来源:origin: org.apache.samza/samza-core

@Override
public void await(long timeout, TimeUnit timeUnit) throws TimeoutException {
 // waitUntilExists signals timeout by returning false as opposed to throwing exception. We internally need to map
 // the non-existence to a TimeoutException in order to respect the contract defined in Latch interface
 boolean targetPathExists = zkUtils.getZkClient().waitUntilExists(targetPath, timeUnit, timeout);
 if (!targetPathExists) {
  throw new TimeoutException("Timed out waiting for the targetPath");
 }
}

代码示例来源:origin: org.apache.samza/samza-core_2.10

@Override
public void await(long timeout, TimeUnit timeUnit) throws TimeoutException {
 // waitUntilExists signals timeout by returning false as opposed to throwing exception. We internally need to map
 // the non-existence to a TimeoutException in order to respect the contract defined in Latch interface
 boolean targetPathExists = zkUtils.getZkClient().waitUntilExists(targetPath, timeUnit, timeout);
 if (!targetPathExists) {
  throw new TimeoutException("Timed out waiting for the targetPath");
 }
}

代码示例来源:origin: org.apache.samza/samza-core_2.11

@Override
public void await(long timeout, TimeUnit timeUnit) throws TimeoutException {
 // waitUntilExists signals timeout by returning false as opposed to throwing exception. We internally need to map
 // the non-existence to a TimeoutException in order to respect the contract defined in Latch interface
 boolean targetPathExists = zkUtils.getZkClient().waitUntilExists(targetPath, timeUnit, timeout);
 if (!targetPathExists) {
  throw new TimeoutException("Timed out waiting for the targetPath");
 }
}

代码示例来源:origin: org.apache.samza/samza-core_2.12

@Override
public void await(long timeout, TimeUnit timeUnit) throws TimeoutException {
 // waitUntilExists signals timeout by returning false as opposed to throwing exception. We internally need to map
 // the non-existence to a TimeoutException in order to respect the contract defined in Latch interface
 boolean targetPathExists = zkUtils.getZkClient().waitUntilExists(targetPath, timeUnit, timeout);
 if (!targetPathExists) {
  throw new TimeoutException("Timed out waiting for the targetPath");
 }
}

代码示例来源:origin: ezbz/projectx

@Override
public ZNode createPersistent(final String path) {
 final String[] parts = StringUtils.split(path, ZookeeperConstants.PATH_SEPARATOR);
 final StringBuilder sb = new StringBuilder();
 for (int i = 0; i < parts.length; i++) {
  sb.append(ZookeeperConstants.PATH_SEPARATOR).append(parts[i]);
  final String pathPart = sb.toString();
  if (!zkClient.exists(pathPart)) {
   zkClient.createPersistent(pathPart);
   final boolean created = zkClient.waitUntilExists(pathPart, TimeUnit.SECONDS,
     nodeCreationTimeoutSeconds);
   if (!created) {
    throw new ZkNoNodeException("Persistent root node not created after "
      + nodeCreationTimeoutSeconds + " seconds, cannot proceed");
   }
  }
 }
 return new ZNodeImpl(path);
}

代码示例来源:origin: ezbz/projectx

@Test
public void test_createPersistentRootExists() {
 when(zkClient.exists(projectx_PATH)).thenReturn(true);
 when(zkClient.exists(ROOT_PATH)).thenReturn(true);
 when(zkClient.waitUntilExists(projectx_PATH, TimeUnit.SECONDS, 5)).thenReturn(true);
 when(zkClient.waitUntilExists(ROOT_PATH, TimeUnit.SECONDS, 5)).thenReturn(true);
 classUnderTest.createPersistent(ROOT_PATH);
 verify(zkClient).exists(projectx_PATH);
 verify(zkClient).exists(ROOT_PATH);
 verify(zkClient, times(0)).createPersistent(projectx_PATH);
 verify(zkClient, times(0)).createPersistent(ROOT_PATH);
 verify(zkClient, times(0)).waitUntilExists(ROOT_PATH, TimeUnit.SECONDS, 5);
}

代码示例来源:origin: ezbz/projectx

@Test(expected = ZkNoNodeException.class)
public void test_createEphemeralSequentialFailure() {
 when(zkClient.waitUntilExists(EPHEMERAL_NODE, TimeUnit.SECONDS, 5)).thenReturn(false);
 classUnderTest.createEphemeralSequential(ROOT_PATH);
}

代码示例来源:origin: ezbz/projectx

@Override
public SequentialZNode createEphemeralSequential(final String path, final Object data) {
 final String ephermalPath = path + ZookeeperConstants.PATH_SEPARATOR
   + ZookeeperConstants.EPHERMAL_PREFIX;
 final String nodeName = zkClient.createEphemeralSequential(ephermalPath, formatData(data));
 final boolean created = zkClient.waitUntilExists(nodeName, TimeUnit.SECONDS,
   nodeCreationTimeoutSeconds);
 if (!created) {
  throw new ZkNoNodeException("Ephemeral node not created after " + nodeCreationTimeoutSeconds
    + " seconds, cannot proceed");
 }
 return createNode(path, nodeName, data);
}

代码示例来源:origin: ezbz/projectx

@Test
public void test_createPersistentRootMissing() {
 when(zkClient.exists(projectx_PATH)).thenReturn(false);
 when(zkClient.exists(ROOT_PATH)).thenReturn(false);
 when(zkClient.waitUntilExists(projectx_PATH, TimeUnit.SECONDS, 5)).thenReturn(true);
 when(zkClient.waitUntilExists(ROOT_PATH, TimeUnit.SECONDS, 5)).thenReturn(true);
 classUnderTest.createPersistent(ROOT_PATH);
 verify(zkClient).exists(projectx_PATH);
 verify(zkClient).exists(ROOT_PATH);
 verify(zkClient).createPersistent(projectx_PATH);
 verify(zkClient).createPersistent(ROOT_PATH);
 verify(zkClient).waitUntilExists(projectx_PATH, TimeUnit.SECONDS, 5);
 verify(zkClient).waitUntilExists(ROOT_PATH, TimeUnit.SECONDS, 5);
}

代码示例来源:origin: ezbz/projectx

@Test(expected = ZkNoNodeException.class)
public void test_createPersistentRootMissingFailure() {
 when(zkClient.exists(projectx_PATH)).thenReturn(false);
 when(zkClient.waitUntilExists(projectx_PATH, TimeUnit.SECONDS, 5)).thenReturn(false);
 classUnderTest.createPersistent(ROOT_PATH);
}

代码示例来源:origin: ezbz/projectx

@Test
public void test_createEphemeralSequential() {
 when(zkClient.createEphemeralSequential(EPHEMERAL_PATH, null)).thenReturn(EPHEMERAL_NODE);
 when(zkClient.waitUntilExists(EPHEMERAL_NODE, TimeUnit.SECONDS, 5)).thenReturn(true);
 final SequentialZNode node = classUnderTest.createEphemeralSequential(ROOT_PATH);
 verify(zkClient).createEphemeralSequential(EPHEMERAL_PATH, null);
 verify(zkClient).waitUntilExists(EPHEMERAL_NODE, TimeUnit.SECONDS, 5);
 assertEquals("incorrect sequence", 0, node.getSequence().intValue());
 assertEquals("incorrect path", ROOT_PATH, node.getPath());
 assertEquals("incorrect full path", EPHEMERAL_NODE, node.getFullPath());
}

相关文章