-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Future-proof some Guava usage #5414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f4deddf
a54c7e5
6f8cd33
6491e47
b9cc2ab
7e34fd3
f831dcb
ac6caa5
5b696a9
3240728
fa03a75
13692b8
72f53df
cc5d60e
3bbe113
716c631
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| com.google.common.collect.MapMaker @ Create java.util.concurrent.ConcurrentHashMap directly | ||
| com.google.common.collect.Maps#newConcurrentMap() @ Create java.util.concurrent.ConcurrentHashMap directly | ||
| com.google.common.collect.Maps#newConcurrentMap() @ Create java.util.concurrent.ConcurrentHashMap directly | ||
| com.google.common.util.concurrent.Futures#transform(com.google.common.util.concurrent.ListenableFuture, com.google.common.util.concurrent.AsyncFunction) @ Use io.druid.java.util.common.concurrent.ListenableFutures#transformAsync | ||
| com.google.common.collect.Iterators#emptyIterator() @ Use java.util.Collections#emptyIterator() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.druid.java.util.common.concurrent; | ||
|
|
||
| import com.google.common.util.concurrent.FutureCallback; | ||
| import com.google.common.util.concurrent.Futures; | ||
| import com.google.common.util.concurrent.ListenableFuture; | ||
| import com.google.common.util.concurrent.SettableFuture; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import java.util.function.Function; | ||
|
|
||
| public class ListenableFutures | ||
| { | ||
| /** | ||
| * Guava 19 changes the Futures.transform signature so that the async form is different. This is here as a | ||
| * compatability layer until such a time as druid only supports Guava 19 or later, in which case | ||
| * Futures.transformAsync should be used | ||
| * | ||
| * This is NOT copied from guava. | ||
| */ | ||
| public static <I, O> ListenableFuture<O> transformAsync( | ||
| final ListenableFuture<I> inFuture, | ||
| final Function<I, ListenableFuture<O>> transform | ||
| ) | ||
| { | ||
| final SettableFuture<O> finalFuture = SettableFuture.create(); | ||
| Futures.addCallback(inFuture, new FutureCallback<I>() | ||
| { | ||
| @Override | ||
| public void onSuccess(@Nullable I result) | ||
| { | ||
| final ListenableFuture<O> transformFuture = transform.apply(result); | ||
| Futures.addCallback(transformFuture, new FutureCallback<O>() | ||
| { | ||
| @Override | ||
| public void onSuccess(@Nullable O result) | ||
| { | ||
| finalFuture.set(result); | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(Throwable t) | ||
| { | ||
| finalFuture.setException(t); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(Throwable t) | ||
| { | ||
| finalFuture.setException(t); | ||
| } | ||
| }); | ||
| return finalFuture; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -352,6 +352,11 @@ | |
| <artifactId>guice-multibindings</artifactId> | ||
| <version>${guice.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this? Why this is needed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Future versions of guava fail to pull this in. 19 specifically if I recall. This causes builds to fail for guava 19 without it. |
||
| <groupId>com.google.errorprone</groupId> | ||
| <artifactId>error_prone_annotations</artifactId> | ||
| <version>2.2.0</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.ibm.icu</groupId> | ||
| <artifactId>icu4j</artifactId> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code copied from Guava? If so, the comment should say so. If not, the comment should also say so, since people might think it was anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed