gpt4 book ai didi

org.apache.bookkeeper.zookeeper.ZooKeeperClient.newBuilder()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 03:39:31 29 4
gpt4 key购买 nike

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

ZooKeeperClient.newBuilder介绍

暂无

代码示例

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

@SuppressWarnings("deprecation")
public ManagedLedgerFactoryImpl(ClientConfiguration bkClientConfiguration, ManagedLedgerFactoryConfig config)
    throws Exception {
  this(ZooKeeperClient.newBuilder()
      .connectString(bkClientConfiguration.getZkServers())
      .sessionTimeoutMs(bkClientConfiguration.getZkTimeout())
      .build(), bkClientConfiguration, config);
}

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

public void startServer() throws Exception {
  // create a ZooKeeper server(dataDir, dataLogDir, port)
  LOG.debug("Running ZK server");
  // ServerStats.registerAsConcrete();
  ClientBase.setupTestEnv();
  ZkTmpDir = File.createTempFile("zookeeper", "test");
  ZkTmpDir.delete();
  ZkTmpDir.mkdir();
  zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
  serverFactory = new NIOServerCnxnFactory();
  serverFactory.configure(zkaddr, 100);
  serverFactory.startup(zks);
  boolean b = ClientBase.waitForServerUp(getZooKeeperConnectString(), ClientBase.CONNECTION_TIMEOUT);
  LOG.debug("Server up: " + b);
  // create a zookeeper client
  LOG.debug("Instantiate ZK Client");
  zkc = ZooKeeperClient.newBuilder().connectString(getZooKeeperConnectString()).build();
  // initialize the zk client with values
  zkc.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
  zkc.create("/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}

代码示例来源:origin: twitter/distributedlog

new BoundExponentialBackoffRetryPolicy(sessionTimeoutMs, sessionTimeoutMs, 0) :
    new BoundExponentialBackoffRetryPolicy(sessionTimeoutMs, sessionTimeoutMs, Integer.MAX_VALUE);
zk = org.apache.bookkeeper.zookeeper.ZooKeeperClient.newBuilder()
    .connectString(zooKeeperServers)
    .sessionTimeoutMs(sessionTimeoutMs)

代码示例来源:origin: pravega/pravega

private void initializeZookeeper() throws Exception {
  log.info("Formatting ZooKeeper ...");
  if (this.secureZK) {
    ZKTLSUtils.setSecureZKClientProperties(this.tlsTrustStore, JKSHelper.loadPasswordFrom(this.tLSKeyStorePasswordPath));
  }
  @Cleanup
  val zkc = ZooKeeperClient.newBuilder()
               .connectString(LOOPBACK_ADDRESS.getHostAddress() + ":" + this.zkPort)
               .sessionTimeoutMs(10000)
               .build();
  String znode;
  StringBuilder znodePath = new StringBuilder();
  for (String z : this.ledgersPath.split("/")) {
    znodePath.append(z);
    znode = znodePath.toString();
    if (!znode.isEmpty()) {
      zkc.create(znode, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    }
    znodePath.append("/");
  }
  znodePath.append("available");
  zkc.create(znodePath.toString(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

private BKHttpServiceProvider(BookieServer bookieServer,
               AutoRecoveryMain autoRecovery,
               ServerConfiguration serverConf,
               StatsProvider statsProvider)
  throws IOException, KeeperException, InterruptedException, BKException {
  this.bookieServer = bookieServer;
  this.autoRecovery = autoRecovery;
  this.serverConf = serverConf;
  this.statsProvider = statsProvider;
  String zkServers = ZKMetadataDriverBase.resolveZkServers(serverConf);
  this.zk = ZooKeeperClient.newBuilder()
   .connectString(zkServers)
   .sessionTimeoutMs(serverConf.getZkTimeout())
   .build();
  ClientConfiguration clientConfiguration = new ClientConfiguration(serverConf);
  this.bka = new BookKeeperAdmin(clientConfiguration);
  this.executor = Executors.newSingleThreadExecutor(
   new ThreadFactoryBuilder().setNameFormat("BKHttpServiceThread").setDaemon(true).build());
}

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

@SuppressWarnings("deprecation")
private void initializeZookeeper(String zkHost, int zkPort) throws IOException {
  LOG.info("Instantiate ZK Client");
  //initialize the zk client with values
  try (ZooKeeperClient zkc = ZooKeeperClient.newBuilder()
        .connectString(zkHost + ":" + zkPort)
        .sessionTimeoutMs(zkSessionTimeOut)
        .build()) {
    List<Op> multiOps = Lists.newArrayListWithExpectedSize(3);
    String zkLedgersRootPath = ZKMetadataDriverBase.resolveZkLedgersRootPath(baseConf);
    multiOps.add(
      Op.create(zkLedgersRootPath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
    multiOps.add(
      Op.create(zkLedgersRootPath + "/" + AVAILABLE_NODE,
        new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
    multiOps.add(
      Op.create(zkLedgersRootPath + "/" + AVAILABLE_NODE + "/" + READONLY,
        new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
    zkc.multi(multiOps);
    // No need to create an entry for each requested bookie anymore as the
    // BookieServers will register themselves with ZooKeeper on startup.
  } catch (KeeperException e) {
    LOG.error("Exception while creating znodes", e);
    throw new IOException("Error creating znodes : ", e);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    LOG.error("Interrupted while creating znodes", e);
    throw new IOException("Error creating znodes : ", e);
  }
}

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

@Override
  public CompletableFuture<ZooKeeper> create(String serverList, SessionType sessionType, int zkSessionTimeoutMillis) {
    CompletableFuture<ZooKeeper> future = new CompletableFuture<>();

    executor.execute(safeRun(() -> {
      try {
        ZooKeeper zk = ZooKeeperClient.newBuilder().connectString(serverList)
            .sessionTimeoutMs(zkSessionTimeoutMillis)
            .connectRetryPolicy(new BoundExponentialBackoffRetryPolicy(zkSessionTimeoutMillis,
                zkSessionTimeoutMillis, 0))
            .build();

        if (zk.getState() == States.CONNECTEDREADONLY && sessionType != SessionType.AllowReadOnly) {
          future.completeExceptionally(new IllegalStateException("Cannot use a read-only session"));
        }

        log.info("ZooKeeper session established: {}", zk);
        future.complete(zk);
      } catch (IOException | KeeperException | InterruptedException exception) {
        log.error("Failed to establish ZooKeeper session: {}", exception.getMessage());
        future.completeExceptionally(exception);
      }
    }, throwable -> {
      future.completeExceptionally(throwable);
    }));

    return future;
  }
}

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

@VisibleForTesting
static ZooKeeperClient createConnectedZooKeeperClient(
    String connectString, int sessionTimeoutMs, Set<Watcher> childWatchers,
    RetryPolicy operationRetryPolicy)
        throws KeeperException, InterruptedException, IOException {
  return ZooKeeperClient.newBuilder()
      .connectString(connectString)
      .sessionTimeoutMs(sessionTimeoutMs)
      .watchers(childWatchers)
      .operationRetryPolicy(operationRetryPolicy)
      .build();
}

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

@Override
  int runCmd(CommandLine cmdLine) throws Exception {
    ZooKeeper zk = null;
    try {
      String metadataServiceUri = bkConf.getMetadataServiceUri();
      String zkServers = ZKMetadataDriverBase.getZKServersFromServiceUri(URI.create(metadataServiceUri));
      zk = ZooKeeperClient.newBuilder()
          .connectString(zkServers)
          .sessionTimeoutMs(bkConf.getZkTimeout())
          .build();
      BookieSocketAddress bookieId = AuditorElector.getCurrentAuditor(bkConf, zk);
      if (bookieId == null) {
        LOG.info("No auditor elected");
        return -1;
      }
      LOG.info("Auditor: " + getBookieSocketAddrStringRepresentation(bookieId));
    } finally {
      if (zk != null) {
        zk.close();
      }
    }
    return 0;
  }
}

代码示例来源:origin: org.apache.pulsar/managed-ledger-original

@SuppressWarnings("deprecation")
public ManagedLedgerFactoryImpl(ClientConfiguration bkClientConfiguration, ManagedLedgerFactoryConfig config)
    throws Exception {
  this(ZooKeeperClient.newBuilder()
      .connectString(bkClientConfiguration.getZkServers())
      .sessionTimeoutMs(bkClientConfiguration.getZkTimeout())
      .build(), bkClientConfiguration, config);
}

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

- lastOverReplicatedLedgerGcTimeMillis > gcOverReplicatedLedgerIntervalMillis);
if (checkOverreplicatedLedgers) {
  zk = ZooKeeperClient.newBuilder().connectString(zkServers)
      .sessionTimeoutMs(conf.getZkTimeout()).build();

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

this.zk = ZooKeeperClient.newBuilder()
  .connectString(zkServers)
  .sessionTimeoutMs(conf.getZkTimeout())

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

private ZooKeeperCache getAndSetZkCache(Configuration conf) {
  ZooKeeperCache zkCache = null;
  if (conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) != null) {
    zkCache = (ZooKeeperCache) conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE);
  } else {
    int zkTimeout;
    String zkServers;
    if (conf instanceof ClientConfiguration) {
      zkTimeout = ((ClientConfiguration) conf).getZkTimeout();
      zkServers = ((ClientConfiguration) conf).getZkServers();
      try {
        ZooKeeper zkClient = ZooKeeperClient.newBuilder().connectString(zkServers)
            .sessionTimeoutMs(zkTimeout).build();
        zkCache = new ZooKeeperCache(zkClient) {
        };
        conf.addProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, zkCache);
      } catch (Exception e) {
        LOG.error("Error creating zookeeper client", e);
      }
    } else {
      LOG.error("No zk configurations available");
    }
  }
  return zkCache;
}

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

private ZooKeeperDataCache<BookiesRackConfiguration> getAndSetZkCache(Configuration conf) {
  ZooKeeperCache zkCache = null;
  if (conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) != null) {
    zkCache = (ZooKeeperCache) conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE);
  } else {
    int zkTimeout;
    String zkServers;
    if (conf instanceof ClientConfiguration) {
      zkTimeout = ((ClientConfiguration) conf).getZkTimeout();
      zkServers = ((ClientConfiguration) conf).getZkServers();
      try {
        ZooKeeper zkClient = ZooKeeperClient.newBuilder().connectString(zkServers)
            .sessionTimeoutMs(zkTimeout).build();
        zkCache = new ZooKeeperCache(zkClient) {
        };
        conf.addProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, zkCache);
      } catch (Exception e) {
        LOG.error("Error creating zookeeper client", e);
      }
    } else {
      LOG.error("No zk configurations available");
    }
  }
  ZooKeeperDataCache<BookiesRackConfiguration> zkDataCache = getZkBookieRackMappingCache(
      zkCache);
  if (zkDataCache != null) {
    zkDataCache.registerListener(this);
  }
  return zkDataCache;
}

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

? new BoundExponentialBackoffRetryPolicy(sessionTimeoutMs, sessionTimeoutMs, 0) :
    new BoundExponentialBackoffRetryPolicy(sessionTimeoutMs, sessionTimeoutMs, Integer.MAX_VALUE);
zk = org.apache.bookkeeper.zookeeper.ZooKeeperClient.newBuilder()
    .connectString(zooKeeperServers)
    .sessionTimeoutMs(sessionTimeoutMs)

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