-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
CompletableFuture
for method return types
Implements support for `CompletableFuture` on method return types by converting through RxJava `Observable`
- Loading branch information
Showing
8 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[pom.xml] | ||
indent_size = 2 | ||
|
||
[*.xml] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
hystrix/src/main/java/feign/hystrix/ObservableCompletableFuture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package feign.hystrix; | ||
|
||
import com.netflix.hystrix.HystrixCommand; | ||
import org.jvnet.animal_sniffer.IgnoreJRERequirement; | ||
import rx.Subscription; | ||
import rx.functions.Action1; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
@IgnoreJRERequirement | ||
final class ObservableCompletableFuture<T> extends CompletableFuture<T> { | ||
|
||
private final Subscription sub; | ||
|
||
ObservableCompletableFuture(final HystrixCommand<T> command) { | ||
this.sub = command.toObservable().single().subscribe(new Action1<T>() { | ||
@Override | ||
public void call(final T o) { | ||
ObservableCompletableFuture.this.complete(o); | ||
} | ||
}, new Action1<Throwable>() { | ||
@Override | ||
public void call(final Throwable throwable) { | ||
ObservableCompletableFuture.this.completeExceptionally(throwable); | ||
} | ||
}); | ||
} | ||
|
||
|
||
@Override | ||
public boolean cancel(final boolean b) { | ||
sub.unsubscribe(); | ||
return super.cancel(b); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package feign.hystrix; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
import static feign.Util.resolveLastTypeParameter; | ||
|
||
final class Util { | ||
|
||
private static final Class<?> COMPLETABLE_FUTURE_CLASS; | ||
|
||
static { | ||
Class<?> clazz = null; | ||
try { | ||
clazz = Class.forName("java.util.concurrent.CompletableFuture"); | ||
} catch (ClassNotFoundException e) { | ||
// Not running on Java 8+ | ||
} | ||
|
||
COMPLETABLE_FUTURE_CLASS = clazz; | ||
} | ||
|
||
static boolean isCompletableFuture(final Class<?> clazz) { | ||
return COMPLETABLE_FUTURE_CLASS != null && COMPLETABLE_FUTURE_CLASS.isAssignableFrom(clazz); | ||
} | ||
|
||
static boolean isCompletableFuture(final Type type) { | ||
return COMPLETABLE_FUTURE_CLASS != null && type.equals(COMPLETABLE_FUTURE_CLASS); | ||
} | ||
|
||
static Type resolveTypeParameter(final Type type) { | ||
return resolveLastTypeParameter(type, COMPLETABLE_FUTURE_CLASS); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters