Skip to content

Commit 9471340

Browse files
pda4codeTotktonada
authored andcommitted
Add CompletionStage support in TarantoolClient
Minimal java version changed from 1.6 to 1.8. Add support of composable operations as ability to return TarantoolClientOps with CompletionStage as Result. This feature is taken from peterservice's fork (see https://github.com/peterservice-rnd/tarantool-java) FutureImpl is replaced with CompletableFuture under the hood of TarantoolClientImpl. Note about behaviour of CompletableFuture (relatively FutureImpl): a result of a CompletableFuture future will not change after the first call of the 'complete' method (unlike FutureImpl.setValue). test: add ClientComposableAsyncOpsIT and AbstractAsyncClientOperationsIT as ancestor of it and AsyncClientOperationsIT. Fixes #102
1 parent d082f1c commit 9471340

10 files changed

+305
-265
lines changed

Diff for: README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,18 @@ TarantoolClient client = new TarantoolClientImpl(socketChannelProvider, config);
110110
> resolution, you could create a function that returns necessary name-to-ID
111111
> mappings.
112112
113-
`TarantoolClient` provides three interfaces to execute queries:
113+
`TarantoolClient` provides four interfaces to execute queries:
114114

115115
* `SyncOps` - returns the operation result
116116
* `AsyncOps` - returns the operation result as a `Future`
117+
* `ComposableAsyncOps` - return the operation result as a `CompletionStage`
117118
* `FireAndForgetOps` - returns the query ID
118119

119120
Feel free to override any method of `TarantoolClientImpl`. For example, to hook
120121
all the results, you could override this:
121122

122123
```java
123-
protected void complete(long code, FutureImpl<?> q);
124+
protected void complete(long code, CompletableFuture<?> q);
124125
```
125126

126127
## Spring NamedParameterJdbcTemplate usage example

Diff for: pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
<artifactId>maven-compiler-plugin</artifactId>
4343
<version>3.2</version>
4444
<configuration>
45-
<source>1.6</source>
46-
<target>1.6</target>
45+
<source>1.8</source>
46+
<target>1.8</target>
4747
</configuration>
4848
</plugin>
4949
<!--

Diff for: src/it/java/org/tarantool/TestTarantoolClient.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.nio.channels.SocketChannel;
77
import java.sql.SQLException;
88
import java.util.Arrays;
9-
import java.util.List;
9+
import java.util.concurrent.CompletableFuture;
1010
import java.util.concurrent.ExecutionException;
1111
import java.util.concurrent.ExecutorService;
1212
import java.util.concurrent.Executors;
@@ -81,7 +81,7 @@ protected void reconnect(int retry, Throwable lastError) {
8181
}
8282

8383
@Override
84-
protected void complete(long code, FutureImpl<?> q) {
84+
protected void complete(long code, CompletableFuture<?> q) {
8585
super.complete(code, q);
8686
if (code != 0) {
8787
System.out.println(code);

Diff for: src/main/java/org/tarantool/FutureImpl.java

-99
This file was deleted.

Diff for: src/main/java/org/tarantool/TarantoolClient.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.List;
44
import java.util.Map;
5+
import java.util.concurrent.CompletionStage;
56
import java.util.concurrent.Future;
67
import java.util.concurrent.TimeUnit;
78

@@ -10,9 +11,11 @@ public interface TarantoolClient {
1011

1112
TarantoolClientOps<Integer, List<?>, Object, Future<List<?>>> asyncOps();
1213

14+
TarantoolClientOps<Integer, List<?>, Object, CompletionStage<List<?>>> composableAsyncOps();
15+
1316
TarantoolClientOps<Integer, List<?>, Object, Long> fireAndForgetOps();
1417

15-
TarantoolSQLOps<Object, Long, List<Map<String,Object>>> sqlSyncOps();
18+
TarantoolSQLOps<Object, Long, List<Map<String, Object>>> sqlSyncOps();
1619

1720
TarantoolSQLOps<Object, Future<Long>, Future<List<Map<String, Object>>>> sqlAsyncOps();
1821

0 commit comments

Comments
 (0)