本文整理匯總了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();
}