本文整理匯總了Java中org.apache.kafka.common.PartitionInfo.leader方法的典型用法代碼示例。如果您正苦於以下問題:Java PartitionInfo.leader方法的具體用法?Java PartitionInfo.leader怎麽用?Java PartitionInfo.leader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.kafka.common.PartitionInfo
的用法示例。
在下文中一共展示了PartitionInfo.leader方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: populateSnapshots
import org.apache.kafka.common.PartitionInfo; //導入方法依賴的package包/類
private void populateSnapshots(Cluster kafkaCluster,
ClusterModel clusterModel,
TopicPartition tp,
Snapshot[] leaderLoadSnapshots) throws ModelInputException {
PartitionInfo partitionInfo = kafkaCluster.partition(tp);
// If partition info does not exist, the topic may have been deleted.
if (partitionInfo != null) {
for (Node replica : partitionInfo.replicas()) {
boolean isLeader = partitionInfo.leader() != null && replica.id() == partitionInfo.leader().id();
String rack = getRackHandleNull(replica);
// Note that we assume the capacity resolver can still return the broker capacity even if the broker
// is dead. We need this to get the host resource capacity.
Map<Resource, Double> brokerCapacity =
_brokerCapacityConfigResolver.capacityForBroker(rack, replica.host(), replica.id());
clusterModel.createReplicaHandleDeadBroker(rack, replica.id(), tp, isLeader, brokerCapacity);
// Push the load snapshot to the replica one by one.
for (int i = 0; i < leaderLoadSnapshots.length; i++) {
clusterModel.pushLatestSnapshot(rack, replica.id(), tp,
isLeader ? leaderLoadSnapshots[i].duplicate() : MonitorUtils.toFollowerSnapshot(leaderLoadSnapshots[i]));
}
}
}
}
示例2: getBrokerLeaderPartitions
import org.apache.kafka.common.PartitionInfo; //導入方法依賴的package包/類
public Map<Integer, List<TopicPartition>> getBrokerLeaderPartitions(
Map<String, List<PartitionInfo>> topicPartitonInfoMap) {
Map<Integer, List<TopicPartition>> result = new HashMap<>();
for (String topic : topicPartitonInfoMap.keySet()) {
List<PartitionInfo> partitionInfoList = topicPartitonInfoMap.get(topic);
if (partitionInfoList == null) {
LOG.error("Failed to get partition info for {}", topic);
continue;
}
for (PartitionInfo info : partitionInfoList) {
Node leaderNode = info.leader();
if (leaderNode != null) {
result.putIfAbsent(leaderNode.id(), new ArrayList<>());
TopicPartition topicPartiton = new TopicPartition(info.topic(), info.partition());
result.get(leaderNode.id()).add(topicPartiton);
}
}
}
return result;
}
示例3: leaderChanged
import org.apache.kafka.common.PartitionInfo; //導入方法依賴的package包/類
private static boolean leaderChanged(PartitionInfo prevPartInfo, PartitionInfo currPartInfo) {
Node prevLeader = prevPartInfo.leader();
Node currLeader = currPartInfo.leader();
return !(prevLeader == null && currLeader == null) && !(prevLeader != null && currLeader != null
&& prevLeader.id() == currLeader.id());
}
示例4: OutOfSyncReplica
import org.apache.kafka.common.PartitionInfo; //導入方法依賴的package包/類
public OutOfSyncReplica(PartitionInfo partitionInfo) {
this.topicPartition = new TopicPartition(partitionInfo.topic(), partitionInfo.partition());
this.inSyncBrokers = getInSyncReplicas(partitionInfo);
this.outOfSyncBrokers = getOutOfSyncReplicas(partitionInfo);
this.leader = partitionInfo.leader();
}