本文整理匯總了Java中kafka.api.Request類的典型用法代碼示例。如果您正苦於以下問題:Java Request類的具體用法?Java Request怎麽用?Java Request使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Request類屬於kafka.api包,在下文中一共展示了Request類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: waitUntilMetadataIsPropagated
import kafka.api.Request; //導入依賴的package包/類
public static void waitUntilMetadataIsPropagated(final List<KafkaServer> servers,
final String topic,
final int partition,
final long timeout) throws InterruptedException {
TestUtils.waitForCondition(new TestCondition() {
@Override
public boolean conditionMet() {
for (final KafkaServer server : servers) {
final MetadataCache metadataCache = server.apis().metadataCache();
final Option<PartitionStateInfo> partitionInfo =
metadataCache.getPartitionInfo(topic, partition);
if (partitionInfo.isEmpty()) {
return false;
}
final PartitionStateInfo partitionStateInfo = partitionInfo.get();
if (!Request.isValidBrokerId(partitionStateInfo.leaderIsrAndControllerEpoch().leaderAndIsr().leader())) {
return false;
}
}
return true;
}
}, timeout, "metadata for topic=" + topic + " partition=" + partition + " not propagated to all brokers");
}
示例2: waitUntilMetadataIsPropagated
import kafka.api.Request; //導入依賴的package包/類
public static void waitUntilMetadataIsPropagated(final List<KafkaServer> servers,
final String topic,
final int partition,
final long timeout) throws InterruptedException {
TestUtils.waitForCondition(new TestCondition() {
@Override
public boolean conditionMet() {
for (final KafkaServer server : servers) {
final MetadataCache metadataCache = server.apis().metadataCache();
final Option<UpdateMetadataRequest.PartitionState> partitionInfo =
metadataCache.getPartitionInfo(topic, partition);
if (partitionInfo.isEmpty()) {
return false;
}
final UpdateMetadataRequest.PartitionState metadataPartitionState = partitionInfo.get();
if (!Request.isValidBrokerId(metadataPartitionState.basePartitionState.leader)) {
return false;
}
}
return true;
}
}, timeout, "metadata for topic=" + topic + " partition=" + partition + " not propagated to all brokers");
}
示例3: getTopicLogSize
import kafka.api.Request; //導入依賴的package包/類
private long getTopicLogSize(String topic, int pid) {
Option<Object> o = ZkUtils.getLeaderForPartition(zkClient, topic, pid);
if (o.isEmpty() || o.get() == null) {
log.error("No broker for partition %s - %s", topic, pid);
return 0;
}
Integer leaderId = Int.unbox(o.get());
SimpleConsumer consumer = consumerMap.get(leaderId);
if (consumer == null) {
consumer = createSimpleConsumer(leaderId);
}
// createSimpleConsumer may fail.
if (consumer == null) {
return 0;
}
consumerMap.put(leaderId, consumer);
TopicAndPartition topicAndPartition = new TopicAndPartition(topic, pid);
PartitionOffsetRequestInfo requestInfo = new PartitionOffsetRequestInfo(OffsetRequest.LatestTime(), 1);
OffsetRequest request = new OffsetRequest(
new Map1<TopicAndPartition, PartitionOffsetRequestInfo>(topicAndPartition, requestInfo),
0,
Request.OrdinaryConsumerId()
);
OffsetResponse response = consumer.getOffsetsBefore(request);
PartitionOffsetsResponse offsetsResponse = response.partitionErrorAndOffsets().get(topicAndPartition).get();
return scala.Long.unbox(offsetsResponse.offsets().head());
}