...
This means you cannot implement them with a java 8 lambda, as that only works for functional interfaces.
Public Interfaces
From In the public interfcateinterface, only org.apache.kafka.common.KafkaFuture
has such helper classes which can better be expressed as functional interfaces.
Proposed Changes
The current proposal implemented in PR#4033 makes from those abstract classes interfaces.
This is a binary incompatible change. Which might be acceptable as KafkaFuture
is annotated as InterfaceStability.Evolving
, where compatibility may be broken at minor release.
This change also helps to move KafkaFuture
closer to the interface of a java 8 CompletableFuture. As KafkaFuture
's javadoc states:
...
introduces a FunctionInterface
which defines the new functional interface. The old Function
class is kept and marked as @Deprecated
.
This class is there to guarantee binary compatibility, also for the thenApply
function (the only public function which was using this Function
object) the old signature is kept next to the new one.
As the Biconsumer
class was not used in the public interface, I decided to stick there with a backwards incompatible change.
Compatibility, Deprecation, and Migration Plan
When the change is implemented like proposed, everybody using this api will need to implement instead of extend their implementations of KafkaFuture.Function
and KafkaFuture.Biconsumer
will get a deprecation warning.
...
Rejected Alternatives
- Keep the current interface as is, as a nicer syntax to address this api might not be worth breaking backwards compatibility
- Wait for a kafka release which will not support java 7 anymore. A backwards incompatible change can then be done to replace
KafkaFuture
withCompletableFuture
Spend more effort and update the definition ofKafkaFuture
in such a way that it gradually switches toCompletableFuture
. By following an approach which looks like this: - Create new interface versions of
KafkaFuture.Function
andKafkaFuture.BiConsumer
, create new methods which handle those functional interface and preferably line their names up with those ofCompletableFuture
. So for exampleKafkaFuture.addWaiter(BiConsumer)
becomesKafkaFuture.whenComplete(BiConsumerInterface)
. Mark the old methods as@Deprecated
. - When kafka does not support java 7 anymore, let
KafkaFuture
extendCompletableFuture
(or evenCompletionStage
) Later on the deprecated methods can be removed, and
KafkaFuture
becomes a shim on Completablefuture
or CompletionStage
.And replace or extend KafkaFuture
with the java 8 CompletionStage
. This KIP can then become part of KIP-118: Drop Support for Java 7 in Kafka 0.11