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


Java MetadataResponse.PartitionMetadata方法代码示例

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


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

示例1: newMetadataResponse

import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
private MetadataResponse newMetadataResponse(String topic, Errors error) {
    List<MetadataResponse.PartitionMetadata> partitionsMetadata = new ArrayList<>();
    if (error == Errors.NONE) {
        for (PartitionInfo partitionInfo : cluster.partitionsForTopic(topic)) {
            partitionsMetadata.add(new MetadataResponse.PartitionMetadata(
                    Errors.NONE,
                    partitionInfo.partition(),
                    partitionInfo.leader(),
                    Arrays.asList(partitionInfo.replicas()),
                    Arrays.asList(partitionInfo.inSyncReplicas())));
        }
    }

    MetadataResponse.TopicMetadata topicMetadata = new MetadataResponse.TopicMetadata(error, topic, false, partitionsMetadata);
    return new MetadataResponse(cluster.nodes(), null, MetadataResponse.NO_CONTROLLER_ID, Arrays.asList(topicMetadata));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:17,代码来源:FetcherTest.java

示例2: newMetadataResponse

import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
private MetadataResponse newMetadataResponse(String topic, Errors error) {
    List<MetadataResponse.PartitionMetadata> partitionsMetadata = new ArrayList<>();
    if (error == Errors.NONE) {
        for (PartitionInfo partitionInfo : cluster.partitionsForTopic(topic)) {
            partitionsMetadata.add(new MetadataResponse.PartitionMetadata(
                    Errors.NONE,
                    partitionInfo.partition(),
                    partitionInfo.leader(),
                    Arrays.asList(partitionInfo.replicas()),
                    Arrays.asList(partitionInfo.inSyncReplicas())));
        }
    }

    MetadataResponse.TopicMetadata topicMetadata = new MetadataResponse.TopicMetadata(error, topic, false, partitionsMetadata);
    return new MetadataResponse(cluster.nodes(), MetadataResponse.NO_CONTROLLER_ID, Arrays.asList(topicMetadata));
}
 
开发者ID:txazo,项目名称:kafka,代码行数:17,代码来源:FetcherTest.java

示例3: getLeaderToShutDown

import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
@Override
public int getLeaderToShutDown(String topic) throws Exception {
	ZkUtils zkUtils = getZkUtils();
	try {
		MetadataResponse.PartitionMetadata firstPart = null;
		do {
			if (firstPart != null) {
				LOG.info("Unable to find leader. error code {}", firstPart.error().code());
				// not the first try. Sleep a bit
				Thread.sleep(150);
			}

			List<MetadataResponse.PartitionMetadata> partitionMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils).partitionMetadata();
			firstPart = partitionMetadata.get(0);
		}
		while (firstPart.error().code() != 0);

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

示例4: fetchMetadata

import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
@Override
public MetadataResponse fetchMetadata() {
    Node node = new Node(1, "host1", 1001);
    MetadataResponse.PartitionMetadata partitionMetadata = new MetadataResponse.PartitionMetadata(Errors.NONE, 1, node, new ArrayList<Node>(), new ArrayList<Node>());
    MetadataResponse.TopicMetadata topicMetadata = new MetadataResponse.TopicMetadata(Errors.NONE, topic, true, Collections.singletonList(partitionMetadata));
    MetadataResponse response = new MetadataResponse(Collections.<Node>singletonList(node), null, MetadataResponse.NO_CONTROLLER_ID,
        Collections.singletonList(topicMetadata));
    return response;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:10,代码来源:InternalTopicManagerTest.java

示例5: waitTopicUntilReady

import org.apache.kafka.common.requests.MetadataResponse; //导入方法依赖的package包/类
public MetadataResponse.TopicMetadata waitTopicUntilReady(String topic) {
    boolean isReady = false;
    MetadataResponse.TopicMetadata topicMeta = null;
    while (!isReady) {
        Random random = new Random();
        topicMeta = this.fetchTopicMeta(topic);
        List<MetadataResponse.PartitionMetadata> partitionsMetadata = topicMeta.partitionMetadata();
        Iterator<MetadataResponse.PartitionMetadata> iterator = partitionsMetadata.iterator();
        boolean hasGotLeader = true;
        boolean hasGotReplica = true;
        while (iterator.hasNext()) {
            MetadataResponse.PartitionMetadata partitionMeta = iterator.next();
            hasGotLeader &= (!partitionMeta.leader().isEmpty());
            if (partitionMeta.leader().isEmpty()) {
                System.out.println("Partition leader is not ready, wait 1s.");
                break;
            }
            hasGotReplica &= (!partitionMeta.replicas().isEmpty());
            if (partitionMeta.replicas().isEmpty()) {
                System.out.println("Partition replica is not ready, wait 1s.");
                break;
            }
        }
        isReady = hasGotLeader & hasGotReplica;
        if (!isReady) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
        }
    }
    return topicMeta;
}
 
开发者ID:apache,项目名称:kylin,代码行数:34,代码来源:MockKafka.java


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