use of org.redisson.misc.CompletableFutureWrapper in project redisson by redisson.
the class RedisClientEntry method pingAsync.
@Override
public RFuture<Boolean> pingAsync(long timeout, TimeUnit timeUnit) {
RFuture<Boolean> f = commandExecutor.readAsync(client, null, RedisCommands.PING_BOOL);
CompletableFuture<Boolean> s = f.toCompletableFuture().handle((res, e) -> {
if (e != null) {
return false;
}
return res;
});
commandExecutor.getConnectionManager().newTimeout(t -> {
RedisTimeoutException ex = new RedisTimeoutException("Command execution timeout for command: PING, Redis client: " + client);
s.completeExceptionally(ex);
}, timeout, timeUnit);
return new CompletableFutureWrapper<>(s);
}
use of org.redisson.misc.CompletableFutureWrapper in project redisson by redisson.
the class RedisNode method pingAsync.
@Override
public RFuture<Boolean> pingAsync(long timeout, TimeUnit timeUnit) {
RFuture<Boolean> f = commandExecutor.readAsync(client, null, RedisCommands.PING_BOOL);
CompletionStage<Boolean> s = f.exceptionally(e -> false);
commandExecutor.getConnectionManager().newTimeout(t -> {
RedisTimeoutException ex = new RedisTimeoutException("Command execution timeout (" + timeUnit.toMillis(timeout) + "ms) for command: PING, Redis client: " + client);
s.toCompletableFuture().completeExceptionally(ex);
}, timeout, timeUnit);
return new CompletableFutureWrapper<>(s);
}
use of org.redisson.misc.CompletableFutureWrapper in project redisson by redisson.
the class RedissonCountDownLatch method awaitAsync.
@Override
public RFuture<Boolean> awaitAsync(long waitTime, TimeUnit unit) {
CompletableFuture<Boolean> result = new CompletableFuture<>();
AtomicLong time = new AtomicLong(unit.toMillis(waitTime));
long currentTime = System.currentTimeMillis();
CompletableFuture<Long> countFuture = getCountAsync().toCompletableFuture();
CompletableFuture<Boolean> f = countFuture.thenCompose(r -> {
long el = System.currentTimeMillis() - currentTime;
time.addAndGet(-el);
if (time.get() <= 0) {
return CompletableFuture.completedFuture(false);
}
long current = System.currentTimeMillis();
CompletableFuture<RedissonCountDownLatchEntry> subscribeFuture = subscribe();
return subscribeFuture.thenCompose(entry -> {
long elapsed = System.currentTimeMillis() - current;
time.addAndGet(-elapsed);
return await(time, entry);
});
});
return new CompletableFutureWrapper<>(f);
}
use of org.redisson.misc.CompletableFutureWrapper in project redisson by redisson.
the class RedissonBaseAdder method resetAsync.
public RFuture<Void> resetAsync() {
String id = generateId();
RFuture<Long> future = topic.publishAsync(CLEAR_MSG + ":" + id);
RSemaphore semaphore = getSemaphore(id);
CompletionStage<Void> f = future.thenCompose(r -> semaphore.acquireAsync(r.intValue())).thenCompose(r -> semaphore.deleteAsync().thenApply(res -> null));
return new CompletableFutureWrapper<>(f);
}
use of org.redisson.misc.CompletableFutureWrapper in project redisson by redisson.
the class RedissonBaseAdder method resetAsync.
public RFuture<Void> resetAsync(long timeout, TimeUnit timeUnit) {
String id = generateId();
RFuture<Long> future = topic.publishAsync(CLEAR_MSG + ":" + id);
RSemaphore semaphore = getSemaphore(id);
CompletionStage<Void> f = future.thenCompose(r -> tryAcquire(semaphore, timeout, timeUnit, r.intValue())).thenCompose(r -> semaphore.deleteAsync().thenApply(res -> null));
return new CompletableFutureWrapper<>(f);
}
Aggregations