本文整理汇总了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));
}
示例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));
}
示例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();
}
}
示例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;
}
示例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;
}