001/*
002 * Copyright (c) 2007-2022 The Cascading Authors. All Rights Reserved.
003 *
004 * Project and contact information: https://cascading.wensel.net/
005 *
006 * This file is part of the Cascading project.
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *     http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020
021package cascading.local.tap.kafka.decorator;
022
023import java.time.Duration;
024import java.util.Collection;
025import java.util.List;
026import java.util.Map;
027import java.util.Properties;
028import java.util.Set;
029import java.util.concurrent.TimeUnit;
030import java.util.regex.Pattern;
031
032import org.apache.kafka.clients.consumer.Consumer;
033import org.apache.kafka.clients.consumer.ConsumerRebalanceListener;
034import org.apache.kafka.clients.consumer.ConsumerRecords;
035import org.apache.kafka.clients.consumer.KafkaConsumer;
036import org.apache.kafka.clients.consumer.OffsetAndMetadata;
037import org.apache.kafka.clients.consumer.OffsetAndTimestamp;
038import org.apache.kafka.clients.consumer.OffsetCommitCallback;
039import org.apache.kafka.common.Metric;
040import org.apache.kafka.common.MetricName;
041import org.apache.kafka.common.PartitionInfo;
042import org.apache.kafka.common.TopicPartition;
043
044/**
045 *
046 */
047public class ForwardingConsumer<K, V> implements Consumer<K, V>
048  {
049  Consumer<K, V> consumer;
050
051  public ForwardingConsumer( Properties properties )
052    {
053    this.consumer = createKafkaConsumerInstance( properties );
054    }
055
056  protected KafkaConsumer<K, V> createKafkaConsumerInstance( Properties properties )
057    {
058    return new KafkaConsumer<>( properties );
059    }
060
061  public Consumer<K, V> getConsumer()
062    {
063    return consumer;
064    }
065
066  @Override
067  public Set<TopicPartition> assignment()
068    {
069    return consumer.assignment();
070    }
071
072  @Override
073  public Set<String> subscription()
074    {
075    return consumer.subscription();
076    }
077
078  @Override
079  public void subscribe( Collection<String> collection )
080    {
081    consumer.subscribe( collection );
082    }
083
084  @Override
085  public void subscribe( Collection<String> collection, ConsumerRebalanceListener consumerRebalanceListener )
086    {
087    consumer.subscribe( collection, consumerRebalanceListener );
088    }
089
090  @Override
091  public void assign( Collection<TopicPartition> collection )
092    {
093    consumer.assign( collection );
094    }
095
096  @Override
097  public void subscribe( Pattern pattern, ConsumerRebalanceListener consumerRebalanceListener )
098    {
099    consumer.subscribe( pattern, consumerRebalanceListener );
100    }
101
102  @Override
103  public void subscribe( Pattern pattern )
104    {
105    consumer.subscribe( pattern );
106    }
107
108  @Override
109  public void unsubscribe()
110    {
111    consumer.unsubscribe();
112    }
113
114  @Deprecated
115  @Override
116  public ConsumerRecords<K, V> poll( long l )
117    {
118    return consumer.poll( l );
119    }
120
121  @Override
122  public ConsumerRecords<K, V> poll( Duration duration )
123    {
124    return consumer.poll( duration );
125    }
126
127  @Override
128  public void commitSync()
129    {
130    consumer.commitSync();
131    }
132
133  @Override
134  public void commitSync( Duration duration )
135    {
136    consumer.commitSync( duration );
137    }
138
139  @Override
140  public void commitSync( Map<TopicPartition, OffsetAndMetadata> map )
141    {
142    consumer.commitSync( map );
143    }
144
145  @Override
146  public void commitSync( Map<TopicPartition, OffsetAndMetadata> map, Duration duration )
147    {
148    consumer.commitSync( map, duration );
149    }
150
151  @Override
152  public void commitAsync()
153    {
154    consumer.commitAsync();
155    }
156
157  @Override
158  public void commitAsync( OffsetCommitCallback offsetCommitCallback )
159    {
160    consumer.commitAsync( offsetCommitCallback );
161    }
162
163  @Override
164  public void commitAsync( Map<TopicPartition, OffsetAndMetadata> map, OffsetCommitCallback offsetCommitCallback )
165    {
166    consumer.commitAsync( map, offsetCommitCallback );
167    }
168
169  @Override
170  public void seek( TopicPartition topicPartition, long l )
171    {
172    consumer.seek( topicPartition, l );
173    }
174
175  @Override
176  public void seekToBeginning( Collection<TopicPartition> collection )
177    {
178    consumer.seekToBeginning( collection );
179    }
180
181  @Override
182  public void seekToEnd( Collection<TopicPartition> collection )
183    {
184    consumer.seekToEnd( collection );
185    }
186
187  @Override
188  public long position( TopicPartition topicPartition )
189    {
190    return consumer.position( topicPartition );
191    }
192
193  @Override
194  public long position( TopicPartition topicPartition, Duration duration )
195    {
196    return consumer.position( topicPartition, duration );
197    }
198
199  @Override
200  public OffsetAndMetadata committed( TopicPartition topicPartition )
201    {
202    return consumer.committed( topicPartition );
203    }
204
205  @Override
206  public OffsetAndMetadata committed( TopicPartition topicPartition, Duration duration )
207    {
208    return consumer.committed( topicPartition, duration );
209    }
210
211  @Override
212  public Map<MetricName, ? extends Metric> metrics()
213    {
214    return consumer.metrics();
215    }
216
217  @Override
218  public List<PartitionInfo> partitionsFor( String string )
219    {
220    return consumer.partitionsFor( string );
221    }
222
223  @Override
224  public List<PartitionInfo> partitionsFor( String string, Duration duration )
225    {
226    return consumer.partitionsFor( string, duration );
227    }
228
229  @Override
230  public Map<String, List<PartitionInfo>> listTopics()
231    {
232    return consumer.listTopics();
233    }
234
235  @Override
236  public Map<String, List<PartitionInfo>> listTopics( Duration duration )
237    {
238    return consumer.listTopics( duration );
239    }
240
241  @Override
242  public Set<TopicPartition> paused()
243    {
244    return consumer.paused();
245    }
246
247  @Override
248  public void pause( Collection<TopicPartition> collection )
249    {
250    consumer.pause( collection );
251    }
252
253  @Override
254  public void resume( Collection<TopicPartition> collection )
255    {
256    consumer.resume( collection );
257    }
258
259  @Override
260  public Map<TopicPartition, OffsetAndTimestamp> offsetsForTimes( Map<TopicPartition, Long> map )
261    {
262    return consumer.offsetsForTimes( map );
263    }
264
265  @Override
266  public Map<TopicPartition, OffsetAndTimestamp> offsetsForTimes( Map<TopicPartition, Long> map, Duration duration )
267    {
268    return consumer.offsetsForTimes( map, duration );
269    }
270
271  @Override
272  public Map<TopicPartition, Long> beginningOffsets( Collection<TopicPartition> collection )
273    {
274    return consumer.beginningOffsets( collection );
275    }
276
277  @Override
278  public Map<TopicPartition, Long> beginningOffsets( Collection<TopicPartition> collection, Duration duration )
279    {
280    return consumer.beginningOffsets( collection, duration );
281    }
282
283  @Override
284  public Map<TopicPartition, Long> endOffsets( Collection<TopicPartition> collection )
285    {
286    return consumer.endOffsets( collection );
287    }
288
289  @Override
290  public Map<TopicPartition, Long> endOffsets( Collection<TopicPartition> collection, Duration duration )
291    {
292    return consumer.endOffsets( collection, duration );
293    }
294
295  @Override
296  public void close()
297    {
298    consumer.close();
299    }
300
301  @Deprecated
302  @Override
303  public void close( long l, TimeUnit timeUnit )
304    {
305    consumer.close( l, timeUnit );
306    }
307
308  @Override
309  public void close( Duration duration )
310    {
311    consumer.close( duration );
312    }
313
314  @Override
315  public void wakeup()
316    {
317    consumer.wakeup();
318    }
319  }