From 5061312e9a0a4367c957810d79e3399ad29e4a0b Mon Sep 17 00:00:00 2001 From: Pavel Vorobyev Date: Sat, 17 Feb 2024 21:53:45 +0300 Subject: [PATCH 1/7] minimal java version from 1.6 to 1.8 --- example/java/README.md | 2 +- example/java/td_jni.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/java/README.md b/example/java/README.md index bca3e7ad9c76..898b61385487 100644 --- a/example/java/README.md +++ b/example/java/README.md @@ -1,6 +1,6 @@ # TDLib Java example -To run this example, you will need installed JDK >= 1.6. +To run this example, you will need installed JDK >= 1.8. For Javadoc documentation generation PHP is needed. You can find complete build instructions for your operating system at https://tdlib.github.io/td/build.html?language=Java. diff --git a/example/java/td_jni.cpp b/example/java/td_jni.cpp index 0271e0575094..4815af5ac3dc 100644 --- a/example/java/td_jni.cpp +++ b/example/java/td_jni.cpp @@ -84,7 +84,7 @@ static jstring Function_toString(JNIEnv *env, jobject object) { return td::jni::to_jstring(env, to_string(td::td_api::Function::fetch(env, object))); } -static constexpr jint JAVA_VERSION = JNI_VERSION_1_6; +static constexpr jint JAVA_VERSION = JNI_VERSION_1_8; static JavaVM *java_vm; static jobject log_message_handler; From 37a7c1c1ba4ed44795bc20a4451ef1df204d9020 Mon Sep 17 00:00:00 2001 From: Pavel Vorobyev Date: Sat, 17 Feb 2024 21:57:29 +0300 Subject: [PATCH 2/7] added option to java client to send query with CompletableFuture response --- example/java/org/drinkless/tdlib/Client.java | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/example/java/org/drinkless/tdlib/Client.java b/example/java/org/drinkless/tdlib/Client.java index 8783135437a3..83641446afa7 100644 --- a/example/java/org/drinkless/tdlib/Client.java +++ b/example/java/org/drinkless/tdlib/Client.java @@ -6,6 +6,7 @@ // package org.drinkless.tdlib; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; @@ -111,6 +112,27 @@ public void send(TdApi.Function query, ResultHandler resultHandler) { send(query, resultHandler, null); } + /** + * Sends a request to the TDLib. + * + * @param query Object representing a query to the TDLib. + * @param Automatically deduced return type of the query. + * @return {@link CompletableFuture} response with result type + * If this stage completes exceptionally it throws {@link ExecutionException} + */ + @SuppressWarnings("unchecked") + public CompletableFuture send(TdApi.Function query) { + CompletableFuture future = new CompletableFuture<>(); + send(query, object -> { + if (object instanceof TdApi.Error) { + future.completeExceptionally(new ExecutionException((TdApi.Error) object)); + } else { + future.complete((T) object); + } + }); + return future; + } + /** * Synchronously executes a TDLib request. Only a few marked accordingly requests can be executed synchronously. * From 4eae9949f301e3baf6a7524045c4e97566a65e80 Mon Sep 17 00:00:00 2001 From: Pavel Vorobyev Date: Sat, 17 Feb 2024 22:00:46 +0300 Subject: [PATCH 3/7] minimal java version from 1.6 to 1.8 --- example/java/README.md | 2 +- example/java/td_jni.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/java/README.md b/example/java/README.md index bca3e7ad9c76..898b61385487 100644 --- a/example/java/README.md +++ b/example/java/README.md @@ -1,6 +1,6 @@ # TDLib Java example -To run this example, you will need installed JDK >= 1.6. +To run this example, you will need installed JDK >= 1.8. For Javadoc documentation generation PHP is needed. You can find complete build instructions for your operating system at https://tdlib.github.io/td/build.html?language=Java. diff --git a/example/java/td_jni.cpp b/example/java/td_jni.cpp index 0271e0575094..4815af5ac3dc 100644 --- a/example/java/td_jni.cpp +++ b/example/java/td_jni.cpp @@ -84,7 +84,7 @@ static jstring Function_toString(JNIEnv *env, jobject object) { return td::jni::to_jstring(env, to_string(td::td_api::Function::fetch(env, object))); } -static constexpr jint JAVA_VERSION = JNI_VERSION_1_6; +static constexpr jint JAVA_VERSION = JNI_VERSION_1_8; static JavaVM *java_vm; static jobject log_message_handler; From 5c981e0cd90ee7ba3b2faf7551c8f043bf4ac3ab Mon Sep 17 00:00:00 2001 From: Pavel Vorobyev Date: Sat, 17 Feb 2024 22:00:59 +0300 Subject: [PATCH 4/7] added option to java client to send query with CompletableFuture response --- example/java/org/drinkless/tdlib/Client.java | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/example/java/org/drinkless/tdlib/Client.java b/example/java/org/drinkless/tdlib/Client.java index 8783135437a3..83641446afa7 100644 --- a/example/java/org/drinkless/tdlib/Client.java +++ b/example/java/org/drinkless/tdlib/Client.java @@ -6,6 +6,7 @@ // package org.drinkless.tdlib; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; @@ -111,6 +112,27 @@ public void send(TdApi.Function query, ResultHandler resultHandler) { send(query, resultHandler, null); } + /** + * Sends a request to the TDLib. + * + * @param query Object representing a query to the TDLib. + * @param Automatically deduced return type of the query. + * @return {@link CompletableFuture} response with result type + * If this stage completes exceptionally it throws {@link ExecutionException} + */ + @SuppressWarnings("unchecked") + public CompletableFuture send(TdApi.Function query) { + CompletableFuture future = new CompletableFuture<>(); + send(query, object -> { + if (object instanceof TdApi.Error) { + future.completeExceptionally(new ExecutionException((TdApi.Error) object)); + } else { + future.complete((T) object); + } + }); + return future; + } + /** * Synchronously executes a TDLib request. Only a few marked accordingly requests can be executed synchronously. * From 2d65201af9c4a90eba299b739005bd45c73fb9f9 Mon Sep 17 00:00:00 2001 From: Pavel Vorobyev Date: Sat, 17 Feb 2024 22:01:47 +0300 Subject: [PATCH 5/7] Revert "added option to java client to send query with CompletableFuture response" This reverts commit 37a7c1c1ba4ed44795bc20a4451ef1df204d9020. --- example/java/org/drinkless/tdlib/Client.java | 22 -------------------- 1 file changed, 22 deletions(-) diff --git a/example/java/org/drinkless/tdlib/Client.java b/example/java/org/drinkless/tdlib/Client.java index 83641446afa7..8783135437a3 100644 --- a/example/java/org/drinkless/tdlib/Client.java +++ b/example/java/org/drinkless/tdlib/Client.java @@ -6,7 +6,6 @@ // package org.drinkless.tdlib; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; @@ -112,27 +111,6 @@ public void send(TdApi.Function query, ResultHandler resultHandler) { send(query, resultHandler, null); } - /** - * Sends a request to the TDLib. - * - * @param query Object representing a query to the TDLib. - * @param Automatically deduced return type of the query. - * @return {@link CompletableFuture} response with result type - * If this stage completes exceptionally it throws {@link ExecutionException} - */ - @SuppressWarnings("unchecked") - public CompletableFuture send(TdApi.Function query) { - CompletableFuture future = new CompletableFuture<>(); - send(query, object -> { - if (object instanceof TdApi.Error) { - future.completeExceptionally(new ExecutionException((TdApi.Error) object)); - } else { - future.complete((T) object); - } - }); - return future; - } - /** * Synchronously executes a TDLib request. Only a few marked accordingly requests can be executed synchronously. * From 90bd3951fb97f85e763a0a02c8210121256d7a02 Mon Sep 17 00:00:00 2001 From: Pavel Vorobyev Date: Sat, 17 Feb 2024 22:01:47 +0300 Subject: [PATCH 6/7] Revert "minimal java version from 1.6 to 1.8" This reverts commit 5061312e9a0a4367c957810d79e3399ad29e4a0b. --- example/java/README.md | 2 +- example/java/td_jni.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/java/README.md b/example/java/README.md index 898b61385487..bca3e7ad9c76 100644 --- a/example/java/README.md +++ b/example/java/README.md @@ -1,6 +1,6 @@ # TDLib Java example -To run this example, you will need installed JDK >= 1.8. +To run this example, you will need installed JDK >= 1.6. For Javadoc documentation generation PHP is needed. You can find complete build instructions for your operating system at https://tdlib.github.io/td/build.html?language=Java. diff --git a/example/java/td_jni.cpp b/example/java/td_jni.cpp index 4815af5ac3dc..0271e0575094 100644 --- a/example/java/td_jni.cpp +++ b/example/java/td_jni.cpp @@ -84,7 +84,7 @@ static jstring Function_toString(JNIEnv *env, jobject object) { return td::jni::to_jstring(env, to_string(td::td_api::Function::fetch(env, object))); } -static constexpr jint JAVA_VERSION = JNI_VERSION_1_8; +static constexpr jint JAVA_VERSION = JNI_VERSION_1_6; static JavaVM *java_vm; static jobject log_message_handler; From e8d4948c977a5d3a7cf4a9dbef545c545a5b0eb2 Mon Sep 17 00:00:00 2001 From: Pavel Vorobyev Date: Sun, 10 Mar 2024 01:12:53 +0300 Subject: [PATCH 7/7] added Result class for function call with a future response in java client --- example/java/org/drinkless/tdlib/Client.java | 34 +++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/example/java/org/drinkless/tdlib/Client.java b/example/java/org/drinkless/tdlib/Client.java index 83641446afa7..16afe85d55a0 100644 --- a/example/java/org/drinkless/tdlib/Client.java +++ b/example/java/org/drinkless/tdlib/Client.java @@ -63,6 +63,30 @@ public interface LogMessageHandler { void onLogMessage(int verbosityLevel, String message); } + /** + * Result class for an asynchronous function call with a future response. + * + * @param The object type that is returned by the function + */ + public final static class Result { + + /** + * An object of this type can be returned upon a successful function call, otherwise it will be null. + */ + public final T object; + + /** + * An object of this type can be returned on every function call, in case of an error, otherwise it will be null. + */ + public final TdApi.Error error; + + private Result(T object, TdApi.Error error) { + this.object = object; + this.error = error; + } + + } + /** * Exception class thrown when TDLib error occurred while performing {@link #execute(TdApi.Function)}. */ @@ -117,17 +141,17 @@ public void send(TdApi.Function query, ResultHandler resultHandler) { * * @param query Object representing a query to the TDLib. * @param Automatically deduced return type of the query. - * @return {@link CompletableFuture} response with result type + * @return {@link CompletableFuture} response with {@link Result} * If this stage completes exceptionally it throws {@link ExecutionException} */ @SuppressWarnings("unchecked") - public CompletableFuture send(TdApi.Function query) { - CompletableFuture future = new CompletableFuture<>(); + public CompletableFuture> send(TdApi.Function query) { + CompletableFuture> future = new CompletableFuture<>(); send(query, object -> { if (object instanceof TdApi.Error) { - future.completeExceptionally(new ExecutionException((TdApi.Error) object)); + future.complete(new Result<>(null, (TdApi.Error) object)); } else { - future.complete((T) object); + future.complete(new Result<>((T) object, null)); } }); return future;