feat: use java 8 api instead of exposing guava types #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi qdrant team.
Well, this is quite a big PR for a first contribution... all the more so as it introduces a breaking change.
And without even starting a discussion before proposing this PR.
So first of all, I apologize for that.
Why this PR?
Currently, the
QdrantClient
exposesListenableFuture
guava type in its public api. Prior to java 8, the guava library was the only way to implement asynchronous programming in java. Starting with java 8,CompletionStage
andCompletableFuture
have been added for that purpose.Usually,
ListenableFuture
is used when java 6/7 compatibility is required. Since Qdrant java-client requires java 8 minimum, there's nothing preventing the use ofCompletableFuture
.I have spent so much time migrating code base from
ListenableFuture
toCompletableFuture
... I don't want to migrate yet another code base just because a new library exposingListenableFuture
is added. So I started to write a wrapper aroundQdrantClient
to get rid ofListenableFuture
.The goal of this PR is to remove the usage of
ListenableFuture
in the public api of this library. So I can avoid using a wrapper (good for me!) and you will avoid exposing thirdparty library to your public api (good for you!).Why not just sticking with ListenableFuture?
ListenableFuture
tends to be less and less used in favor ofCompletableFuture
. At any time, the guava team may decide to move forward and uses the official api. This change may never happen admittedly, yet the official guava documentation is mentioning this eventuality.For example, the datastax cassandra client library moves from
ListenableFuture
toCompletableFuture
(version 3 is usingListenableFuture
while version 4 usesCompletableFuture
).The more we wait, the more painful the migration will be.
How the migration have been done in this PR?
Since grpc is using
ListenableFuture
, we have to convertListenableFuture
toCompletableFuture
. The easiest way to do that is to use the future-converter library.Now, the drawbacks of using this library are the following:
To avoid these drawbacks, I have copied and paste code from future-converter in a sub-package. Fortunately, it's the same license!
For the other parts of the migration, I used this guide.
Please not that the guava library is still required at runtime to use your lib. Yet, it is no more exposed in the public api. So guava could be (hypothetically) safely removed without harm in a future version.
What if this PR is rejected?
It's perfectly fine, no drama! Introducing a breaking change is always a hard choice.
I would like to avoid breaking change
Maybe other strategies can be considered, such as adding a new
QdrantClientJava8
while keeping the current one to maintain backwards compatibility (or to ease the migration). This comes with the drawback of having to maintain two versions of the code.At least, we could use this PR to discuss alternatives.
Thanks for taking the time to read this PR.