Skip to content

Commit 5c78c30

Browse files
garyrussellartembilan
authored andcommitted
spring-projectsGH-597: Add default impls for listener methods
Resolves spring-projects#597 Add default no-op methods as a convenience so only those that are needed have to be implemented.
1 parent 9be96d5 commit 5c78c30

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

spring-kafka/src/main/java/org/springframework/kafka/listener/ConsumerAwareRebalanceListener.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,9 @@
2323
import org.apache.kafka.common.TopicPartition;
2424

2525
/**
26-
* A rebalance listener that provides access to the consumer object.
26+
* A rebalance listener that provides access to the consumer object. Starting with version
27+
* 2.1.5, as a convenience, default no-op implementations are provided for all methods,
28+
* allowing the user to implement just those (s)he is interested in.
2729
*
2830
* @author Gary Russell
2931
* @since 2.0
@@ -37,23 +39,29 @@ public interface ConsumerAwareRebalanceListener extends ConsumerRebalanceListene
3739
* @param consumer the consumer.
3840
* @param partitions the partitions.
3941
*/
40-
void onPartitionsRevokedBeforeCommit(Consumer<?, ?> consumer, Collection<TopicPartition> partitions);
42+
default void onPartitionsRevokedBeforeCommit(Consumer<?, ?> consumer, Collection<TopicPartition> partitions) {
43+
// do nothing
44+
}
4145

4246
/**
4347
* The same as {@link #onPartitionsRevoked(Collection)} with the additional consumer
4448
* parameter. It is invoked by the container after any pending offsets are committed.
4549
* @param consumer the consumer.
4650
* @param partitions the partitions.
4751
*/
48-
void onPartitionsRevokedAfterCommit(Consumer<?, ?> consumer, Collection<TopicPartition> partitions);
52+
default void onPartitionsRevokedAfterCommit(Consumer<?, ?> consumer, Collection<TopicPartition> partitions) {
53+
// do nothing
54+
}
4955

5056
/**
5157
* The same as {@link #onPartitionsAssigned(Collection)} with the additional consumer
5258
* parameter.
5359
* @param consumer the consumer.
5460
* @param partitions the partitions.
5561
*/
56-
void onPartitionsAssigned(Consumer<?, ?> consumer, Collection<TopicPartition> partitions);
62+
default void onPartitionsAssigned(Consumer<?, ?> consumer, Collection<TopicPartition> partitions) {
63+
// do nothing
64+
}
5765

5866
@Override
5967
default void onPartitionsRevoked(Collection<TopicPartition> partitions) {

0 commit comments

Comments
 (0)