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


Java ZkClient.close方法代码示例

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


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

示例1: createTopic

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
/**
 * Create a Kafka topic with the given parameters.
 *
 * @param topic       The name of the topic.
 * @param partitions  The number of partitions for this topic.
 * @param replication The replication factor for (partitions of) this topic.
 * @param topicConfig Additional topic-level configuration settings.
 */
public void createTopic(final String topic,
                        final int partitions,
                        final int replication,
                        final Properties topicConfig) {
    log.debug("Creating topic { name: {}, partitions: {}, replication: {}, config: {} }",
        topic, partitions, replication, topicConfig);

    // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
    // createTopic() will only seem to work (it will return without error).  The topic will exist in
    // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
    // topic.
    final ZkClient zkClient = new ZkClient(
        zookeeperConnect(),
        DEFAULT_ZK_SESSION_TIMEOUT_MS,
        DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
        ZKStringSerializer$.MODULE$);
    final boolean isSecure = false;
    final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
    AdminUtils.createTopic(zkUtils, topic, partitions, replication, topicConfig, RackAwareMode.Enforced$.MODULE$);
    zkClient.close();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:30,代码来源:KafkaEmbedded.java

示例2: createTopic

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
/**
 * Create a Kafka topic with the given parameters.
 *
 * @param topic       The name of the topic.
 * @param partitions  The number of partitions for this topic.
 * @param replication The replication factor for (partitions of) this topic.
 * @param topicConfig Additional topic-level configuration settings.
 */
public void createTopic(String topic,
                        int partitions,
                        int replication,
                        Properties topicConfig) {
  log.debug("Creating topic { name: {}, partitions: {}, replication: {}, config: {} }",
      topic, partitions, replication, topicConfig);
  // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
  // createTopic() will only seem to work (it will return without error).  The topic will exist in
  // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
  // topic.
  ZkClient zkClient = new ZkClient(
      zookeeperConnect(),
      DEFAULT_ZK_SESSION_TIMEOUT_MS,
      DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
      ZKStringSerializer$.MODULE$);
  boolean isSecure = false;
  ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
  AdminUtils.createTopic(zkUtils, topic, partitions, replication, topicConfig, RackAwareMode.Enforced$.MODULE$);
  zkClient.close();
}
 
开发者ID:kaiwaehner,项目名称:kafka-streams-machine-learning-examples,代码行数:29,代码来源:KafkaEmbedded.java

示例3: close

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
@Override
public void close() {
    closed = true;

    // 停止心跳
    this.heartbeatStop();
    // 关闭KafkaProuder
    if (LazySingletonProducer.isInstanced()) {
        // producer实际上已经初始化
        LazySingletonProducer.getInstance(this.config).close();
    }

    // 关闭client,临时节点消失,监控系统进行感知报警
    ZkClient client = this.zkRegister == null ? null : this.zkRegister.getClient();
    if (null != client) {
        client.close();
    }
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:19,代码来源:KafkaAppender.java

示例4: stop

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
@Override
public void stop() {
    super.stop();

    // 停止心跳
    this.heartbeatStop();

    // 关闭KafkaProuder
    if (LazySingletonProducer.isInstanced()) {
        // producer实际上已经初始化
        LazySingletonProducer.getInstance(this.config).close();
    }

    // 关闭client,临时节点消失,监控系统进行感知报警
    ZkClient client = this.zkRegister == null ? null : this.zkRegister.getClient();
    if (null != client) {
        client.close();
    }
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:20,代码来源:KafkaAppender.java

示例5: startServer

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
public static KafkaServerStartable startServer(final int port, final int brokerId,
    final String zkStr, 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("/tmp/kafka-" + Double.toHexString(Math.random()));
  logDir.mkdirs();

  configureKafkaPort(configuration, port);
  configureZkConnectionString(configuration, zkStr);
  configureBrokerId(configuration, brokerId);
  configureKafkaLogDirectory(configuration, logDir);
  KafkaConfig config = new KafkaConfig(configuration);

  KafkaServerStartable serverStartable = new KafkaServerStartable(config);
  serverStartable.startup();

  return serverStartable;
}
 
开发者ID:uber,项目名称:uReplicator,代码行数:27,代码来源:KafkaStarterUtils.java

示例6: createTopic

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
/**
 * Creates a Topic.
 *
 * @param topicName             Topic name.
 * @param partitions        Number of partitions for the topic.
 * @param replicationFactor Replication factor.
 * @param curatorFramework CuratorFramework.
 */
public static void createTopic(String topicName, int partitions, int replicationFactor, CuratorFramework curatorFramework) {
    if (partitions <= 0)
        throw new AdminOperationException("number of partitions must be larger than 0");

    if (replicationFactor <= 0)
        throw new AdminOperationException("replication factor must be larger than 0");

    if (!topicExists(topicName, curatorFramework)) {
        m_logger.info(String.format("Topic %s not found, creating...", topicName));
        ZkClient zkClient = fromCurator(curatorFramework);
        try {
            AdminUtils.createTopic(zkClient, topicName, partitions, replicationFactor, new Properties());
            m_logger.info("Topic created. name: {}, partitions: {}, replicationFactor: {}", topicName,
                    partitions, replicationFactor);
        } catch (TopicExistsException ignore) {
            m_logger.info("Topic exists. name: {}", topicName);
        } finally {
            if (zkClient != null) {
                zkClient.close();
            }
        }
    } else {
        m_logger.info(String.format("Topic %s found!", topicName));
    }
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:34,代码来源:KafkaUtils.java

示例7: getLeaderToShutDown

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
@Override
public int getLeaderToShutDown(String topic) throws Exception {
	ZkClient zkClient = createZkClient();
	PartitionMetadata firstPart = null;
	do {
		if (firstPart != null) {
			LOG.info("Unable to find leader. error code {}", firstPart.errorCode());
			// not the first try. Sleep a bit
			Thread.sleep(150);
		}

		Seq<PartitionMetadata> partitionMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkClient).partitionsMetadata();
		firstPart = partitionMetadata.head();
	}
	while (firstPart.errorCode() != 0);
	zkClient.close();

	return firstPart.leader().get().id();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:KafkaTestEnvironmentImpl.java

示例8: deleteTestTopic

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
@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();
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:17,代码来源:KafkaTestEnvironmentImpl.java

示例9: assertConnect

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
private void assertConnect(RegistryConfig registryConfig) {
	try {
		ZkClient zk = new ZkClient(registryConfig.getRegistryAddress(), registryConfig.getRegistryTimeout());
		zk.close();
	} catch (Exception e) {
		throw new RuntimeException("注册中心 " + registryConfig.getRegistryAddress() + "无法连接", e);
	}
}
 
开发者ID:tonyruiyu,项目名称:dubbo-mock,代码行数:9,代码来源:DubboMockServer.java

示例10: deleteTopic

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
public void deleteTopic(final String topic) {
    log.debug("Deleting topic { name: {} }", topic);

    final ZkClient zkClient = new ZkClient(
        zookeeperConnect(),
        DEFAULT_ZK_SESSION_TIMEOUT_MS,
        DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
        ZKStringSerializer$.MODULE$);
    final boolean isSecure = false;
    final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
    AdminUtils.deleteTopic(zkUtils, topic);
    zkClient.close();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:KafkaEmbedded.java

示例11: getTopicConfigProperties

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
private Properties getTopicConfigProperties(final String changelog) {
    // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
    // createTopics() will only seem to work (it will return without error).  The topic will exist in
    // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
    // topic.
    final ZkClient zkClient = new ZkClient(
            CLUSTER.zKConnectString(),
            DEFAULT_ZK_SESSION_TIMEOUT_MS,
            DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
            ZKStringSerializer$.MODULE$);
    try {
        final boolean isSecure = false;
        final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(CLUSTER.zKConnectString()), isSecure);

        final Map<String, Properties> topicConfigs = AdminUtils.fetchAllTopicConfigs(zkUtils);
        final Iterator it = topicConfigs.iterator();
        while (it.hasNext()) {
            final Tuple2<String, Properties> topicConfig = (Tuple2<String, Properties>) it.next();
            final String topic = topicConfig._1;
            final Properties prop = topicConfig._2;
            if (topic.equals(changelog)) {
                return prop;
            }
        }
        return new Properties();
    } finally {
        zkClient.close();
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:30,代码来源:InternalTopicIntegrationTest.java

示例12: closeResources

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
/**
 * 关闭zk和kafka、心跳检测
 */
public void closeResources() {
    if (null != this.timer) {
        this.timer.cancel();
    }
    if (LazySingletonProducer.isInstanced()) {
        LazySingletonProducer.getInstance(KafkaManager.this.config).close();
    }
    ZkClient client = this.zkRegister == null ? null : this.zkRegister.getClient();
    if (null != client) {
        client.close();
    }
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:16,代码来源:KafkaManager.java

示例13: validate

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
@Override
public void validate() throws ValidationException {
  super.validate();
  if (zkConnect == null || zkConnect.isEmpty())
    throw new ValidationException(LOGGER.translate("ZKCONNECT_VALIDATE_ERROR"));
  if (bootstrap == null || bootstrap.isEmpty())
    throw new ValidationException(LOGGER.translate("BOOTSTRAP_VALIDATE_ERROR"));
  if (topic == null || topic.isEmpty())
    throw new ValidationException(LOGGER.translate("TOPIC_VALIDATE_ERROR"));
  ZkClient zkClient = new ZkClient(zkConnect, 10000, 8000, ZKStringSerializer$.MODULE$);
  // Security for Kafka was added in Kafka 0.9.0.0 -> isSecureKafkaCluster = false
  ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zkConnect), false);
  if (AdminUtils.topicExists(zkUtils, topic))
    zkClient.deleteRecursive(ZkUtils.getTopicPath(topic));

  ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  try
  {

    Thread.currentThread().setContextClassLoader(null);
    AdminUtils.createTopic(zkUtils, topic, partitions, replicas, new Properties(), RackAwareMode.Disabled$.MODULE$);
  }
  catch (Throwable th) {
    LOGGER.error(th.getMessage(), th);
    throw new ValidationException(th.getMessage());
  }
  finally {
    Thread.currentThread().setContextClassLoader(classLoader);
  }
  zkClient.close();
}
 
开发者ID:Esri,项目名称:kafka-for-geoevent,代码行数:32,代码来源:KafkaOutboundTransport.java

示例14: validate

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
@Override
public void validate() throws ValidationException {
  super.validate();
  if (zkConnect.isEmpty())
    throw new ValidationException(LOGGER.translate("ZKCONNECT_VALIDATE_ERROR"));
  if (topic.isEmpty())
    throw new ValidationException(LOGGER.translate("TOPIC_VALIDATE_ERROR"));
  if (groupId.isEmpty())
    throw new ValidationException(LOGGER.translate("GROUP_ID_VALIDATE_ERROR"));
  if (numThreads < 1)
    throw new ValidationException(LOGGER.translate("NUM_THREADS_VALIDATE_ERROR"));
  ZkClient zkClient = new ZkClient(zkConnect, 10000, 8000, ZKStringSerializer$.MODULE$);
  // Security for Kafka was added in Kafka 0.9.0.0 -> isSecureKafkaCluster = false
  ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zkConnect), false);
  Boolean topicExists = AdminUtils.topicExists(zkUtils, topic);
  zkClient.close();
  if (!topicExists)
    throw new ValidationException(LOGGER.translate("TOPIC_VALIDATE_ERROR"));
  // Init Consumer Config
  Properties props = new Properties()
  {
    { put("zookeeper.connect", zkConnect); }
    { put("group.id", groupId); }
    { put("zookeeper.session.timeout.ms", "400"); }
    { put("zookeeper.sync.time.ms", "200"); }
    { put("auto.commit.interval.ms", "1000"); }
  };
  consumerConfig = new ConsumerConfig(props);
}
 
开发者ID:Esri,项目名称:kafka-for-geoevent,代码行数:30,代码来源:KafkaInboundTransport.java

示例15: createTestTopic

import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
@Override
public void createTestTopic(String topic, int numberOfPartitions, int replicationFactor, Properties topicConfig) {
	// create topic with one client
	LOG.info("Creating topic {}", topic);

	ZkClient creator = createZkClient();

	AdminUtils.createTopic(creator, topic, numberOfPartitions, replicationFactor, topicConfig);
	creator.close();

	// validate that the topic has been created
	final long deadline = System.currentTimeMillis() + 30000;
	do {
		try {
			Thread.sleep(100);
		}
		catch (InterruptedException e) {
			// restore interrupted state
		}
		List<KafkaTopicPartitionLeader> partitions = FlinkKafkaConsumer08.getPartitionsForTopic(Collections.singletonList(topic), standardProps);
		if (partitions != null && partitions.size() > 0) {
			return;
		}
	}
	while (System.currentTimeMillis() < deadline);
	fail ("Test topic could not be created");
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:28,代码来源:KafkaTestEnvironmentImpl.java


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