diff --git a/.gitignore b/.gitignore
index b6174007b..e5294d8d1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,4 @@ tmp/
*.swo
.bloop/
.metals/
+.vscode/
diff --git a/pom.xml b/pom.xml
index 538ae0000..d1c00272c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -280,10 +280,10 @@
test
- org.openjdk.jmh
- jmh-generator-annprocess
- 1.35
- test
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ 1.35
+ test
org.junit.jupiter
@@ -413,12 +413,19 @@
-classpath
- org.openjdk.jmh.Main]
+ org.openjdk.jmh.Main
+ ${benchmark}
+ ${benchmarkArgs}
+
+ true
+ SingleInstanceBenchmarkRunner
+
+
release
diff --git a/src/main/java/io/tarantool/driver/api/TarantoolCallOperations.java b/src/main/java/io/tarantool/driver/api/TarantoolCallOperations.java
index eb6ff7ae3..d6b7b1d5d 100644
--- a/src/main/java/io/tarantool/driver/api/TarantoolCallOperations.java
+++ b/src/main/java/io/tarantool/driver/api/TarantoolCallOperations.java
@@ -2,7 +2,6 @@
import io.tarantool.driver.exceptions.TarantoolClientException;
import io.tarantool.driver.mappers.CallResultMapper;
-import io.tarantool.driver.mappers.MessagePackMapper;
import io.tarantool.driver.mappers.MessagePackObjectMapper;
import io.tarantool.driver.mappers.converters.ValueConverter;
import io.tarantool.driver.mappers.factories.ResultMapperFactoryFactory;
@@ -54,18 +53,6 @@ public interface TarantoolCallOperations {
*/
CompletableFuture> call(String functionName, Collection> arguments) throws TarantoolClientException;
- /**
- * Execute a function defined on Tarantool instance
- *
- * @param functionName function name, must not be null or empty
- * @param arguments list of function arguments
- * @param mapper mapper for arguments object-to-MessagePack entity conversion and result values conversion
- * @return some result
- * @throws TarantoolClientException if the client is not connected
- */
- CompletableFuture> call(String functionName, Collection> arguments, MessagePackMapper mapper)
- throws TarantoolClientException;
-
/**
* Execute a function defined on Tarantool instance. The call result is interpreted as an array of tuples. The value
* mapper specified in the client configuration will be used for converting the result values from MessagePack
@@ -85,13 +72,13 @@ CompletableFuture> callForTupleResult(String functionName
*
* @param desired function call result type
* @param functionName function name, must not be null or empty
- * @param resultMapper mapper for result value MessagePack entity-to-object conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
*/
CompletableFuture call(
String functionName,
- CallResultMapper> resultMapper)
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException;
/**
@@ -120,14 +107,14 @@ CompletableFuture> callForTupleResult(
* @param functionName function name, must not be null or empty
* @param arguments list of function arguments. The object mapper specified in the client configuration
* will be used for arguments conversion to MessagePack entities
- * @param resultMapper mapper for result value MessagePack entity-to-object conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
*/
CompletableFuture call(
String functionName,
Collection> arguments,
- CallResultMapper> resultMapper)
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException;
/**
@@ -138,7 +125,7 @@ CompletableFuture call(
* @param desired function call result type
* @param functionName function name, must not be null or empty
* @param arguments list of function arguments
- * @param argumentsMapper mapper for arguments object-to-MessagePack entity conversion
+ * @param argumentsMapperSupplier mapper supplier for arguments object-to-MessagePack entity conversion
* @param entityClass target result entity class
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
@@ -146,7 +133,7 @@ CompletableFuture call(
CompletableFuture> callForTupleResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
Class entityClass)
throws TarantoolClientException;
@@ -156,16 +143,16 @@ CompletableFuture> callForTupleResult(
* @param desired function call result type
* @param functionName function name, must not be null or empty
* @param arguments list of function arguments
- * @param argumentsMapper mapper for arguments object-to-MessagePack entity conversion
- * @param resultMapper mapper for result value MessagePack entity-to-object conversion
+ * @param argumentsMapperSupplier mapper supplier for arguments object-to-MessagePack entity conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
*/
CompletableFuture call(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
- CallResultMapper> resultMapper)
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException;
/**
@@ -175,7 +162,7 @@ CompletableFuture call(
* @param target result content type
* @param functionName function name, must not be null or empty
* @param arguments list of function arguments
- * @param argumentsMapper mapper for arguments object-to-MessagePack entity conversion
+ * @param argumentsMapperSupplier mapper supplier for arguments object-to-MessagePack entity conversion
* @param resultClass target result entity class
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
@@ -183,7 +170,7 @@ CompletableFuture call(
CompletableFuture callForSingleResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
Class resultClass)
throws TarantoolClientException;
@@ -194,7 +181,7 @@ CompletableFuture callForSingleResult(
* @param target result content type
* @param functionName function name, must not be null or empty
* @param arguments list of function arguments
- * @param argumentsMapper mapper for arguments object-to-MessagePack entity conversion
+ * @param argumentsMapperSupplier mapper supplier for arguments object-to-MessagePack entity conversion
* @param valueConverter MessagePack value to entity converter for each result item
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
@@ -202,7 +189,7 @@ CompletableFuture callForSingleResult(
CompletableFuture callForSingleResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
ValueConverter valueConverter)
throws TarantoolClientException;
@@ -213,16 +200,16 @@ CompletableFuture callForSingleResult(
* @param target result content type
* @param functionName function name, must not be null or empty
* @param arguments list of function arguments
- * @param argumentsMapper mapper for arguments object-to-MessagePack entity conversion
- * @param resultMapper mapper for result conversion
+ * @param argumentsMapperSupplier mapper supplier for arguments object-to-MessagePack entity conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
*/
CompletableFuture callForSingleResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
- CallResultMapper> resultMapper)
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException;
/**
@@ -266,14 +253,14 @@ CompletableFuture callForSingleResult(
* @param target result content type
* @param functionName function name, must not be null or empty
* @param arguments list of function arguments
- * @param resultMapper mapper for result conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
*/
CompletableFuture callForSingleResult(
String functionName,
Collection> arguments,
- CallResultMapper> resultMapper)
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException;
/**
@@ -312,13 +299,13 @@ CompletableFuture callForSingleResult(
*
* @param target result content type
* @param functionName function name, must not be null or empty
- * @param resultMapper mapper for result conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
*/
CompletableFuture callForSingleResult(
String functionName,
- CallResultMapper> resultMapper)
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException;
/**
@@ -328,7 +315,7 @@ CompletableFuture callForSingleResult(
* @param target result type
* @param functionName function name, must not be null or empty
* @param arguments list of function arguments
- * @param argumentsMapper mapper for arguments object-to-MessagePack entity conversion
+ * @param argumentsMapperSupplier mapper supplier for arguments object-to-MessagePack entity conversion
* @param resultContainerSupplier supplier function for new empty result collection
* @param resultClass target result entity class
* @return some result
@@ -337,7 +324,7 @@ CompletableFuture callForSingleResult(
> CompletableFuture callForMultiResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
Supplier resultContainerSupplier,
Class resultClass)
throws TarantoolClientException;
@@ -349,7 +336,7 @@ > CompletableFuture callForMultiResult(
* @param target result type
* @param functionName function name, must not be null or empty
* @param arguments list of function arguments
- * @param argumentsMapper mapper for arguments object-to-MessagePack entity conversion
+ * @param argumentsMapperSupplier mapper supplier for arguments object-to-MessagePack entity conversion
* @param resultContainerSupplier supplier function for new empty result collection
* @param valueConverter MessagePack value to entity converter for each result item
* @return some result
@@ -358,7 +345,7 @@ > CompletableFuture callForMultiResult(
> CompletableFuture callForMultiResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
Supplier resultContainerSupplier,
ValueConverter valueConverter)
throws TarantoolClientException;
@@ -370,16 +357,16 @@ > CompletableFuture callForMultiResult(
* @param target result type
* @param functionName function name, must not be null or empty
* @param arguments list of function arguments
- * @param argumentsMapper mapper for arguments object-to-MessagePack entity conversion
- * @param resultMapper mapper for result conversion
+ * @param argumentsMapperSupplier mapper supplier for arguments object-to-MessagePack entity conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
*/
> CompletableFuture callForMultiResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
- CallResultMapper> resultMapper)
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException;
/**
@@ -427,14 +414,14 @@ > CompletableFuture callForMultiResult(
* @param target result type
* @param functionName function name, must not be null or empty
* @param arguments list of function arguments
- * @param resultMapper mapper for result conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
*/
> CompletableFuture callForMultiResult(
String functionName,
Collection> arguments,
- CallResultMapper> resultMapper)
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException;
/**
@@ -477,13 +464,13 @@ > CompletableFuture callForMultiResult(
* @param target result content type
* @param target result type
* @param functionName function name, must not be null or empty
- * @param resultMapper mapper for result conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected or some other error occurred
*/
> CompletableFuture callForMultiResult(
String functionName,
- CallResultMapper> resultMapper)
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException;
/**
diff --git a/src/main/java/io/tarantool/driver/api/TarantoolEvalOperations.java b/src/main/java/io/tarantool/driver/api/TarantoolEvalOperations.java
index 68173bb05..4048d552b 100644
--- a/src/main/java/io/tarantool/driver/api/TarantoolEvalOperations.java
+++ b/src/main/java/io/tarantool/driver/api/TarantoolEvalOperations.java
@@ -7,6 +7,7 @@
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
+import java.util.function.Supplier;
/**
* Aggregates all value operation variants
@@ -43,11 +44,11 @@ public interface TarantoolEvalOperations {
* keyword return
.
*
* @param expression lua expression, must not be null or empty
- * @param resultMapper mapper for result value MessagePack entity-to-object conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected
*/
- CompletableFuture> eval(String expression, MessagePackValueMapper resultMapper)
+ CompletableFuture> eval(String expression, Supplier extends MessagePackValueMapper> resultMapperSupplier)
throws TarantoolClientException;
/**
@@ -57,11 +58,12 @@ CompletableFuture> eval(String expression, MessagePackValueMapper result
* @param expression lua expression, must not be null or empty
* @param arguments the list of function arguments. The object mapper specified in the client configuration
* will be used for arguments conversion to MessagePack entities
- * @param resultMapper mapper for result value MessagePack entity-to-object conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected
*/
- CompletableFuture> eval(String expression, Collection> arguments, MessagePackValueMapper resultMapper)
+ CompletableFuture> eval(
+ String expression, Collection> arguments, Supplier extends MessagePackValueMapper> resultMapperSupplier)
throws TarantoolClientException;
/**
@@ -70,14 +72,14 @@ CompletableFuture> eval(String expression, Collection> arguments, Mess
*
* @param expression lua expression, must not be null or empty
* @param arguments the list of function arguments
- * @param argumentsMapper mapper for arguments object-to-MessagePack entity conversion
- * @param resultMapper mapper for result value MessagePack entity-to-object conversion
+ * @param argumentsMapperSupplier mapper supplier for arguments object-to-MessagePack entity conversion
+ * @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected
*/
CompletableFuture> eval(
String expression,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
- MessagePackValueMapper resultMapper) throws TarantoolClientException;
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier extends MessagePackValueMapper> resultMapperSupplier) throws TarantoolClientException;
}
diff --git a/src/main/java/io/tarantool/driver/api/connection/TarantoolConnection.java b/src/main/java/io/tarantool/driver/api/connection/TarantoolConnection.java
index 00915576f..7fe720766 100644
--- a/src/main/java/io/tarantool/driver/api/connection/TarantoolConnection.java
+++ b/src/main/java/io/tarantool/driver/api/connection/TarantoolConnection.java
@@ -2,12 +2,11 @@
import io.netty.channel.Channel;
import io.tarantool.driver.TarantoolVersion;
+import io.tarantool.driver.core.TarantoolRequestMetadata;
import io.tarantool.driver.exceptions.TarantoolClientException;
-import io.tarantool.driver.mappers.MessagePackValueMapper;
import io.tarantool.driver.protocol.TarantoolRequest;
import java.net.InetSocketAddress;
-import java.util.concurrent.CompletableFuture;
public interface TarantoolConnection extends AutoCloseable {
/**
@@ -37,11 +36,9 @@ public interface TarantoolConnection extends AutoCloseable {
* Send a prepared request to the Tarantool server and flush the buffer
*
* @param request the request
- * @param resultMapper the mapper for response body
- * @param result type
- * @return result future
+ * @return request metadata containing the request result future
*/
- CompletableFuture sendRequest(TarantoolRequest request, MessagePackValueMapper resultMapper);
+ TarantoolRequestMetadata sendRequest(TarantoolRequest request);
/**
* Get the Netty channel baking this connection
diff --git a/src/main/java/io/tarantool/driver/core/AbstractTarantoolClient.java b/src/main/java/io/tarantool/driver/core/AbstractTarantoolClient.java
index 25b4440ba..1a7ec1a6d 100644
--- a/src/main/java/io/tarantool/driver/core/AbstractTarantoolClient.java
+++ b/src/main/java/io/tarantool/driver/core/AbstractTarantoolClient.java
@@ -4,8 +4,10 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -47,6 +49,7 @@
import io.tarantool.driver.mappers.factories.ResultMapperFactoryFactoryImpl;
import io.tarantool.driver.protocol.Packable;
import io.tarantool.driver.protocol.TarantoolProtocolException;
+import io.tarantool.driver.protocol.TarantoolRequestSignature;
import io.tarantool.driver.protocol.requests.TarantoolCallRequest;
import io.tarantool.driver.protocol.requests.TarantoolEvalRequest;
import io.tarantool.driver.utils.Assert;
@@ -68,6 +71,8 @@ public abstract class AbstractTarantoolClient metadataHolder = new AtomicReference<>();
private final ResultMapperFactoryFactoryImpl mapperFactoryFactory;
+ private final Map argumentsMapperCache;
+ private final Map resultMapperCache;
private final SpacesMetadataProvider metadataProvider;
private final ScheduledExecutorService timeoutScheduler;
@@ -113,6 +118,8 @@ public AbstractTarantoolClient(TarantoolClientConfig config, TarantoolConnection
this.config = config;
this.mapperFactoryFactory = new ResultMapperFactoryFactoryImpl();
+ this.argumentsMapperCache = new ConcurrentHashMap<>();
+ this.resultMapperCache = new ConcurrentHashMap<>();
this.eventLoopGroup = new NioEventLoopGroup(config.getEventLoopThreadsNumber());
this.bootstrap = new Bootstrap()
.group(eventLoopGroup)
@@ -224,7 +231,8 @@ public TarantoolMetadataProvider metadataProvider() {
@Override
public CompletableFuture> call(String functionName) throws TarantoolClientException {
- return call(functionName, Collections.emptyList());
+ return makeRequest(functionName, Collections.emptyList(), null,
+ config::getMessagePackMapper, config::getMessagePackMapper);
}
@Override
@@ -236,13 +244,8 @@ public CompletableFuture> call(String functionName, Object... arguments)
@Override
public CompletableFuture> call(String functionName, Collection> arguments)
throws TarantoolClientException {
- return call(functionName, arguments, config.getMessagePackMapper());
- }
-
- @Override
- public CompletableFuture> call(String functionName, Collection> arguments, MessagePackMapper mapper)
- throws TarantoolClientException {
- return makeRequest(functionName, arguments, mapper, mapper);
+ return makeRequest(functionName, arguments, null,
+ config::getMessagePackMapper, config::getMessagePackMapper);
}
@Override
@@ -254,46 +257,50 @@ public CompletableFuture> callForTupleResult(String funct
@Override
public CompletableFuture call(
String functionName,
- CallResultMapper> resultMapper)
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException {
- return call(functionName, Collections.emptyList(), resultMapper);
+ return call(functionName, Collections.emptyList(), resultMapperSupplier);
}
@Override
public CompletableFuture> callForTupleResult(
String functionName, Collection> arguments, Class tupleClass)
throws TarantoolClientException {
- return callForTupleResult(functionName, arguments, config.getMessagePackMapper(), tupleClass);
+ return callForTupleResult(functionName, arguments, config::getMessagePackMapper, tupleClass);
}
@Override
public CompletableFuture call(
String functionName,
Collection> arguments,
- CallResultMapper> resultMapper)
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException {
- return call(functionName, arguments, config.getMessagePackMapper(), resultMapper);
+ return call(functionName, arguments, config::getMessagePackMapper, resultMapperSupplier);
}
@Override
public CompletableFuture> callForTupleResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
Class tupleClass)
throws TarantoolClientException {
- return call(functionName, arguments, argumentsMapper,
- mapperFactoryFactory.getTarantoolResultMapper(config.getMessagePackMapper(), tupleClass));
+ Supplier, SingleValueCallResult>>>
+ resultMapperSupplier = () ->
+ mapperFactoryFactory.getTarantoolResultMapper(config.getMessagePackMapper(), tupleClass);
+ TarantoolRequestSignature signature = TarantoolRequestSignature.create(
+ functionName, arguments, tupleClass, argumentsMapperSupplier, resultMapperSupplier);
+ return callForSingleResult(functionName, arguments, signature, argumentsMapperSupplier, resultMapperSupplier);
}
@Override
public CompletableFuture call(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
- CallResultMapper> resultMapper)
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException {
- return callForSingleResult(functionName, arguments, argumentsMapper, resultMapper);
+ return callForSingleResult(functionName, arguments, argumentsMapperSupplier, resultMapperSupplier);
}
@Override
@@ -302,7 +309,7 @@ public CompletableFuture callForSingleResult(
Collection> arguments,
Class resultClass)
throws TarantoolClientException {
- return callForSingleResult(functionName, arguments, config.getMessagePackMapper(), resultClass);
+ return callForSingleResult(functionName, arguments, config::getMessagePackMapper, resultClass);
}
@Override
@@ -311,15 +318,15 @@ public CompletableFuture callForSingleResult(
Collection> arguments,
ValueConverter valueConverter)
throws TarantoolClientException {
- return callForSingleResult(functionName, arguments, config.getMessagePackMapper(), valueConverter);
+ return callForSingleResult(functionName, arguments, config::getMessagePackMapper, valueConverter);
}
@Override
public CompletableFuture callForSingleResult(
String functionName,
Collection> arguments,
- CallResultMapper> resultMapper) throws TarantoolClientException {
- return callForSingleResult(functionName, arguments, config.getMessagePackMapper(), resultMapper);
+ Supplier>> resultMapperSupplier) throws TarantoolClientException {
+ return callForSingleResult(functionName, arguments, config::getMessagePackMapper, resultMapperSupplier);
}
@Override
@@ -337,40 +344,59 @@ public CompletableFuture callForSingleResult(String functionName, ValueCo
@Override
public CompletableFuture callForSingleResult(
String functionName,
- CallResultMapper> resultMapper) throws TarantoolClientException {
- return callForSingleResult(functionName, Collections.emptyList(), resultMapper);
+ Supplier>> resultMapperSupplier) throws TarantoolClientException {
+ return callForSingleResult(functionName, Collections.emptyList(), resultMapperSupplier);
}
@Override
public CompletableFuture callForSingleResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
Class resultClass)
throws TarantoolClientException {
- return callForSingleResult(functionName, arguments, argumentsMapper,
- mapperFactoryFactory.getDefaultSingleValueMapper(config.getMessagePackMapper(), resultClass));
+ Supplier>> resultMapperSupplier = () ->
+ mapperFactoryFactory.getDefaultSingleValueMapper(config.getMessagePackMapper(), resultClass);
+ TarantoolRequestSignature signature = TarantoolRequestSignature.create(
+ functionName, arguments, resultClass, argumentsMapperSupplier, resultMapperSupplier);
+ return callForSingleResult(functionName, arguments, signature, argumentsMapperSupplier, resultMapperSupplier);
}
@Override
public CompletableFuture callForSingleResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
ValueConverter valueConverter)
throws TarantoolClientException {
- return callForSingleResult(functionName, arguments, argumentsMapper,
- mapperFactoryFactory.getSingleValueResultMapper(valueConverter));
+ Supplier>> resultMapperSupplier = () ->
+ mapperFactoryFactory.getSingleValueResultMapper(valueConverter);
+ TarantoolRequestSignature signature = TarantoolRequestSignature.create(
+ functionName, arguments, valueConverter.getClass(), argumentsMapperSupplier, resultMapperSupplier);
+ return callForSingleResult(functionName, arguments, signature, argumentsMapperSupplier, resultMapperSupplier);
+ }
+
+ private CompletableFuture callForSingleResult(
+ String functionName,
+ Collection> arguments,
+ TarantoolRequestSignature signature,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier>> resultMapperSupplier)
+ throws TarantoolClientException {
+ return makeRequestForSingleResult(
+ functionName, arguments, signature, argumentsMapperSupplier, resultMapperSupplier)
+ .thenApply(CallResult::value);
}
@Override
public CompletableFuture callForSingleResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
- CallResultMapper> resultMapper)
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException {
- return makeRequestForSingleResult(functionName, arguments, argumentsMapper, resultMapper)
+ return makeRequestForSingleResult(
+ functionName, arguments, null, argumentsMapperSupplier, resultMapperSupplier)
.thenApply(CallResult::value);
}
@@ -382,7 +408,7 @@ public > CompletableFuture callForMultiResult(
Class resultClass)
throws TarantoolClientException {
return callForMultiResult(
- functionName, arguments, config.getMessagePackMapper(), resultContainerSupplier, resultClass);
+ functionName, arguments, config::getMessagePackMapper, resultContainerSupplier, resultClass);
}
@Override
@@ -391,7 +417,7 @@ public > CompletableFuture callForMultiResult(
Collection> arguments,
Supplier resultContainerSupplier,
ValueConverter valueConverter) throws TarantoolClientException {
- return callForMultiResult(functionName, arguments, config.getMessagePackMapper(),
+ return callForMultiResult(functionName, arguments, config::getMessagePackMapper,
resultContainerSupplier, valueConverter);
}
@@ -399,8 +425,9 @@ public > CompletableFuture callForMultiResult(
public > CompletableFuture callForMultiResult(
String functionName,
Collection> arguments,
- CallResultMapper> resultMapper) throws TarantoolClientException {
- return callForMultiResult(functionName, arguments, config.getMessagePackMapper(), resultMapper);
+ Supplier>> resultMapperSupplier)
+ throws TarantoolClientException {
+ return callForMultiResult(functionName, arguments, config::getMessagePackMapper, resultMapperSupplier);
}
@Override
@@ -424,67 +451,88 @@ public > CompletableFuture callForMultiResult(
@Override
public > CompletableFuture callForMultiResult(
String functionName,
- CallResultMapper> resultMapper)
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException {
- return callForMultiResult(functionName, Collections.emptyList(), resultMapper);
+ return callForMultiResult(functionName, Collections.emptyList(), resultMapperSupplier);
}
@Override
public > CompletableFuture callForMultiResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
Supplier resultContainerSupplier,
Class resultClass)
throws TarantoolClientException {
- return callForMultiResult(functionName, arguments, argumentsMapper,
- mapperFactoryFactory.getDefaultMultiValueMapper(config.getMessagePackMapper(), resultClass));
+ Supplier>> resultMapperSupplier = () ->
+ mapperFactoryFactory.getDefaultMultiValueMapper(config.getMessagePackMapper(), resultClass);
+ TarantoolRequestSignature signature = TarantoolRequestSignature.create(
+ functionName, arguments, resultClass, argumentsMapperSupplier, resultMapperSupplier);
+ return callForMultiResult(functionName, arguments, signature, argumentsMapperSupplier, resultMapperSupplier);
}
@Override
public > CompletableFuture callForMultiResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
Supplier resultContainerSupplier,
ValueConverter valueConverter)
throws TarantoolClientException {
- return callForMultiResult(functionName, arguments, argumentsMapper,
- mapperFactoryFactory.getMultiValueResultMapper(resultContainerSupplier, valueConverter));
+ Supplier>> resultMapperSupplier = () ->
+ mapperFactoryFactory.getMultiValueResultMapper(resultContainerSupplier, valueConverter);
+ TarantoolRequestSignature signature = TarantoolRequestSignature.create(
+ functionName, arguments, valueConverter.getClass(), argumentsMapperSupplier, resultMapperSupplier);
+ return callForMultiResult(functionName, arguments, signature, argumentsMapperSupplier, resultMapperSupplier);
+ }
+
+ private > CompletableFuture callForMultiResult(
+ String functionName,
+ Collection> arguments,
+ TarantoolRequestSignature signature,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier>> resultMapperSupplier)
+ throws TarantoolClientException {
+ return makeRequestForMultiResult(
+ functionName, arguments, signature, argumentsMapperSupplier, resultMapperSupplier)
+ .thenApply(CallResult::value);
}
@Override
public > CompletableFuture callForMultiResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
- CallResultMapper> resultMapper)
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier>> resultMapperSupplier)
throws TarantoolClientException {
- return makeRequestForMultiResult(functionName, arguments, argumentsMapper, resultMapper)
+ return makeRequestForMultiResult(functionName, arguments, null, argumentsMapperSupplier, resultMapperSupplier)
.thenApply(CallResult::value);
}
private CompletableFuture> makeRequestForSingleResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
- CallResultMapper> resultMapper) {
- return makeRequest(functionName, arguments, argumentsMapper, resultMapper);
+ TarantoolRequestSignature requestSignature,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier>> resultMapperSupplier) {
+ return makeRequest(functionName, arguments, requestSignature, argumentsMapperSupplier, resultMapperSupplier);
}
private > CompletableFuture> makeRequestForMultiResult(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
- CallResultMapper> resultMapper) {
- return makeRequest(functionName, arguments, argumentsMapper, resultMapper);
+ TarantoolRequestSignature requestSignature,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier>> resultMapperSupplier) {
+ return makeRequest(functionName, arguments, requestSignature, argumentsMapperSupplier, resultMapperSupplier);
}
private CompletableFuture makeRequest(
String functionName,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
- MessagePackValueMapper resultMapper)
+ TarantoolRequestSignature requestSignature,
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier extends MessagePackValueMapper> resultMapperSupplier)
throws TarantoolClientException {
try {
TarantoolCallRequest.Builder builder = new TarantoolCallRequest.Builder()
@@ -493,9 +541,18 @@ private CompletableFuture makeRequest(
if (arguments.size() > 0) {
builder.withArguments(arguments);
}
+ builder.withSignature(requestSignature);
+ MessagePackObjectMapper argumentsMapper = requestSignature != null ?
+ argumentsMapperCache.computeIfAbsent(requestSignature, s -> argumentsMapperSupplier.get()) :
+ argumentsMapperSupplier.get();
+ MessagePackValueMapper resultMapper = requestSignature != null ?
+ resultMapperCache.computeIfAbsent(requestSignature, s -> resultMapperSupplier.get()) :
+ resultMapperSupplier.get();
TarantoolCallRequest request = builder.build(argumentsMapper);
- return connectionManager().getConnection().thenCompose(c -> c.sendRequest(request, resultMapper));
+ return connectionManager().getConnection()
+ .thenCompose(c -> c.sendRequest(request).getFuture())
+ .thenApply(resultMapper::fromValue);
} catch (TarantoolProtocolException e) {
throw new TarantoolClientException(e);
}
@@ -509,34 +566,44 @@ public CompletableFuture> eval(String expression) throws TarantoolClient
@Override
public CompletableFuture> eval(String expression, Collection> arguments)
throws TarantoolClientException {
- return eval(expression, arguments, config.getMessagePackMapper());
+ return eval(expression, arguments, config::getMessagePackMapper);
}
@Override
- public CompletableFuture> eval(String expression, MessagePackValueMapper resultMapper)
+ public CompletableFuture> eval(
+ String expression, Supplier extends MessagePackValueMapper> resultMapperSupplier)
throws TarantoolClientException {
- return eval(expression, Collections.emptyList(), resultMapper);
+ return eval(expression, Collections.emptyList(), resultMapperSupplier);
}
@Override
public CompletableFuture> eval(
- String expression, Collection> arguments, MessagePackValueMapper resultMapper)
+ String expression, Collection> arguments, Supplier extends MessagePackValueMapper> resultMapperSupplier)
throws TarantoolClientException {
- return eval(expression, arguments, config.getMessagePackMapper(), resultMapper);
+ return eval(expression, arguments, config::getMessagePackMapper, resultMapperSupplier);
}
@Override
public CompletableFuture> eval(
String expression,
Collection> arguments,
- MessagePackObjectMapper argumentsMapper,
- MessagePackValueMapper resultMapper) throws TarantoolClientException {
+ Supplier extends MessagePackObjectMapper> argumentsMapperSupplier,
+ Supplier extends MessagePackValueMapper> resultMapperSupplier) throws TarantoolClientException {
try {
+ TarantoolRequestSignature signature = TarantoolRequestSignature.create(
+ expression, arguments, List.class, argumentsMapperSupplier, resultMapperSupplier);
+ MessagePackObjectMapper argumentsMapper = argumentsMapperCache.computeIfAbsent(
+ signature, s -> argumentsMapperSupplier.get());
+ MessagePackValueMapper resultMapper = resultMapperCache.computeIfAbsent(
+ signature, s -> resultMapperSupplier.get());
TarantoolEvalRequest request = new TarantoolEvalRequest.Builder()
.withExpression(expression)
.withArguments(arguments)
+ .withSignature(signature)
.build(argumentsMapper);
- return connectionManager().getConnection().thenCompose(c -> c.sendRequest(request, resultMapper));
+ return connectionManager().getConnection()
+ .thenCompose(c -> c.sendRequest(request).getFuture())
+ .thenApply(resultMapper::fromValue);
} catch (TarantoolProtocolException e) {
throw new TarantoolClientException(e);
}
diff --git a/src/main/java/io/tarantool/driver/core/ProxyTarantoolClient.java b/src/main/java/io/tarantool/driver/core/ProxyTarantoolClient.java
index e16269f4d..51a898cf7 100644
--- a/src/main/java/io/tarantool/driver/core/ProxyTarantoolClient.java
+++ b/src/main/java/io/tarantool/driver/core/ProxyTarantoolClient.java
@@ -20,7 +20,6 @@
import io.tarantool.driver.exceptions.TarantoolClientException;
import io.tarantool.driver.exceptions.TarantoolSpaceNotFoundException;
import io.tarantool.driver.mappers.CallResultMapper;
-import io.tarantool.driver.mappers.MessagePackMapper;
import io.tarantool.driver.mappers.MessagePackObjectMapper;
import io.tarantool.driver.mappers.MessagePackValueMapper;
import io.tarantool.driver.mappers.converters.ValueConverter;
@@ -182,12 +181,6 @@ public CompletableFuture> call(String functionName, Collection> argume
return client.call(functionName, arguments);
}
- @Override
- public CompletableFuture> call(String functionName, Collection> arguments, MessagePackMapper mapper)
- throws TarantoolClientException {
- return client.call(functionName, arguments, mapper);
- }
-
@Override
public CompletableFuture> callForTupleResult(String functionName, Class entityClass)
throws TarantoolClientException {
@@ -196,8 +189,8 @@ public CompletableFuture> callForTupleResult(String funct
@Override
public CompletableFuture call(String functionName,
- CallResultMapper> resultMapper) throws TarantoolClientException {
- return client.call(functionName, resultMapper);
+ Supplier>> resultMapperSupplier) throws TarantoolClientException {
+ return client.call(functionName, resultMapperSupplier);
}
@Override
@@ -208,51 +201,57 @@ public CompletableFuture> callForTupleResult(String funct
@Override
public CompletableFuture call(String functionName, Collection> arguments,
- CallResultMapper> resultMapper) throws TarantoolClientException {
- return client.call(functionName, arguments, resultMapper);
+ Supplier>> resultMapperSupplier) throws TarantoolClientException {
+ return client.call(functionName, arguments, resultMapperSupplier);
}
@Override
- public CompletableFuture> callForTupleResult(String functionName, Collection> arguments,
- MessagePackObjectMapper argumentsMapper, Class entityClass) throws TarantoolClientException {
- return client.callForTupleResult(functionName, arguments, argumentsMapper, entityClass);
+ public CompletableFuture