Github user tweise commented on a diff in the pull request:

    
https://github.com/apache/incubator-apex-malhar/pull/134#discussion_r48452268
  
    --- Diff: 
kafka/src/main/java/org/apache/apex/malhar/kafka/KafkaConsumerWrapper.java ---
    @@ -0,0 +1,408 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.apex.malhar.kafka;
    +
    +import java.io.Closeable;
    +import java.io.IOException;
    +import java.util.HashMap;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Properties;
    +import java.util.concurrent.ArrayBlockingQueue;
    +import java.util.concurrent.ConcurrentHashMap;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +
    +import javax.validation.constraints.Pattern;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import org.apache.commons.io.IOUtils;
    +import org.apache.commons.lang3.tuple.Pair;
    +import org.apache.kafka.clients.consumer.ConsumerConfig;
    +import org.apache.kafka.clients.consumer.ConsumerRecord;
    +import org.apache.kafka.clients.consumer.ConsumerRecords;
    +import org.apache.kafka.clients.consumer.KafkaConsumer;
    +import org.apache.kafka.clients.consumer.NoOffsetForPartitionException;
    +import org.apache.kafka.clients.consumer.OffsetAndMetadata;
    +import org.apache.kafka.clients.consumer.OffsetCommitCallback;
    +import org.apache.kafka.common.Metric;
    +import org.apache.kafka.common.MetricName;
    +import org.apache.kafka.common.TopicPartition;
    +import org.apache.kafka.common.errors.WakeupException;
    +
    +import com.google.common.base.Joiner;
    +import com.google.common.util.concurrent.ThreadFactoryBuilder;
    +
    +/**
    + * This is the wrapper class for new Kafka consumer API
    + *
    + * It starts number of consumers(one for each cluster) in same number of 
threads.
    + * Maintains the consumer offsets
    + *
    + * It also use the consumers to commit the application processed offsets 
along with the application name
    + *
    + * @param <K> The key object, needs to be used with 
http://kafka.apache.org/090/javadoc/org/apache/kafka/clients/consumer/ConsumerConfig.html#KEY_DESERIALIZER_CLASS_CONFIG
    + * @param <V> The value object, needs to be used with 
http://kafka.apache.org/090/javadoc/org/apache/kafka/clients/consumer/ConsumerConfig.html#VALUE_DESERIALIZER_CLASS_CONFIG
    + */
    +public class KafkaConsumerWrapper<K, V> implements Closeable
    +{
    +
    +  private static final Logger logger = 
LoggerFactory.getLogger(KafkaConsumerWrapper.class);
    +
    +  /**
    +   * number of messages in buffer
    +   */
    +  private int cacheSize = 1024;
    +
    +  /**
    +   * consumer timeout
    +   */
    +  private long timeout = 5000;
    +
    +  private boolean isAlive = false;
    +
    +  private transient Map<String, KafkaConsumer<K, V>> consumers = new 
HashMap<>();
    +
    +  // The in memory buffer hold consumed messages
    +  private transient ArrayBlockingQueue<Pair<String, ConsumerRecord<K, V>>> 
holdingBuffer;
    +
    +
    +  /**
    +   * refer to AbstractKafkaInputOperator.initialOffset
    +   */
    +  @Pattern(flags = {Pattern.Flag.CASE_INSENSITIVE},
    +      regexp = 
"earliest|latest|application_or_earliest|application_or_latest")
    +  private String initialOffset = "latest";
    +
    +  private transient AbstractKafkaInputOperator<K, V> ownerOperator = null;
    +
    +  private transient ExecutorService kafkaConsumerExecutor;
    +
    +  private transient Map<String, Map<TopicPartition, OffsetAndMetadata>> 
offsetsToCommit = new HashMap<>();
    +
    +  /**
    +   * You can customize the offsetCommit
    +   */
    +  private transient OffsetCommitCallback offsetCommitCallback = new 
OffsetCommitCallback()
    +  {
    +    @Override
    +    public void onComplete(Map<TopicPartition, OffsetAndMetadata> map, 
Exception e)
    +    {
    +      if (logger.isDebugEnabled()) {
    --- End diff --
    
    What's the purpose of this implementation?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to