gpt4 book ai didi

org.apache.twill.zookeeper.ZKClientService类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 20:30:40 26 4
gpt4 key购买 nike

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

ZKClientService介绍

[英]A ZKClient that extends from Service to provide lifecycle management functions. The #start() method needed to be called before calling any other method on this interface. When the client is no longer needed, call #stop() to release any resources that it holds.
[中]从服务扩展到提供生命周期管理功能的客户机。在调用此接口上的任何其他方法之前,需要调用#start()方法。当不再需要客户端时,调用#stop()释放它所拥有的任何资源。

代码示例

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

public void start() {
  zkClient.startAndWait();
}

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

@Override
public void close() throws IOException {
  zkClient.stopAndWait();
}

代码示例来源:origin: org.apache.twill/twill-zookeeper

@Override
public Supplier<ZooKeeper> getZooKeeperSupplier() {
 return delegate.getZooKeeperSupplier();
}

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

@Override
 public Cancellable register(Discoverable discoverable) {
  if (!zkClient.isRunning()) {
   zkClient.startAndWait();
  }
  return delegate.register(discoverable);
 }
};

代码示例来源:origin: caskdata/cdap

@Override
protected final void startUp() throws Exception {
 zkClientService.startAndWait();
 try {
  delegate.startAndWait();
 } catch (Exception e) {
  try {
   zkClientService.stopAndWait();
  } catch (Exception se) {
   e.addSuppressed(se);
  }
  throw e;
 }
}

代码示例来源:origin: caskdata/coopr

for (int i = 0; i < 2; i++) {
  ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
  zkClient.startAndWait();
 KillZKSession.kill(zkClients.get(follower).getZooKeeperSupplier().get(),
           zkClients.get(follower).getConnectString(), 10000);
} finally {
 for (ZKClientService zkClient : zkClients) {
  zkClient.stopAndWait();

代码示例来源:origin: cdapio/cdap

zkClientService.startAndWait();
Assert.assertTrue(zkClientService.isRunning());
Assert.assertTrue(zkClientService.isRunning());
zkClientService.stopAndWait();

代码示例来源:origin: cdapio/cdap

@Test
public void testCreateOrSet() throws Exception {
 String path = "/parent/testCreateOrSet";
 ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
 zkClient.startAndWait();
 // Create with "1"
 Assert.assertEquals(1, ZKExtOperations.createOrSet(zkClient, path,
                           Suppliers.ofInstance(1), INT_CODEC, 0).get().intValue());
 // Should get "1" back
 Assert.assertEquals(1, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
 // Set with "2"
 Assert.assertEquals(2, ZKExtOperations.createOrSet(zkClient, path,
                           Suppliers.ofInstance(2), INT_CODEC, 0).get().intValue());
 // Should get "2" back
 Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
 zkClient.stopAndWait();
}

代码示例来源:origin: cdapio/cdap

@Before
public void beforeTest() throws Exception {
 zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build();
 zkServer.startAndWait();
 CConfiguration cConf = CConfiguration.create();
 String kafkaZKNamespace = cConf.get(KafkaConstants.ConfigKeys.ZOOKEEPER_NAMESPACE_CONFIG);
 kafkaZKConnect = zkServer.getConnectionStr();
 if (kafkaZKNamespace != null) {
  ZKClientService zkClient = new DefaultZKClientService(zkServer.getConnectionStr(), 2000, null,
                             ImmutableMultimap.<String, byte[]>of());
  zkClient.startAndWait();
  zkClient.create("/" + kafkaZKNamespace, null, CreateMode.PERSISTENT);
  zkClient.stopAndWait();
  kafkaZKConnect += "/" + kafkaZKNamespace;
 }
 kafkaServer = createKafkaServer(kafkaZKConnect, TEMP_FOLDER.newFolder());
 kafkaServer.startAndWait();
}

代码示例来源:origin: org.apache.twill/twill-yarn

private void startUp() throws Exception {
 zkClientService.startAndWait();
 ZKOperations.ignoreError(zkClientService.create("/", null, CreateMode.PERSISTENT),
              KeeperException.NodeExistsException.class, null).get();

代码示例来源:origin: cdapio/cdap

client.create(path, null, CreateMode.PERSISTENT),
  KeeperException.NodeExistsException.class, path).get();
 client.stopAndWait();
 zkConnectStr = String.format("%s/%s", zkConnectStr, zkNamespace);
} catch (Exception e) {
 throw Throwables.propagate(e);
} finally {
 client.stopAndWait();

代码示例来源:origin: caskdata/tephra

private void expireZkSession(ZKClientService zkClientService) throws Exception {
 ZooKeeper zooKeeper = zkClientService.getZooKeeperSupplier().get();
 final SettableFuture<?> connectFuture = SettableFuture.create();
 Watcher watcher = new Watcher() {
  @Override
  public void process(WatchedEvent event) {
   if (event.getState() == Event.KeeperState.SyncConnected) {
    connectFuture.set(null);
   }
  }
 };
 // Create another Zookeeper session with the same sessionId so that the original one expires.
 final ZooKeeper dupZookeeper =
  new ZooKeeper(zkClientService.getConnectString(), zooKeeper.getSessionTimeout(), watcher,
         zooKeeper.getSessionId(), zooKeeper.getSessionPasswd());
 connectFuture.get(30, TimeUnit.SECONDS);
 Assert.assertEquals("Failed to re-create current session", dupZookeeper.getState(), ZooKeeper.States.CONNECTED);
 dupZookeeper.close();
}

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

@Override
public boolean isRunning() {
 return delegate.isRunning();
}

代码示例来源:origin: org.apache.twill/twill-yarn

return new YarnTwillPreparer(config, twillSpec, runId, zkClientService.getConnectString(),
               appLocation, jvmOptions, locationCache, new YarnTwillControllerFactory() {
 @Override

代码示例来源:origin: cdapio/cdap

@Override
public void start() throws Exception {
 logAppenderInitializer.initialize();
 resetShutdownTime();
 createDirectory("twill");
 createSystemHBaseNamespace();
 updateConfigurationTable();
 Services.startAndWait(zkClient, cConf.getLong(Constants.Zookeeper.CLIENT_STARTUP_TIMEOUT_MILLIS),
            TimeUnit.MILLISECONDS,
            String.format("Connection timed out while trying to start ZooKeeper client. Please " +
                    "verify that the ZooKeeper quorum settings are correct in cdap-site.xml. " +
                    "Currently configured as: %s", cConf.get(Constants.Zookeeper.QUORUM)));
 // Tries to create the ZK root node (which can be namespaced through the zk connection string)
 Futures.getUnchecked(ZKOperations.ignoreError(zkClient.create("/", null, CreateMode.PERSISTENT),
                        KeeperException.NodeExistsException.class, null));
 electionInfoService.startAndWait();
 leaderElection.startAndWait();
}

代码示例来源:origin: co.cask.cdap/cdap-common

@Override
protected final void startUp() throws Exception {
 zkClientService.startAndWait();
 try {
  delegate.startAndWait();
 } catch (Exception e) {
  try {
   zkClientService.stopAndWait();
  } catch (Exception se) {
   e.addSuppressed(se);
  }
  throw e;
 }
}

代码示例来源:origin: caskdata/cdap

zkClient1.startAndWait();
zkClient2.startAndWait();
KillZKSession.kill(zkClient1.getZooKeeperSupplier().get(), zkClient1.getConnectString(), 10000);
zkClient1.stopAndWait();
zkClient2.stopAndWait();

代码示例来源:origin: cdapio/cdap

zkClientService.startAndWait();
Assert.assertTrue(zkClientService.isRunning());
Assert.assertTrue(zkClientService.isRunning());
zkClientService.stopAndWait();

代码示例来源:origin: co.cask.tephra/tephra-core

@Override
 public Cancellable register(Discoverable discoverable) {
  if (!zkClient.isRunning()) {
   zkClient.startAndWait();
  }
  return delegate.register(discoverable);
 }
};

代码示例来源:origin: cdapio/cdap

@Test
public void testSetOrCreate() throws Exception {
 String path = "/parent/testSetOrCreate";
 ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
 zkClient.startAndWait();
 // Create with "1"
 Assert.assertEquals(1, ZKExtOperations.setOrCreate(zkClient, path,
                           Suppliers.ofInstance(1), INT_CODEC, 0).get().intValue());
 // Should get "1" back
 Assert.assertEquals(1, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
 // Set with "2"
 Assert.assertEquals(2, ZKExtOperations.setOrCreate(zkClient, path,
                           Suppliers.ofInstance(2), INT_CODEC, 0).get().intValue());
 // Should get "2" back
 Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
 zkClient.stopAndWait();
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com