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