All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.lenses.topology.client.kafka.metrics.CallbackConsumer Maven / Gradle / Ivy

The newest version!
package io.lenses.topology.client.kafka.metrics;

import io.lenses.topology.client.Publisher;
import org.apache.kafka.clients.consumer.*;
import org.apache.kafka.common.Metric;
import org.apache.kafka.common.MetricName;
import org.apache.kafka.common.PartitionInfo;
import org.apache.kafka.common.TopicPartition;

import java.time.Duration;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

/**
 * An implementation of {@link Publisher} which will invoke a supplied
 * callback when the underlying producer is closed.
 */
public class CallbackConsumer implements Consumer {

  private final Consumer consumer;
  private final Runnable callback;

  public CallbackConsumer(Consumer consumer, Runnable callback) {
    this.consumer = consumer;
    this.callback = callback;
  }

  @Override
  public Set assignment() {
    return consumer.assignment();
  }

  @Override
  public Set subscription() {
    return consumer.subscription();
  }

  @Override
  public void subscribe(Collection collection) {
    consumer.subscribe(collection);
  }

  @Override
  public void subscribe(Collection collection, ConsumerRebalanceListener consumerRebalanceListener) {
    consumer.subscribe(collection, consumerRebalanceListener);
  }

  @Override
  public void assign(Collection collection) {
    consumer.assign(collection);
  }

  @Override
  public void subscribe(Pattern pattern, ConsumerRebalanceListener consumerRebalanceListener) {
    consumer.subscribe(pattern, consumerRebalanceListener);
  }

  @Override
  public void subscribe(Pattern pattern) {
    consumer.subscribe(pattern);
  }

  @Override
  public void unsubscribe() {
    consumer.unsubscribe();
  }

  @Override
  public ConsumerRecords poll(long l) {
    return consumer.poll(l);
  }

  @Override
  public ConsumerRecords poll(Duration timeout) {
    return consumer.poll(timeout);
  }

  @Override
  public void commitSync() {
    consumer.commitSync();
  }

  @Override
  public void commitSync(Duration timeout) {
    consumer.commitSync(timeout);
  }

  @Override
  public void commitSync(Map map) {
    consumer.commitSync(map);
  }

  @Override
  public void commitSync(Map offsets, Duration timeout) {
    consumer.commitSync(offsets, timeout);
  }

  @Override
  public void commitAsync() {
    consumer.commitAsync();
  }

  @Override
  public void commitAsync(OffsetCommitCallback offsetCommitCallback) {
    consumer.commitAsync(offsetCommitCallback);
  }

  @Override
  public void commitAsync(Map map, OffsetCommitCallback offsetCommitCallback) {
    consumer.commitAsync(map, offsetCommitCallback);
  }

  @Override
  public void seek(TopicPartition topicPartition, long l) {
    consumer.seek(topicPartition, l);
  }

  @Override
  public void seek(TopicPartition partition, OffsetAndMetadata offsetAndMetadata) {
    consumer.seek(partition, offsetAndMetadata);
  }

  @Override
  public void seekToBeginning(Collection collection) {
    consumer.seekToBeginning(collection);
  }

  @Override
  public void seekToEnd(Collection collection) {
    consumer.seekToEnd(collection);
  }

  @Override
  public long position(TopicPartition topicPartition) {
    return consumer.position(topicPartition);
  }

  @Override
  public long position(TopicPartition partition, Duration timeout) {
    return consumer.position(partition, timeout);
  }

  @Override
  public OffsetAndMetadata committed(TopicPartition topicPartition) {
    return consumer.committed(topicPartition);
  }

  @Override
  public OffsetAndMetadata committed(TopicPartition partition, Duration timeout) {
    return consumer.committed(partition, timeout);
  }

  @Override
  public Map committed(Set partitions) {
    return consumer.committed(partitions);
  }

  @Override
  public Map committed(Set partitions, Duration timeout) {
    return consumer.committed(partitions, timeout);
  }

  @Override
  public Map metrics() {
    return consumer.metrics();
  }

  @Override
  public List partitionsFor(String s) {
    return consumer.partitionsFor(s);
  }

  @Override
  public List partitionsFor(String topic, Duration timeout) {
    return consumer.partitionsFor(topic, timeout);
  }

  @Override
  public Map> listTopics() {
    return consumer.listTopics();
  }

  @Override
  public Map> listTopics(Duration timeout) {
    return consumer.listTopics(timeout);
  }

  @Override
  public Set paused() {
    return consumer.paused();
  }

  @Override
  public void pause(Collection collection) {
    consumer.pause(collection);
  }

  @Override
  public void resume(Collection collection) {
    consumer.resume(collection);
  }

  @Override
  public Map offsetsForTimes(Map map) {
    return consumer.offsetsForTimes(map);
  }

  @Override
  public Map offsetsForTimes(Map timestampsToSearch, Duration timeout) {
    return consumer.offsetsForTimes(timestampsToSearch, timeout);
  }

  @Override
  public Map beginningOffsets(Collection collection) {
    return consumer.beginningOffsets(collection);
  }

  @Override
  public Map beginningOffsets(Collection partitions, Duration timeout) {
    return consumer.beginningOffsets(partitions, timeout);
  }

  @Override
  public Map endOffsets(Collection collection) {
    return consumer.endOffsets(collection);
  }

  @Override
  public Map endOffsets(Collection partitions, Duration timeout) {
    return consumer.endOffsets(partitions, timeout);
  }

  @Override
  public ConsumerGroupMetadata groupMetadata() {
    return consumer.groupMetadata();
  }

  @Override
  public void enforceRebalance() {
    consumer.enforceRebalance();
  }

  @Override
  public void close() {
    consumer.close();
    callback.run();
  }

  @Override
  public void close(long l, TimeUnit timeUnit) {
    consumer.close(l, timeUnit);
    callback.run();
  }

  @Override
  public void close(Duration timeout) {
    consumer.close(timeout);
    callback.run();
  }

  @Override
  public void wakeup() {
    consumer.wakeup();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy