diff options
author | Jiayu Liu <jiayu.liu@airbnb.com> | 2022-04-12 22:42:10 +0800 |
---|---|---|
committer | Jens Geyer <Jens-G@users.noreply.github.com> | 2022-04-13 21:49:21 +0200 |
commit | aa82214dbc1ee981040719067a6d4eb7791fe7ec (patch) | |
tree | d4f6cbe4ace2e8cf64ea27d9f2690fae354d011a /lib/java | |
parent | 2f6ddc91456aaa18e017ba1aa95dbd5f98525fce (diff) | |
download | thrift-aa82214dbc1ee981040719067a6d4eb7791fe7ec.tar.gz |
add interface generation
Diffstat (limited to 'lib/java')
-rw-r--r-- | lib/java/gradle/generateTestThrift.gradle | 4 | ||||
-rw-r--r-- | lib/java/src/org/apache/thrift/async/AsyncMethodFutureAdapter.java | 35 |
2 files changed, 37 insertions, 2 deletions
diff --git a/lib/java/gradle/generateTestThrift.gradle b/lib/java/gradle/generateTestThrift.gradle index 924dd0d0f..d5bc3afaf 100644 --- a/lib/java/gradle/generateTestThrift.gradle +++ b/lib/java/gradle/generateTestThrift.gradle @@ -91,7 +91,7 @@ task generateBeanJava(group: 'Build') { ext.outputBuffer = new ByteArrayOutputStream() - thriftCompile(it, 'JavaBeansTest.thrift', 'java:beans,nocamel', genBeanSrc) + thriftCompile(it, 'JavaBeansTest.thrift', 'java:beans,nocamel,future_iface', genBeanSrc) } task generateReuseJava(group: 'Build') { @@ -100,7 +100,7 @@ task generateReuseJava(group: 'Build') { ext.outputBuffer = new ByteArrayOutputStream() - thriftCompile(it, 'FullCamelTest.thrift', 'java:fullcamel', genFullCamelSrc) + thriftCompile(it, 'FullCamelTest.thrift', 'java:fullcamel,future_iface', genFullCamelSrc) } task generateFullCamelJava(group: 'Build') { diff --git a/lib/java/src/org/apache/thrift/async/AsyncMethodFutureAdapter.java b/lib/java/src/org/apache/thrift/async/AsyncMethodFutureAdapter.java new file mode 100644 index 000000000..0bee3a7cf --- /dev/null +++ b/lib/java/src/org/apache/thrift/async/AsyncMethodFutureAdapter.java @@ -0,0 +1,35 @@ +package org.apache.thrift.async; + +import java.util.concurrent.CompletableFuture; + +/** + * A simple adapter that bridges {@link AsyncMethodCallback} with {@link CompletableFuture}-returning style clients. + * Compiler generated code will invoke this adapter to implement {@code FutureClient}s. + * + * @param <T> return type (can be {@link Void}). + */ +public final class AsyncMethodFutureAdapter<T> implements AsyncMethodCallback<T> { + + private AsyncMethodFutureAdapter() { + } + + public static <T> AsyncMethodFutureAdapter<T> create() { + return new AsyncMethodFutureAdapter<>(); + } + + private final CompletableFuture<T> future = new CompletableFuture<>(); + + public CompletableFuture<T> getFuture() { + return future; + } + + @Override + public void onComplete(T response) { + future.complete(response); + } + + @Override + public void onError(Exception exception) { + future.completeExceptionally(exception); + } +} |