當前位置: 首頁>>代碼示例>>Java>>正文


Java TopicPartition.partition方法代碼示例

本文整理匯總了Java中org.apache.kafka.common.TopicPartition.partition方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicPartition.partition方法的具體用法?Java TopicPartition.partition怎麽用?Java TopicPartition.partition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.kafka.common.TopicPartition的用法示例。


在下文中一共展示了TopicPartition.partition方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: committedFileName

import org.apache.kafka.common.TopicPartition; //導入方法依賴的package包/類
public static String committedFileName(String url, String topicsDir, String directory,
                                       TopicPartition topicPart, long startOffset, long endOffset,
                                       String extension, String zeroPadFormat) {
  String topic = topicPart.topic();
  int partition = topicPart.partition();
  StringBuilder sb = new StringBuilder();
  sb.append(topic);
  sb.append(HdfsSinkConnectorConstants.COMMMITTED_FILENAME_SEPARATOR);
  sb.append(partition);
  sb.append(HdfsSinkConnectorConstants.COMMMITTED_FILENAME_SEPARATOR);
  sb.append(String.format(zeroPadFormat, startOffset));
  sb.append(HdfsSinkConnectorConstants.COMMMITTED_FILENAME_SEPARATOR);
  sb.append(String.format(zeroPadFormat, endOffset));
  sb.append(extension);
  String name = sb.toString();
  return fileName(url, topicsDir, directory, name);
}
 
開發者ID:jiangxiluning,項目名稱:kafka-connect-hdfs,代碼行數:18,代碼來源:FileUtils.java

示例2: hasPartition

import org.apache.kafka.common.TopicPartition; //導入方法依賴的package包/類
private boolean hasPartition(final TopicPartition topicPartition) {
    final List<PartitionInfo> partitions = partitionInfo.get(topicPartition.topic());

    if (partitions == null) {
        return false;
    }

    for (final PartitionInfo partition : partitions) {
        if (partition.partition() == topicPartition.partition()) {
            return true;
        }
    }

    return false;

}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:17,代碼來源:StoreChangelogReader.java

示例3: compare

import org.apache.kafka.common.TopicPartition; //導入方法依賴的package包/類
@Override
public int compare(TopicPartition p1, TopicPartition p2) {
    int result = p1.topic().compareTo(p2.topic());

    if (result != 0) {
        return result;
    } else {
        return p1.partition() < p2.partition() ? UNKNOWN : (p1.partition() > p2.partition() ? 1 : 0);
    }
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:11,代碼來源:StreamPartitionAssignor.java

示例4: compare

import org.apache.kafka.common.TopicPartition; //導入方法依賴的package包/類
@Override
public int compare(TopicPartition o1, TopicPartition o2) {
    int ret = map.get(o1).size() - map.get(o2).size();
    if (ret == 0) {
        ret = o1.topic().compareTo(o2.topic());
        if (ret == 0)
            ret = o1.partition() - o2.partition();
    }
    return ret;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:11,代碼來源:StickyAssignor.java

示例5: onConsume

import org.apache.kafka.common.TopicPartition; //導入方法依賴的package包/類
@Override
public ConsumerRecords<K, V> onConsume(ConsumerRecords<K, V> records) {
    onConsumeCount++;
    if (throwExceptionOnConsume)
        throw new KafkaException("Injected exception in FilterConsumerInterceptor.onConsume.");

    // filters out topic/partitions with partition == FILTER_PARTITION
    Map<TopicPartition, List<ConsumerRecord<K, V>>> recordMap = new HashMap<>();
    for (TopicPartition tp : records.partitions()) {
        if (tp.partition() != filterPartition)
            recordMap.put(tp, records.records(tp));
    }
    return new ConsumerRecords<K, V>(recordMap);
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:15,代碼來源:ConsumerInterceptorsTest.java

示例6: compare

import org.apache.kafka.common.TopicPartition; //導入方法依賴的package包/類
@Override
public int compare(TopicPartition x, TopicPartition y) {
  int result = x.topic().compareTo(y.topic());
  if (result == 0) {
    result = x.partition() - y.partition();
  }
  return result;
}
 
開發者ID:pinterest,項目名稱:doctorkafka,代碼行數:9,代碼來源:KafkaUtils.java

示例7: partitionHandleDotInTopicName

import org.apache.kafka.common.TopicPartition; //導入方法依賴的package包/類
private TopicPartition partitionHandleDotInTopicName(TopicPartition tp) {
  // In the reported metrics, the "." in the topic name will be replaced by "_".
  return !tp.topic().contains(".") ? tp :
    new TopicPartition(tp.topic().replace('.', '_'), tp.partition());
}
 
開發者ID:linkedin,項目名稱:cruise-control,代碼行數:6,代碼來源:CruiseControlMetricsProcessor.java

示例8: directoryName

import org.apache.kafka.common.TopicPartition; //導入方法依賴的package包/類
public static String directoryName(String url, String topicsDir, TopicPartition topicPart) {
  String topic = topicPart.topic();
  int partition = topicPart.partition();
  return url + "/" + topicsDir + "/" + topic + "/" + partition;
}
 
開發者ID:jiangxiluning,項目名稱:kafka-connect-hdfs,代碼行數:6,代碼來源:FileUtils.java

示例9: fileName

import org.apache.kafka.common.TopicPartition; //導入方法依賴的package包/類
public static String fileName(String url, String topicsDir, TopicPartition topicPart,
                              String name) {
  String topic = topicPart.topic();
  int partition = topicPart.partition();
  return url + "/" + topicsDir + "/" + topic + "/" + partition + "/" + name;
}
 
開發者ID:jiangxiluning,項目名稱:kafka-connect-hdfs,代碼行數:7,代碼來源:FileUtils.java

示例10: getOffsetQuarz

import org.apache.kafka.common.TopicPartition; //導入方法依賴的package包/類
public static List<OffsetInfo> getOffsetQuarz() {

        Map<String, Map<String, List<OffsetInfo>>> groupTopicPartitionListMap = new ConcurrentHashMap<>();

        for (Map.Entry<GroupTopicPartition, OffsetAndMetadata> entry: kafkaConsumerOffsets.entrySet()) {
            GroupTopicPartition groupTopicPartition = entry.getKey();
            OffsetAndMetadata offsetAndMetadata = entry.getValue();
            String group = groupTopicPartition.group();
            TopicPartition topicPartition = groupTopicPartition.topicPartition();
            String topic = topicPartition.topic();
            int partition = topicPartition.partition();
            Long committedOffset = offsetAndMetadata.offset();

            if (!logEndOffsetMap.containsKey(topicPartition)) {
                logger.error("The logEndOffsetMap not contains " + topicPartition);
                return null;
            }
            long logSize = logEndOffsetMap.get(topicPartition);

            // May the refresh operation thread take some time to update
            logSize = logSize >= committedOffset ? logSize : committedOffset;
            long lag = committedOffset == -1 ? 0 : (logSize - committedOffset);

            OffsetInfo offsetInfo = new OffsetInfo();
            offsetInfo.setGroup(group);
            offsetInfo.setTopic(topic);
            offsetInfo.setCommittedOffset(committedOffset);
            offsetInfo.setLogSize(logSize);
            offsetInfo.setLag(lag);
            offsetInfo.setTimestamp(offsetAndMetadata.commitTimestamp());

            if (!groupTopicPartitionListMap.containsKey(group)) {
                Map<String, List<OffsetInfo>> topicPartitionMap = new ConcurrentHashMap<>();
                groupTopicPartitionListMap.put(group, topicPartitionMap);
            }
            if (!groupTopicPartitionListMap.get(group).containsKey(topic)) {
                List<OffsetInfo> offsetInfos = new ArrayList<>();
                groupTopicPartitionListMap.get(group).put(topic, offsetInfos);
            }
            groupTopicPartitionListMap.get(group).get(topic).add(offsetInfo);

        }
        return flattenNestedMap(groupTopicPartitionListMap);
    }
 
開發者ID:dubin555,項目名稱:Kafka-Insight,代碼行數:45,代碼來源:KafkaOffsetGetter.java

示例11: getPartition

import org.apache.kafka.common.TopicPartition; //導入方法依賴的package包/類
private int getPartition(final String topic) {
    final TopicPartition partition = partitionForTopic.get(topic);
    return partition == null ? taskId.partition : partition.partition();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:5,代碼來源:ProcessorStateManager.java


注:本文中的org.apache.kafka.common.TopicPartition.partition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。