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


Java ProduceRequestResult類代碼示例

本文整理匯總了Java中org.apache.kafka.clients.producer.internals.ProduceRequestResult的典型用法代碼示例。如果您正苦於以下問題:Java ProduceRequestResult類的具體用法?Java ProduceRequestResult怎麽用?Java ProduceRequestResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ProduceRequestResult類屬於org.apache.kafka.clients.producer.internals包,在下文中一共展示了ProduceRequestResult類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: send

import org.apache.kafka.clients.producer.internals.ProduceRequestResult; //導入依賴的package包/類
/**
 * Adds the record to the list of sent records.
 *
 * @see #history()
 */
@Override
public synchronized Future<RecordMetadata> send(ProducerRecord<K, V> record, Callback callback) {
    verifyProducerState();
    int partition = 0;
    if (!this.cluster.partitionsForTopic(record.topic()).isEmpty())
        partition = partition(record, this.cluster);
    TopicPartition topicPartition = new TopicPartition(record.topic(), partition);
    ProduceRequestResult result = new ProduceRequestResult(topicPartition);
    FutureRecordMetadata future = new FutureRecordMetadata(result, 0, RecordBatch.NO_TIMESTAMP, 0L, 0, 0);
    long offset = nextOffset(topicPartition);
    Completion completion = new Completion(offset, new RecordMetadata(topicPartition, 0, offset,
            RecordBatch.NO_TIMESTAMP, Long.valueOf(0L), 0, 0), result, callback);

    if (!this.transactionInFlight)
        this.sent.add(record);
    else
        this.uncommittedSends.add(record);

    if (autoComplete)
        completion.complete(null);
    else
        this.completions.addLast(completion);

    return future;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:31,代碼來源:MockProducer.java

示例2: testTimeout

import org.apache.kafka.clients.producer.internals.ProduceRequestResult; //導入依賴的package包/類
/**
 * Test that waiting on a request that never completes times out
 */
@Test
public void testTimeout() throws Exception {
    ProduceRequestResult request = new ProduceRequestResult(topicPartition);
    FutureRecordMetadata future = new FutureRecordMetadata(request, relOffset,
            RecordBatch.NO_TIMESTAMP, 0L, 0, 0);
    assertFalse("Request is not completed", future.isDone());
    try {
        future.get(5, TimeUnit.MILLISECONDS);
        fail("Should have thrown exception.");
    } catch (TimeoutException e) { /* this is good */
    }

    request.set(baseOffset, RecordBatch.NO_TIMESTAMP, null);
    request.done();
    assertTrue(future.isDone());
    assertEquals(baseOffset + relOffset, future.get().offset());
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:21,代碼來源:RecordSendTest.java

示例3: send

import org.apache.kafka.clients.producer.internals.ProduceRequestResult; //導入依賴的package包/類
/**
 * Adds the record to the list of sent records.
 *
 * @see #history()
 */
@Override
public synchronized Future<RecordMetadata> send(ProducerRecord<K, V> record, Callback callback) {
    int partition = 0;
    if (this.cluster.partitionsForTopic(record.topic()) != null)
        partition = partition(record, this.cluster);
    ProduceRequestResult result = new ProduceRequestResult();
    FutureRecordMetadata future = new FutureRecordMetadata(result, 0, Record.NO_TIMESTAMP, 0, 0, 0);
    TopicPartition topicPartition = new TopicPartition(record.topic(), partition);
    long offset = nextOffset(topicPartition);
    Completion completion = new Completion(topicPartition, offset,
                                           new RecordMetadata(topicPartition, 0, offset, Record.NO_TIMESTAMP, 0, 0, 0),
                                           result, callback);
    this.sent.add(record);
    if (autoComplete)
        completion.complete(null);
    else
        this.completions.addLast(completion);
    return future;
}
 
開發者ID:txazo,項目名稱:kafka,代碼行數:25,代碼來源:MockProducer.java

示例4: testTimeout

import org.apache.kafka.clients.producer.internals.ProduceRequestResult; //導入依賴的package包/類
/**
 * Test that waiting on a request that never completes times out
 */
@Test
public void testTimeout() throws Exception {
    ProduceRequestResult request = new ProduceRequestResult();
    FutureRecordMetadata future = new FutureRecordMetadata(request, relOffset,
                                                           Record.NO_TIMESTAMP, 0, 0, 0);
    assertFalse("Request is not completed", future.isDone());
    try {
        future.get(5, TimeUnit.MILLISECONDS);
        fail("Should have thrown exception.");
    } catch (TimeoutException e) { /* this is good */
    }

    request.done(topicPartition, baseOffset, null);
    assertTrue(future.isDone());
    assertEquals(baseOffset + relOffset, future.get().offset());
}
 
開發者ID:txazo,項目名稱:kafka,代碼行數:20,代碼來源:RecordSendTest.java

示例5: Completion

import org.apache.kafka.clients.producer.internals.ProduceRequestResult; //導入依賴的package包/類
public Completion(long offset,
                  RecordMetadata metadata,
                  ProduceRequestResult result,
                  Callback callback) {
    this.metadata = metadata;
    this.offset = offset;
    this.result = result;
    this.callback = callback;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:10,代碼來源:MockProducer.java

示例6: asyncRequest

import org.apache.kafka.clients.producer.internals.ProduceRequestResult; //導入依賴的package包/類
public ProduceRequestResult asyncRequest(final long baseOffset, final RuntimeException error, final long timeout) {
    final ProduceRequestResult request = new ProduceRequestResult(topicPartition);
    Thread thread = new Thread() {
        public void run() {
            try {
                sleep(timeout);
                request.set(baseOffset, RecordBatch.NO_TIMESTAMP, error);
                request.done();
            } catch (InterruptedException e) { }
        }
    };
    thread.start();
    return request;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:15,代碼來源:RecordSendTest.java

示例7: Completion

import org.apache.kafka.clients.producer.internals.ProduceRequestResult; //導入依賴的package包/類
public Completion(TopicPartition topicPartition,
                  long offset,
                  RecordMetadata metadata,
                  ProduceRequestResult result,
                  Callback callback) {
    this.metadata = metadata;
    this.offset = offset;
    this.result = result;
    this.callback = callback;
    this.topicPartition = topicPartition;
}
 
開發者ID:txazo,項目名稱:kafka,代碼行數:12,代碼來源:MockProducer.java

示例8: asyncRequest

import org.apache.kafka.clients.producer.internals.ProduceRequestResult; //導入依賴的package包/類
public ProduceRequestResult asyncRequest(final long baseOffset, final RuntimeException error, final long timeout) {
    final ProduceRequestResult request = new ProduceRequestResult();
    Thread thread = new Thread() {
        public void run() {
            try {
                sleep(timeout);
                request.done(topicPartition, baseOffset, error);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    };
    thread.start();
    return request;
}
 
開發者ID:txazo,項目名稱:kafka,代碼行數:16,代碼來源:RecordSendTest.java


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