gpt4 book ai didi

org.I0Itec.zkclient.ZkClient类的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 13:48:40 27 4
gpt4 key购买 nike

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

ZkClient介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-dubbo

public ZkClientWrapper(final String serverAddr, long timeout) {
  this.timeout = timeout;
  completableFuture = CompletableFuture.supplyAsync(() -> new ZkClient(serverAddr, Integer.MAX_VALUE));
}

代码示例来源:origin: weibocom/motan

@Override
  public void close() {
    this.zkClient.close();
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

protected String createPersistent(String path, boolean sequential) {
  try {
    if (sequential) {
      return zkClient.createPersistentSequential(path, true);
    } else {
      zkClient.createPersistent(path, true);
      return path;
    }
  } catch (ZkNodeExistsException ignored) {
  }
  return null;
}

代码示例来源:origin: weibocom/motan

private List<String> getChildren(String path) {
  List<String> children = new ArrayList<String>();
  if (zkClient.exists(path)) {
    children = zkClient.getChildren(path);
  }
  return children;
}

代码示例来源:origin: weibocom/motan

private void removeNode(URL url, ZkNodeType nodeType) {
  String nodePath = ZkUtils.toNodePath(url, nodeType);
  if (zkClient.exists(nodePath)) {
    zkClient.delete(nodePath);
  }
}

代码示例来源:origin: apache/incubator-gobblin

Properties props = new Properties();
props.setProperty(KafkaWriterConfigurationKeys.KAFKA_TOPIC, topic);
props.setProperty(KafkaWriterConfigurationKeys.REPLICATION_COUNT, topicReplicationCount);
props.setProperty(KafkaWriterConfigurationKeys.PARTITION_COUNT, topicPartitionCount );
props.setProperty(KafkaWriterConfigurationKeys.CLUSTER_ZOOKEEPER, liveZookeeper);
ZkClient zkClient = new ZkClient(
  liveZookeeper,
  sessionTimeoutMs,
  ZKStringSerializer$.MODULE$);
boolean isSecureKafkaCluster = false;
ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(liveZookeeper), isSecureKafkaCluster);

代码示例来源:origin: apache/incubator-druid

int connectionTimeoutMs = 10000;
 String zkHosts = config.getZookeeperHosts();
 zkClient = new ZkClient(zkHosts, sessionTimeoutMs, connectionTimeoutMs, ZKStringSerializer$.MODULE$);
 zkUtils = new ZkUtils(zkClient, new ZkConnection(zkHosts, sessionTimeoutMs), false);
 if (config.manageKafkaTopic()) {
  int numPartitions = 1;
  int replicationFactor = 1;
  Properties topicConfig = new Properties();
Properties properties = new Properties();
addFilteredProperties(properties);
properties.put("bootstrap.servers", config.getKafkaHost());
LOG.info("Kafka bootstrap.servers: [%s]", config.getKafkaHost());
properties.put("acks", "all");

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

@Override
public void deleteTestTopic(String topic) {
  ZkUtils zkUtils = getZkUtils();
  try {
    LOG.info("Deleting topic {}", topic);
    ZkClient zk = new ZkClient(zookeeperConnectionString, Integer.valueOf(standardProps.getProperty("zookeeper.session.timeout.ms")),
      Integer.valueOf(standardProps.getProperty("zookeeper.connection.timeout.ms")), new ZooKeeperStringSerializer());
    AdminUtils.deleteTopic(zkUtils, topic);
    zk.close();
  } finally {
    zkUtils.close();
  }
}

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

public ZkUtils getZkUtils() {
  LOG.info("In getZKUtils:: zookeeperConnectionString = {}", zookeeperConnectionString);
  ZkClient creator = new ZkClient(zookeeperConnectionString, Integer.valueOf(standardProps.getProperty("zookeeper.session.timeout.ms")),
      Integer.valueOf(standardProps.getProperty("zookeeper.connection.timeout.ms")), new ZooKeeperStringSerializer());
  return ZkUtils.apply(creator, false);
}

代码示例来源:origin: apache/incubator-gobblin

ZkClient zkClient = new ZkClient(zookeeperConnect, sessionTimeoutMs, connectionTimeoutMs, ZKStringSerializer$.MODULE$);
ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect), false);
int partitions = ConfigUtils.getInt(config, KafkaWriterConfigurationKeys.PARTITION_COUNT, KafkaWriterConfigurationKeys.PARTITION_COUNT_DEFAULT);
int replication = ConfigUtils.getInt(config, KafkaWriterConfigurationKeys.REPLICATION_COUNT, KafkaWriterConfigurationKeys.PARTITION_COUNT_DEFAULT);
Properties topicConfig = new Properties(); 
if(AdminUtils.topicExists(zkUtils, topicName)) {
  log.debug("Topic"+topicName+" already Exists with replication: "+replication+" and partitions :"+partitions);

代码示例来源:origin: apache/incubator-pinot

public static KafkaServerStartable startServer(final int port, final int brokerId, final String zkStr,
  final String logDirPath, final Properties configuration) {
 // Create the ZK nodes for Kafka, if needed
 int indexOfFirstSlash = zkStr.indexOf('/');
 if (indexOfFirstSlash != -1) {
  String bareZkUrl = zkStr.substring(0, indexOfFirstSlash);
  String zkNodePath = zkStr.substring(indexOfFirstSlash);
  ZkClient client = new ZkClient(bareZkUrl);
  client.createPersistent(zkNodePath, true);
  client.close();
 }
 File logDir = new File(logDirPath);
 logDir.mkdirs();
 configureKafkaPort(configuration, port);
 configureZkConnectionString(configuration, zkStr);
 configureBrokerId(configuration, brokerId);
 configureKafkaLogDirectory(configuration, logDir);
 configuration.put("zookeeper.session.timeout.ms", "60000");
 KafkaConfig config = new KafkaConfig(configuration);
 KafkaServerStartable serverStartable = new KafkaServerStartable(config);
 serverStartable.startup();
 return serverStartable;
}

代码示例来源:origin: apache/incubator-gobblin

void start()
 throws RuntimeException {
 if (_numStarted.incrementAndGet() == 1) {
  log.warn("Starting up Kafka server suite. Zk at " + _zkConnectString + "; Kafka server at " + _kafkaServerPort);
  _zkServer = new EmbeddedZookeeper(_zkConnectString);
  _zkClient = new ZkClient(_zkConnectString, 30000, 30000, ZKStringSerializer$.MODULE$);
  Properties props = kafka.utils.TestUtils.createBrokerConfig(_brokerId, _kafkaServerPort, true);
  props.setProperty("zookeeper.connect", _zkConnectString);
  KafkaConfig config = new KafkaConfig(props);
  Time mock = new MockTime();
  _kafkaServer = kafka.utils.TestUtils.createServer(config, mock);
 }
 else
 {
  log.info("Kafka server suite already started... continuing");
 }
}

代码示例来源:origin: Dromara/soul

private void loadWatchAppAuth() {
  final String appAuthParent = ZkPathConstants.APP_AUTH_PARENT;
  if (!zkClient.exists(appAuthParent)) {
    zkClient.createPersistent(appAuthParent, true);
  }
  final List<String> childrenList = zkClient.getChildren(appAuthParent);
  if (CollectionUtils.isNotEmpty(childrenList)) {
    childrenList.forEach(children -> {
      String realPath = buildRealPath(appAuthParent, children);
      final AppAuthZkDTO appAuthZkDTO = zkClient.readData(realPath);
      Optional.ofNullable(appAuthZkDTO)
          .ifPresent(dto -> AUTH_MAP.put(dto.getAppKey(), dto));
      subscribeAppAuthDataChanges(realPath);
    });
  }
  zkClient.subscribeChildChanges(appAuthParent, (parentPath, currentChilds) -> {
    if (CollectionUtils.isNotEmpty(currentChilds)) {
      final List<String> unsubscribePath = unsubscribePath(childrenList, currentChilds);
      unsubscribePath.stream().map(children -> buildRealPath(parentPath, children))
          .forEach(this::subscribeAppAuthDataChanges);
    }
  });
}

代码示例来源:origin: apache/incubator-pinot

public DynamicBrokerSelector(String zkServers) {
 ZkClient zkClient = new ZkClient(zkServers);
 zkClient.setZkSerializer(new BytesPushThroughSerializer());
 zkClient.waitUntilConnected(60, TimeUnit.SECONDS);
 zkClient.subscribeDataChanges(ExternalViewReader.BROKER_EXTERNAL_VIEW_PATH, this);
 evReader = new ExternalViewReader(zkClient);
 refresh();
}

代码示例来源:origin: weibocom/motan

private void createNode(URL url, ZkNodeType nodeType) {
  String nodeTypePath = ZkUtils.toNodeTypePath(url, nodeType);
  if (!zkClient.exists(nodeTypePath)) {
    zkClient.createPersistent(nodeTypePath, true);
  }
  zkClient.createEphemeral(ZkUtils.toNodePath(url, nodeType), url.toFullStr());
}

代码示例来源:origin: linkedin/cruise-control

public BrokerFailureDetector(KafkaCruiseControlConfig config,
               LoadMonitor loadMonitor,
               Queue<Anomaly> anomalies,
               Time time,
               KafkaCruiseControl kafkaCruiseControl) {
 String zkUrl = config.getString(KafkaCruiseControlConfig.ZOOKEEPER_CONNECT_CONFIG);
 ZkConnection zkConnection = new ZkConnection(zkUrl, 30000);
 _zkClient = new ZkClient(zkConnection, 30000, new ZkStringSerializer());
 // Do not support secure ZK at this point.
 _zkUtils = new ZkUtils(_zkClient, zkConnection, false);
 _failedBrokers = new HashMap<>();
 _failedBrokersZkPath = config.getString(KafkaCruiseControlConfig.FAILED_BROKERS_ZK_PATH_CONFIG);
 _loadMonitor = loadMonitor;
 _anomalies = anomalies;
 _time = time;
 _kafkaCruiseControl = kafkaCruiseControl;
 _allowCapacityEstimation = config.getBoolean(KafkaCruiseControlConfig.ANOMALY_DETECTION_ALLOW_CAPACITY_ESTIMATION_CONFIG);
}

代码示例来源:origin: apache/incubator-pinot

private void addAndRemoveNewInstanceConfig(ZkClient zkClient)
  throws Exception {
 int biggerRandomNumber = NUM_INSTANCES + new Random().nextInt(NUM_INSTANCES);
 String instanceName = "Server_localhost_" + String.valueOf(biggerRandomNumber);
 String instanceConfigPath = PropertyPathBuilder.instanceConfig(_helixClusterName, instanceName);
 Assert.assertFalse(zkClient.exists(instanceConfigPath));
 List<String> instances = _helixResourceManager.getAllInstances();
 Assert.assertFalse(instances.contains(instanceName));
 // Add new ZNode.
 ZNRecord znRecord = new ZNRecord(instanceName);
 zkClient.createPersistent(instanceConfigPath, znRecord);
 List<String> latestAllInstances = _helixResourceManager.getAllInstances();
 long maxTime = System.currentTimeMillis() + MAX_TIMEOUT_IN_MILLISECOND;
 while (!latestAllInstances.contains(instanceName) && System.currentTimeMillis() < maxTime) {
  Thread.sleep(100L);
  latestAllInstances = _helixResourceManager.getAllInstances();
 }
 Assert.assertTrue(System.currentTimeMillis() < maxTime, "Timeout when waiting for adding instance config");
 // Remove new ZNode.
 zkClient.delete(instanceConfigPath);
 latestAllInstances = _helixResourceManager.getAllInstances();
 maxTime = System.currentTimeMillis() + MAX_TIMEOUT_IN_MILLISECOND;
 while (latestAllInstances.contains(instanceName) && System.currentTimeMillis() < maxTime) {
  Thread.sleep(100L);
  latestAllInstances = _helixResourceManager.getAllInstances();
 }
 Assert.assertTrue(System.currentTimeMillis() < maxTime, "Timeout when waiting for removing instance config");
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public List<String> getChildren(String path) {
  try {
    return zkClient.getChildren(path);
  } catch (ZkNoNodeException e) {
    return null;
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public <T> T getData(String path) {
  return zkClient.readData(path);
}

代码示例来源:origin: crossoverJie/cim

/**
 * 创建父级节点
 */
public void createRootNode(){
  boolean exists = zkClient.exists(appConfiguration.getZkRoot());
  if (exists){
    return;
  }
  //创建 root
  zkClient.createPersistent(appConfiguration.getZkRoot()) ;
}

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