Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.tarantool.client.factory;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -78,7 +79,7 @@ public CompletableFuture<IProtoResponse> iprotoCall(
TarantoolJacksonMapping.toValue(withSpaceName(args)),
null,
IProtoRequestOpts.empty()
.withRequestTimeout(options.getTimeout())
.withRequestTimeout(Duration.ofMillis(options.getTimeout()))
.withStreamId(options.getStreamId())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.tarantool.client.factory;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -441,7 +442,7 @@ private CompletableFuture<IProtoResponse> iprotoUpsert(
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
.withRequestTimeout(options.getTimeout())
.withRequestTimeout(Duration.ofMillis(options.getTimeout()))
.withStreamId(options.getStreamId());

int indexId;
Expand Down Expand Up @@ -496,7 +497,7 @@ private CompletableFuture<IProtoResponse> iprotoUpdate(
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
.withRequestTimeout(options.getTimeout())
.withRequestTimeout(Duration.ofMillis(options.getTimeout()))
.withStreamId(options.getStreamId());

Integer indexId;
Expand Down Expand Up @@ -548,7 +549,7 @@ private CompletableFuture<IProtoResponse> iprotoDelete(List<?> key, DeleteOption
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
.withRequestTimeout(options.getTimeout())
.withRequestTimeout(Duration.ofMillis(options.getTimeout()))
.withStreamId(options.getStreamId());

Integer indexId;
Expand Down Expand Up @@ -613,7 +614,7 @@ private CompletableFuture<IProtoResponse> iprotoSelect(List<?> key, SelectOption
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
.withRequestTimeout(options.getTimeout())
.withRequestTimeout(Duration.ofMillis(options.getTimeout()))
.withStreamId(options.getStreamId());

Integer indexId;
Expand Down Expand Up @@ -673,7 +674,7 @@ private CompletableFuture<IProtoResponse> iprotoReplace(Object tuple, Options op
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
.withRequestTimeout(options.getTimeout())
.withRequestTimeout(Duration.ofMillis(options.getTimeout()))
.withStreamId(options.getStreamId());

if (fetcher == null) {
Expand Down Expand Up @@ -715,7 +716,7 @@ private CompletableFuture<IProtoResponse> iprotoInsert(Object tuple, Options opt
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
.withRequestTimeout(options.getTimeout())
.withRequestTimeout(Duration.ofMillis(options.getTimeout()))
.withStreamId(options.getStreamId());

if (fetcher == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -168,7 +169,7 @@ protected TarantoolClientImpl(
*/
private IProtoRequestOpts convertOptions(Options opts) {
return IProtoRequestOpts.empty()
.withRequestTimeout(opts.getTimeout())
.withRequestTimeout(Duration.ofMillis(opts.getTimeout()))
.withStreamId(opts.getStreamId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.tarantool.client.benchmark;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -189,15 +190,16 @@ public static Boolean beginReplaceCommit(
() -> {
long streamId = iprotoClient.allocateStreamId();
return iprotoClient
.begin(streamId, 2_000, TransactionIsolationLevel.DEFAULT)
.begin(streamId, Duration.ofSeconds(2), TransactionIsolationLevel.DEFAULT)
.thenCompose(
r ->
client
.space("tmp")
.replace(
Arrays.asList(counter.getAndIncrement(), "artyom"),
BaseOptions.builder().withStreamId(streamId).build()))
.thenCompose(r -> iprotoClient.commit(streamId));
.thenCompose(r -> iprotoClient.commit(streamId))
.toCompletableFuture();
});
}

Expand All @@ -221,7 +223,7 @@ public static Boolean beginThreeReplaceCommit(
() -> {
long streamId = iprotoClient.allocateStreamId();
return iprotoClient
.begin(streamId, 2_000, TransactionIsolationLevel.DEFAULT)
.begin(streamId, Duration.ofSeconds(2), TransactionIsolationLevel.DEFAULT)
.thenCompose(
r ->
client
Expand All @@ -243,7 +245,8 @@ public static Boolean beginThreeReplaceCommit(
.replace(
Arrays.asList(counter.getAndIncrement(), "artyom"),
BaseOptions.builder().withStreamId(streamId).build()))
.thenCompose(r -> iprotoClient.commit(streamId));
.thenCompose(r -> iprotoClient.commit(streamId))
.toCompletableFuture();
});
}

Expand Down
39 changes: 37 additions & 2 deletions tarantool-core/src/main/java/io/tarantool/core/IProtoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
package io.tarantool.core;

import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

Expand All @@ -25,11 +27,24 @@

public interface IProtoClient {

/**
* @deprecated Use {@link #connect(InetSocketAddress, Duration)}
*/
@Deprecated
CompletableFuture<Void> connect(InetSocketAddress address, long timeoutMs);

CompletionStage<Void> connect(InetSocketAddress address, Duration timeout);

/**
* @deprecated Use {@link #connect(InetSocketAddress, Duration, boolean)}
*/
@Deprecated
CompletableFuture<Void> connect(
InetSocketAddress address, long timeoutMs, boolean gracefulShutdown);

CompletionStage<Void> connect(
InetSocketAddress address, Duration timeout, boolean gracefulShutdown);

CompletableFuture<IProtoResponse> authorize(String user, String password);

CompletableFuture<IProtoResponse> authorize(String user, String password, IProtoRequestOpts opts);
Expand Down Expand Up @@ -201,11 +216,25 @@ CompletableFuture<IProtoResponse> execute(

long allocateStreamId();

/**
* @deprecated Use {@link #begin(Long, Duration, TransactionIsolationLevel)}
*/
@Deprecated
CompletableFuture<IProtoResponse> begin(
Long streamId, long timeout, TransactionIsolationLevel level);
Long streamId, long timeoutMs, TransactionIsolationLevel level);

CompletionStage<IProtoResponse> begin(
Long streamId, Duration timeout, TransactionIsolationLevel level);

/**
* @deprecated Use {@link #begin(Long, Duration, TransactionIsolationLevel, IProtoRequestOpts)}
*/
@Deprecated
CompletableFuture<IProtoResponse> begin(
Long streamId, long timeout, TransactionIsolationLevel level, IProtoRequestOpts opts);
Long streamId, long timeoutMs, TransactionIsolationLevel level, IProtoRequestOpts opts);

CompletionStage<IProtoResponse> begin(
Long streamId, Duration timeout, TransactionIsolationLevel level, IProtoRequestOpts opts);

CompletableFuture<IProtoResponse> commit(Long streamId);

Expand Down Expand Up @@ -264,7 +293,13 @@ CompletableFuture<IProtoResponse> id(

void resume();

/**
* @deprecated Use {@link #setIdleTimeout(Duration)}
*/
@Deprecated
void setIdleTimeout(int idleTimeout);

void setIdleTimeout(Duration timeout);

boolean isPaused();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.tarantool.core;

import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -15,6 +16,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -78,7 +80,7 @@

public static final IProtoAuth.AuthType DEFAULT_AUTH_TYPE = IProtoAuth.AuthType.CHAP_SHA1;
public static final IProtoRequestOpts DEFAULT_REQUEST_OPTS =
IProtoRequestOpts.empty().withRequestTimeout(5000);
IProtoRequestOpts.empty().withRequestTimeout(Duration.ofSeconds(5));
public static final WatcherOptions DEFAULT_WATCHER_OPTS = WatcherOptions.builder().build();
private static final Set<IProtoFeature> FEATURES_SET_ENUM = EnumSet.allOf(IProtoFeature.class);
private static final List<Integer> FEATURES_LIST_INT =
Expand All @@ -89,7 +91,7 @@
private static final String CALL_CONNECT_BEFORE_GETTING_SERVER_DETAILS =
"Call connect before getting server details";
private static final String SHUTDOWN_EVENT_KEY = "box.shutdown";
private static final int DEFAULT_IDLE_TIMEOUT = 1_000;
private static final Duration DEFAULT_IDLE_TIMEOUT = Duration.ofSeconds(1);
private static final Logger log = LoggerFactory.getLogger(IProtoClientImpl.class);
private final AtomicLong streamIdSequence;
private final AtomicLong syncIdSequence;
Expand Down Expand Up @@ -178,13 +180,26 @@
}

@Override
@Deprecated
public CompletableFuture<Void> connect(InetSocketAddress address, long timeoutMs) {
return connect(address, timeoutMs, true);
return connect(address, Duration.ofMillis(timeoutMs), true).toCompletableFuture();
}

@Override
public CompletionStage<Void> connect(InetSocketAddress address, Duration timeout) {
return connect(address, timeout, true);
}

@Override
@Deprecated
public CompletableFuture<Void> connect(
InetSocketAddress address, long timeoutMs, boolean gracefulShutdown) {
return connect(address, Duration.ofMillis(timeoutMs), gracefulShutdown).toCompletableFuture();
}

@Override
public CompletionStage<Void> connect(
InetSocketAddress address, Duration timeout, boolean gracefulShutdown) {
if (gracefulShutdown) {
watch(SHUTDOWN_EVENT_KEY, this::shutdownEventCallback);
}
Expand All @@ -193,7 +208,7 @@
serverProtocolVersion = new CompletableFuture<>();
serverFeatures = new CompletableFuture<>();
return connection
.connect(address, timeoutMs)
.connect(address, timeout)
.thenRun(
() -> {
updateWatchers();
Expand Down Expand Up @@ -542,15 +557,36 @@
return streamIdSequence.updateAndGet(n -> n == Long.MAX_VALUE ? 1 : n + 1);
}

@Deprecated
@Override
public CompletableFuture<IProtoResponse> begin(
Long streamId, long streamTimeout, TransactionIsolationLevel level) {
return begin(streamId, streamTimeout, level, DEFAULT_REQUEST_OPTS);
Long streamId, long streamTimeoutMs, TransactionIsolationLevel level) {
return begin(streamId, Duration.ofMillis(streamTimeoutMs), level, DEFAULT_REQUEST_OPTS)
.toCompletableFuture();
}

@Override
public CompletionStage<IProtoResponse> begin(
Long streamId, Duration timeout, TransactionIsolationLevel level) {
return begin(streamId, timeout, level, DEFAULT_REQUEST_OPTS);
}

@Deprecated
@Override
public CompletableFuture<IProtoResponse> begin(
Long streamId, long streamTimeout, TransactionIsolationLevel level, IProtoRequestOpts opts) {
Long streamId,
long streamTimeoutMs,
TransactionIsolationLevel level,
IProtoRequestOpts opts) {
return begin(streamId, Duration.ofMillis(streamTimeoutMs), level, opts).toCompletableFuture();
}

@Override
public CompletionStage<IProtoResponse> begin(
Long streamId,
Duration streamTimeout,
TransactionIsolationLevel level,
IProtoRequestOpts opts) {
return runRequest(new IProtoBegin(streamId, streamTimeout, level), opts);
}

Expand Down Expand Up @@ -793,12 +829,18 @@
}

@Override
public void setIdleTimeout(int idleTimeout) {

Check warning on line 832 in tarantool-core/src/main/java/io/tarantool/core/IProtoClientImpl.java

View workflow job for this annotation

GitHub Actions / tests-unit

[deprecation] setIdleTimeout(int) in IProtoClient has been deprecated

Check warning on line 832 in tarantool-core/src/main/java/io/tarantool/core/IProtoClientImpl.java

View workflow job for this annotation

GitHub Actions / tests-box-integration (3.5.0)

[deprecation] setIdleTimeout(int) in IProtoClient has been deprecated

Check warning on line 832 in tarantool-core/src/main/java/io/tarantool/core/IProtoClientImpl.java

View workflow job for this annotation

GitHub Actions / tests-box-integration (2.11.8-ubuntu20.04)

[deprecation] setIdleTimeout(int) in IProtoClient has been deprecated

Check warning on line 832 in tarantool-core/src/main/java/io/tarantool/core/IProtoClientImpl.java

View workflow job for this annotation

GitHub Actions / tests-crud-integration (3.5.0)

[deprecation] setIdleTimeout(int) in IProtoClient has been deprecated

Check warning on line 832 in tarantool-core/src/main/java/io/tarantool/core/IProtoClientImpl.java

View workflow job for this annotation

GitHub Actions / tests-crud-integration (2.11.8-ubuntu20.04)

[deprecation] setIdleTimeout(int) in IProtoClient has been deprecated
if (idleTimeout <= 0) {
setIdleTimeout(Duration.ofMillis(idleTimeout));
}

@Override
public void setIdleTimeout(Duration timeout) {
if (timeout.isNegative() || timeout.isZero()) {
log.warn("idleTimeout must be greater than 0");
this.connection.setIdleTimeout(DEFAULT_IDLE_TIMEOUT);
return;
}
this.connection.setIdleTimeout(idleTimeout);
this.connection.setIdleTimeout(timeout);
}

@Override
Expand Down
Loading
Loading