netty Future interface methods moved to RFuture interface

pull/605/head
Nikita 9 years ago
parent 3d26419614
commit d00a1a7ae8

@ -33,6 +33,7 @@ import org.redisson.client.codec.LongCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandExecutor;
import org.redisson.executor.RemotePromise;
import org.redisson.misc.RPromise;
import org.redisson.remote.RRemoteServiceResponse;
import org.redisson.remote.RemoteServiceAck;
import org.redisson.remote.RemoteServiceAckTimeoutException;
@ -47,7 +48,6 @@ import org.slf4j.LoggerFactory;
import io.netty.buffer.ByteBufUtil;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
import io.netty.util.internal.ThreadLocalRandom;
/**
@ -200,7 +200,7 @@ public abstract class BaseRemoteService {
}
if (optionsCopy.isAckExpected()) {
Future<Boolean> future = commandExecutor.evalWriteAsync(responseName, LongCodec.INSTANCE,
RFuture<Boolean> future = commandExecutor.evalWriteAsync(responseName, LongCodec.INSTANCE,
RedisCommands.EVAL_BOOLEAN,
"if redis.call('setnx', KEYS[1], 1) == 1 then "
+ "redis.call('pexpire', KEYS[1], ARGV[2]);"
@ -250,7 +250,7 @@ public abstract class BaseRemoteService {
result.setRequestId(requestId);
Future<Boolean> addFuture = addAsync(requestQueue, request, result);
RFuture<Boolean> addFuture = addAsync(requestQueue, request, result);
addFuture.addListener(new FutureListener<Boolean>() {
@Override
@ -262,7 +262,7 @@ public abstract class BaseRemoteService {
if (optionsCopy.isAckExpected()) {
final RBlockingQueue<RemoteServiceAck> responseQueue = redisson.getBlockingQueue(responseName, getCodec());
Future<RemoteServiceAck> ackFuture = responseQueue.pollAsync(optionsCopy.getAckTimeoutInMillis(), TimeUnit.MILLISECONDS);
RFuture<RemoteServiceAck> ackFuture = responseQueue.pollAsync(optionsCopy.getAckTimeoutInMillis(), TimeUnit.MILLISECONDS);
ackFuture.addListener(new FutureListener<RemoteServiceAck>() {
@Override
public void operationComplete(Future<RemoteServiceAck> future) throws Exception {
@ -273,7 +273,7 @@ public abstract class BaseRemoteService {
RemoteServiceAck ack = future.getNow();
if (ack == null) {
Future<RemoteServiceAck> ackFutureAttempt =
RFuture<RemoteServiceAck> ackFutureAttempt =
tryPollAckAgainAsync(optionsCopy, responseQueue, ackName);
ackFutureAttempt.addListener(new FutureListener<RemoteServiceAck>() {
@ -318,7 +318,7 @@ public abstract class BaseRemoteService {
private void awaitResultAsync(final RemoteInvocationOptions optionsCopy, final RemotePromise<Object> result,
final RemoteServiceRequest request, final String responseName, final String ackName) {
Future<Boolean> deleteFuture = redisson.getBucket(ackName).deleteAsync();
RFuture<Boolean> deleteFuture = redisson.getBucket(ackName).deleteAsync();
deleteFuture.addListener(new FutureListener<Boolean>() {
@Override
public void operationComplete(Future<Boolean> future) throws Exception {
@ -340,7 +340,7 @@ public abstract class BaseRemoteService {
}
RBlockingQueue<RRemoteServiceResponse> responseQueue = redisson.getBlockingQueue(responseName, getCodec());
Future<RRemoteServiceResponse> responseFuture = responseQueue
RFuture<RRemoteServiceResponse> responseFuture = responseQueue
.pollAsync(optionsCopy.getExecutionTimeoutInMillis(), TimeUnit.MILLISECONDS);
responseFuture.addListener(new FutureListener<RRemoteServiceResponse>() {
@ -448,7 +448,7 @@ public abstract class BaseRemoteService {
private RemoteServiceAck tryPollAckAgain(RemoteInvocationOptions optionsCopy,
RBlockingQueue<? extends RRemoteServiceResponse> responseQueue, String ackName)
throws InterruptedException {
Future<Boolean> ackClientsFuture = commandExecutor.evalWriteAsync(ackName, LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
RFuture<Boolean> ackClientsFuture = commandExecutor.evalWriteAsync(ackName, LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
"if redis.call('setnx', KEYS[1], 1) == 1 then "
+ "redis.call('pexpire', KEYS[1], ARGV[1]);"
+ "return 0;"
@ -464,11 +464,11 @@ public abstract class BaseRemoteService {
return null;
}
private Future<RemoteServiceAck> tryPollAckAgainAsync(RemoteInvocationOptions optionsCopy,
private RFuture<RemoteServiceAck> tryPollAckAgainAsync(RemoteInvocationOptions optionsCopy,
final RBlockingQueue<RemoteServiceAck> responseQueue, String ackName)
throws InterruptedException {
final Promise<RemoteServiceAck> promise = commandExecutor.getConnectionManager().newPromise();
Future<Boolean> ackClientsFuture = commandExecutor.evalWriteAsync(ackName, LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
final RPromise<RemoteServiceAck> promise = commandExecutor.getConnectionManager().newPromise();
RFuture<Boolean> ackClientsFuture = commandExecutor.evalWriteAsync(ackName, LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
"if redis.call('setnx', KEYS[1], 1) == 1 then "
+ "redis.call('pexpire', KEYS[1], ARGV[1]);"
+ "return 0;"
@ -485,7 +485,7 @@ public abstract class BaseRemoteService {
}
if (future.getNow()) {
Future<RemoteServiceAck> pollFuture = responseQueue.pollAsync();
RFuture<RemoteServiceAck> pollFuture = responseQueue.pollAsync();
pollFuture.addListener(new FutureListener<RemoteServiceAck>() {
@Override
public void operationComplete(Future<RemoteServiceAck> future) throws Exception {
@ -512,9 +512,9 @@ public abstract class BaseRemoteService {
return ByteBufUtil.hexDump(id);
}
protected Future<Boolean> addAsync(RBlockingQueue<RemoteServiceRequest> requestQueue, RemoteServiceRequest request,
protected RFuture<Boolean> addAsync(RBlockingQueue<RemoteServiceRequest> requestQueue, RemoteServiceRequest request,
RemotePromise<Object> result) {
Future<Boolean> future = requestQueue.addAsync(request);
RFuture<Boolean> future = requestQueue.addAsync(request);
result.setAddFuture(future);
return future;
}

@ -21,6 +21,7 @@ import java.util.LinkedList;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import org.redisson.api.RFuture;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor;
@ -70,7 +71,7 @@ public class EvictionScheduler {
@Override
public void run() {
Future<Integer> future = cleanupExpiredEntires(name, timeoutSetName, maxIdleSetName, keysLimit, multimap);
RFuture<Integer> future = cleanupExpiredEntires(name, timeoutSetName, maxIdleSetName, keysLimit, multimap);
future.addListener(new FutureListener<Integer>() {
@Override
@ -169,7 +170,7 @@ public class EvictionScheduler {
return;
}
Future<Integer> future = cleanupExpiredEntires(name, timeoutSetName, null, valuesAmountToClean, false);
RFuture<Integer> future = cleanupExpiredEntires(name, timeoutSetName, null, valuesAmountToClean, false);
future.addListener(new FutureListener<Integer>() {
@Override
@ -189,7 +190,7 @@ public class EvictionScheduler {
});
}
private Future<Integer> cleanupExpiredEntires(String name, String timeoutSetName, String maxIdleSetName, int keysLimit, boolean multimap) {
private RFuture<Integer> cleanupExpiredEntires(String name, String timeoutSetName, String maxIdleSetName, int keysLimit, boolean multimap) {
if (multimap) {
return executor.evalWriteAsync(name, LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER,
"local expiredKeys = redis.call('zrangebyscore', KEYS[2], 0, ARGV[1], 'limit', 0, ARGV[2]); "

@ -15,7 +15,7 @@
*/
package org.redisson;
import io.netty.util.concurrent.Promise;
import org.redisson.misc.RPromise;
public interface PubSubEntry<E> {
@ -23,6 +23,6 @@ public interface PubSubEntry<E> {
int release();
Promise<E> getPromise();
RPromise<E> getPromise();
}

@ -26,15 +26,16 @@ import java.util.concurrent.CountDownLatch;
import org.redisson.api.Node;
import org.redisson.api.NodeType;
import org.redisson.api.NodesGroup;
import org.redisson.api.RFuture;
import org.redisson.client.RedisConnection;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.connection.ConnectionListener;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.RedisClientEntry;
import org.redisson.misc.RPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
public class RedisNodes<N extends Node> implements NodesGroup<N> {
@ -65,21 +66,21 @@ public class RedisNodes<N extends Node> implements NodesGroup<N> {
@Override
public boolean pingAll() {
List<RedisClientEntry> clients = new ArrayList<RedisClientEntry>(connectionManager.getClients());
final Map<RedisConnection, Future<String>> result = new ConcurrentHashMap<RedisConnection, Future<String>>(clients.size());
final Map<RedisConnection, RFuture<String>> result = new ConcurrentHashMap<RedisConnection, RFuture<String>>(clients.size());
final CountDownLatch latch = new CountDownLatch(clients.size());
for (RedisClientEntry entry : clients) {
Future<RedisConnection> f = entry.getClient().connectAsync();
RFuture<RedisConnection> f = entry.getClient().connectAsync();
f.addListener(new FutureListener<RedisConnection>() {
@Override
public void operationComplete(Future<RedisConnection> future) throws Exception {
if (future.isSuccess()) {
final RedisConnection c = future.getNow();
Promise<RedisConnection> connectionFuture = connectionManager.newPromise();
RPromise<RedisConnection> connectionFuture = connectionManager.newPromise();
connectionManager.getConnectListener().onConnect(connectionFuture, c, null, connectionManager.getConfig());
connectionFuture.addListener(new FutureListener<RedisConnection>() {
@Override
public void operationComplete(Future<RedisConnection> future) throws Exception {
Future<String> r = c.async(connectionManager.getConfig().getPingTimeout(), RedisCommands.PING);
RFuture<String> r = c.async(connectionManager.getConfig().getPingTimeout(), RedisCommands.PING);
result.put(c, r);
latch.countDown();
}
@ -99,7 +100,7 @@ public class RedisNodes<N extends Node> implements NodesGroup<N> {
}
if (System.currentTimeMillis() - time >= connectionManager.getConfig().getConnectTimeout()) {
for (Entry<RedisConnection, Future<String>> entry : result.entrySet()) {
for (Entry<RedisConnection, RFuture<String>> entry : result.entrySet()) {
entry.getKey().closeAsync();
}
return false;
@ -107,8 +108,8 @@ public class RedisNodes<N extends Node> implements NodesGroup<N> {
time = System.currentTimeMillis();
boolean res = true;
for (Entry<RedisConnection, Future<String>> entry : result.entrySet()) {
Future<String> f = entry.getValue();
for (Entry<RedisConnection, RFuture<String>> entry : result.entrySet()) {
RFuture<String> f = entry.getValue();
f.awaitUninterruptibly();
if (!"PONG".equals(f.getNow())) {
res = false;

@ -45,8 +45,6 @@ import org.redisson.client.codec.Codec;
import org.redisson.command.CommandBatchService;
import org.redisson.connection.ConnectionManager;
import io.netty.util.concurrent.Future;
/**
*
*

@ -93,7 +93,7 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
*/
@Override
public V take() throws InterruptedException {
Future<V> res = takeAsync();
RFuture<V> res = takeAsync();
return res.await().getNow();
}
@ -108,7 +108,7 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
*/
@Override
public V poll(long timeout, TimeUnit unit) throws InterruptedException {
Future<V> res = pollAsync(timeout, unit);
RFuture<V> res = pollAsync(timeout, unit);
return res.await().getNow();
}
@ -118,7 +118,7 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
*/
@Override
public V pollFromAny(long timeout, TimeUnit unit, String ... queueNames) throws InterruptedException {
Future<V> res = pollFromAnyAsync(timeout, unit, queueNames);
RFuture<V> res = pollFromAnyAsync(timeout, unit, queueNames);
return res.await().getNow();
}
@ -144,7 +144,7 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
@Override
public V pollLastAndOfferFirstTo(String queueName, long timeout, TimeUnit unit) throws InterruptedException {
Future<V> res = pollLastAndOfferFirstToAsync(queueName, timeout, unit);
RFuture<V> res = pollLastAndOfferFirstToAsync(queueName, timeout, unit);
return res.await().getNow();
}

@ -178,9 +178,9 @@ public class RedissonBloomFilter<T> extends RedissonExpirable implements RBloomF
@Override
public int count() {
CommandBatchService executorService = new CommandBatchService(commandExecutor.getConnectionManager());
Future<Map<String, String>> configFuture = executorService.readAsync(getConfigName(), StringCodec.INSTANCE,
RFuture<Map<String, String>> configFuture = executorService.readAsync(getConfigName(), StringCodec.INSTANCE,
new RedisCommand<Map<Object, Object>>("HGETALL", new ObjectMapReplayDecoder()), getConfigName());
Future<Long> cardinalityFuture = executorService.readAsync(getName(), codec, RedisCommands.BITCOUNT, getName());
RFuture<Long> cardinalityFuture = executorService.readAsync(getName(), codec, RedisCommands.BITCOUNT, getName());
executorService.execute();
readConfig(configFuture.getNow());
@ -194,7 +194,7 @@ public class RedissonBloomFilter<T> extends RedissonExpirable implements RBloomF
}
private void readConfig() {
Future<Map<String, String>> future = commandExecutor.readAsync(getConfigName(), StringCodec.INSTANCE,
RFuture<Map<String, String>> future = commandExecutor.readAsync(getConfigName(), StringCodec.INSTANCE,
new RedisCommand<Map<Object, Object>>("HGETALL", new ObjectMapReplayDecoder()), getConfigName());
Map<String, String> config = commandExecutor.get(future);

@ -26,6 +26,7 @@ import java.util.Map.Entry;
import org.redisson.api.RBucket;
import org.redisson.api.RBuckets;
import org.redisson.api.RFuture;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.DelegateDecoderCodec;
import org.redisson.client.protocol.RedisCommand;
@ -34,8 +35,6 @@ import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandExecutor;
import org.redisson.connection.decoder.MapGetAllDecoder;
import io.netty.util.concurrent.Future;
public class RedissonBuckets implements RBuckets {
private final Codec codec;
@ -73,7 +72,7 @@ public class RedissonBuckets implements RBuckets {
}
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("MGET", new MapGetAllDecoder(Arrays.<Object>asList(keys), 0), ValueType.OBJECTS);
Future<Map<String, V>> future = commandExecutor.readAsync(keys[0], new DelegateDecoderCodec(codec), command, keys);
RFuture<Map<String, V>> future = commandExecutor.readAsync(keys[0], new DelegateDecoderCodec(codec), command, keys);
return commandExecutor.get(future);
}

@ -26,8 +26,6 @@ import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor;
import org.redisson.pubsub.CountDownLatchPubSub;
import io.netty.util.concurrent.Future;
/**
* Distributed alternative to the {@link java.util.concurrent.CountDownLatch}
*
@ -52,7 +50,7 @@ public class RedissonCountDownLatch extends RedissonObject implements RCountDown
}
public void await() throws InterruptedException {
Future<RedissonCountDownLatchEntry> promise = subscribe();
RFuture<RedissonCountDownLatchEntry> promise = subscribe();
try {
get(promise);
@ -70,7 +68,7 @@ public class RedissonCountDownLatch extends RedissonObject implements RCountDown
@Override
public boolean await(long time, TimeUnit unit) throws InterruptedException {
Future<RedissonCountDownLatchEntry> promise = subscribe();
RFuture<RedissonCountDownLatchEntry> promise = subscribe();
try {
if (!await(promise, time, unit)) {
return false;
@ -102,11 +100,11 @@ public class RedissonCountDownLatch extends RedissonObject implements RCountDown
return PUBSUB.getEntry(getEntryName());
}
private Future<RedissonCountDownLatchEntry> subscribe() {
private RFuture<RedissonCountDownLatchEntry> subscribe() {
return PUBSUB.subscribe(getEntryName(), getChannelName(), commandExecutor.getConnectionManager());
}
private void unsubscribe(Future<RedissonCountDownLatchEntry> future) {
private void unsubscribe(RFuture<RedissonCountDownLatchEntry> future) {
PUBSUB.unsubscribe(future.getNow(), getEntryName(), getChannelName(), commandExecutor.getConnectionManager());
}

@ -15,18 +15,17 @@
*/
package org.redisson;
import org.redisson.misc.RPromise;
import org.redisson.misc.ReclosableLatch;
import io.netty.util.concurrent.Promise;
public class RedissonCountDownLatchEntry implements PubSubEntry<RedissonCountDownLatchEntry> {
private int counter;
private final ReclosableLatch latch;
private final Promise<RedissonCountDownLatchEntry> promise;
private final RPromise<RedissonCountDownLatchEntry> promise;
public RedissonCountDownLatchEntry(Promise<RedissonCountDownLatchEntry> promise) {
public RedissonCountDownLatchEntry(RPromise<RedissonCountDownLatchEntry> promise) {
super();
this.latch = new ReclosableLatch();
this.promise = promise;
@ -40,7 +39,7 @@ public class RedissonCountDownLatchEntry implements PubSubEntry<RedissonCountDow
return --counter;
}
public Promise<RedissonCountDownLatchEntry> getPromise() {
public RPromise<RedissonCountDownLatchEntry> getPromise() {
return promise;
}

@ -67,7 +67,6 @@ import org.slf4j.LoggerFactory;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
import io.netty.util.internal.PlatformDependent;
/**
@ -442,7 +441,7 @@ public class RedissonExecutorService implements RScheduledExecutorService {
}
private <T> void execute(RemotePromise<T> promise) {
io.netty.util.concurrent.Future<Boolean> addFuture = promise.getAddFuture();
RFuture<Boolean> addFuture = promise.getAddFuture();
addFuture.syncUninterruptibly();
Boolean res = addFuture.getNow();
if (!res) {
@ -451,9 +450,9 @@ public class RedissonExecutorService implements RScheduledExecutorService {
}
@Override
public <T> Future<T> submit(Runnable task, final T result) {
final Promise<T> resultFuture = connectionManager.newPromise();
io.netty.util.concurrent.Future<Object> future = (io.netty.util.concurrent.Future<Object>) submit(task);
public <T> RFuture<T> submit(Runnable task, final T result) {
final RPromise<T> resultFuture = connectionManager.newPromise();
RFuture<Object> future = (RFuture<Object>) submit(task);
future.addListener(new FutureListener<Object>() {
@Override
public void operationComplete(io.netty.util.concurrent.Future<Object> future) throws Exception {
@ -487,7 +486,7 @@ public class RedissonExecutorService implements RScheduledExecutorService {
@Override
public ScheduledFuture<?> schedule(Runnable task, long delay, TimeUnit unit) {
RedissonScheduledFuture<?> future = (RedissonScheduledFuture<?>) scheduleAsync(task, delay, unit);
execute((RemotePromise<?>)future.getInnerFuture());
execute((RemotePromise<?>)future.getInnerPromise());
return future;
}
@ -505,7 +504,7 @@ public class RedissonExecutorService implements RScheduledExecutorService {
@Override
public <V> ScheduledFuture<V> schedule(Callable<V> task, long delay, TimeUnit unit) {
RedissonScheduledFuture<V> future = (RedissonScheduledFuture<V>) scheduleAsync(task, delay, unit);
execute((RemotePromise<V>)future.getInnerFuture());
execute((RemotePromise<V>)future.getInnerPromise());
return future;
}
@ -523,7 +522,7 @@ public class RedissonExecutorService implements RScheduledExecutorService {
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit unit) {
RedissonScheduledFuture<?> future = (RedissonScheduledFuture<?>) scheduleAtFixedRateAsync(task, initialDelay, period, unit);
execute((RemotePromise<?>)future.getInnerFuture());
execute((RemotePromise<?>)future.getInnerPromise());
return future;
}
@ -541,7 +540,7 @@ public class RedissonExecutorService implements RScheduledExecutorService {
@Override
public RScheduledFuture<?> schedule(Runnable task, CronSchedule cronSchedule) {
RedissonScheduledFuture<?> future = (RedissonScheduledFuture<?>) scheduleAsync(task, cronSchedule);
execute((RemotePromise<?>)future.getInnerFuture());
execute((RemotePromise<?>)future.getInnerPromise());
return future;
}
@ -564,7 +563,7 @@ public class RedissonExecutorService implements RScheduledExecutorService {
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit) {
RedissonScheduledFuture<?> future = (RedissonScheduledFuture<?>) scheduleWithFixedDelayAsync(task, initialDelay, delay, unit);
execute((RemotePromise<?>)future.getInnerFuture());
execute((RemotePromise<?>)future.getInnerPromise());
return future;
}
@ -760,7 +759,7 @@ public class RedissonExecutorService implements RScheduledExecutorService {
if (millis <= 0) {
int remainFutures = tasks.size() - futures.size();
for (int i = 0; i < remainFutures; i++) {
Promise<T> cancelledFuture = connectionManager.newPromise();
RPromise<T> cancelledFuture = connectionManager.newPromise();
cancelledFuture.cancel(true);
futures.add(cancelledFuture);

@ -28,8 +28,6 @@ import org.redisson.client.protocol.RedisStrictCommand;
import org.redisson.command.CommandExecutor;
import org.redisson.pubsub.LockPubSub;
import io.netty.util.concurrent.Future;
/**
* Distributed implementation of {@link java.util.concurrent.locks.Lock}
* Implements reentrant lock.<br>
@ -63,13 +61,13 @@ public class RedissonFairLock extends RedissonLock implements RLock {
}
@Override
protected Future<RedissonLockEntry> subscribe(long threadId) {
protected RFuture<RedissonLockEntry> subscribe(long threadId) {
return PUBSUB.subscribe(getEntryName() + ":" + threadId,
getChannelName() + ":" + getLockName(threadId), commandExecutor.getConnectionManager());
}
@Override
protected void unsubscribe(Future<RedissonLockEntry> future, long threadId) {
protected void unsubscribe(RFuture<RedissonLockEntry> future, long threadId) {
PUBSUB.unsubscribe(future.getNow(), getEntryName() + ":" + threadId,
getChannelName() + ":" + getLockName(threadId), commandExecutor.getConnectionManager());
}

@ -43,7 +43,6 @@ import org.redisson.misc.RPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
public class RedissonKeys implements RKeys {
@ -255,7 +254,7 @@ public class RedissonKeys implements RKeys {
executorService.writeAsync(entry.getKey(), null, RedisCommands.DEL, key);
}
Future<List<?>> future = executorService.executeAsync();
RFuture<List<?>> future = executorService.executeAsync();
future.addListener(listener);
}
@ -303,7 +302,7 @@ public class RedissonKeys implements RKeys {
return commandExecutor.writeAllAsync(RedisCommands.FLUSHALL);
}
private void checkExecution(final Promise<Long> result, final AtomicReference<Throwable> failed,
private void checkExecution(final RPromise<Long> result, final AtomicReference<Throwable> failed,
final AtomicLong count, final AtomicLong executed) {
if (executed.decrementAndGet() == 0) {
if (failed.get() != null) {

@ -339,19 +339,26 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
@Override
public V remove(int index) {
return remove((long) index);
}
public V remove(long index) {
return get(removeAsync(index));
}
public RFuture<V> removeAsync(long index) {
if (index == 0) {
RFuture<V> f = commandExecutor.writeAsync(getName(), codec, LPOP, getName());
return get(f);
return commandExecutor.writeAsync(getName(), codec, LPOP, getName());
}
RFuture<V> f = commandExecutor.evalWriteAsync(getName(), codec, EVAL_OBJECT,
return commandExecutor.evalWriteAsync(getName(), codec, EVAL_OBJECT,
"local v = redis.call('lindex', KEYS[1], ARGV[1]); " +
"redis.call('lset', KEYS[1], ARGV[1], 'DELETED_BY_REDISSON');" +
"redis.call('lrem', KEYS[1], 1, 'DELETED_BY_REDISSON');" +
"return v",
Collections.<Object>singletonList(getName()), index);
return get(f);
}
@Override
public void fastRemove(int index) {
@ -359,7 +366,7 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
}
@Override
public RFuture<Void> fastRemoveAsync(int index) {
public RFuture<Void> fastRemoveAsync(long index) {
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_VOID,
"redis.call('lset', KEYS[1], ARGV[1], 'DELETED_BY_REDISSON');" +
"redis.call('lrem', KEYS[1], 1, 'DELETED_BY_REDISSON');",
@ -376,7 +383,7 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
return indexOfAsync(o, new BooleanNumberReplayConvertor(-1L));
}
private <R> RFuture<R> indexOfAsync(Object o, Convertor<R> convertor) {
public <R> RFuture<R> indexOfAsync(Object o, Convertor<R> convertor) {
return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand<R>("EVAL", convertor, 4),
"local key = KEYS[1] " +
"local obj = ARGV[1] " +
@ -414,6 +421,20 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
"return -1",
Collections.<Object>singletonList(getName()), o);
}
public <R> RFuture<R> lastIndexOfAsync(Object o, Convertor<R> convertor) {
return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand<R>("EVAL", convertor, 4),
"local key = KEYS[1] " +
"local obj = ARGV[1] " +
"local items = redis.call('lrange', key, 0, -1) " +
"for i = #items, 1, -1 do " +
"if items[i] == obj then " +
"return i - 1 " +
"end " +
"end " +
"return -1",
Collections.<Object>singletonList(getName()), o);
}
@Override
public void trim(int fromIndex, int toIndex) {
@ -421,7 +442,7 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
}
@Override
public RFuture<Void> trimAsync(int fromIndex, int toIndex) {
public RFuture<Void> trimAsync(long fromIndex, long toIndex) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.LTRIM, getName(), fromIndex, toIndex);
}

@ -432,27 +432,30 @@ public class RedissonListMultimapValues<V> extends RedissonExpirable implements
@Override
public V remove(int index) {
return get(removeAsync(index));
}
@Override
public RFuture<V> removeAsync(long index) {
if (index == 0) {
RFuture<V> f = commandExecutor.writeAsync(getName(), codec, LPOP, getName());
return get(f);
return commandExecutor.writeAsync(getName(), codec, LPOP, getName());
}
RFuture<V> f = commandExecutor.evalWriteAsync(getName(), codec, EVAL_OBJECT,
return commandExecutor.evalWriteAsync(getName(), codec, EVAL_OBJECT,
"local v = redis.call('lindex', KEYS[1], ARGV[1]); " +
"redis.call('lset', KEYS[1], ARGV[1], 'DELETED_BY_REDISSON');" +
"redis.call('lrem', KEYS[1], 1, 'DELETED_BY_REDISSON');" +
"return v",
Collections.<Object>singletonList(getName()), index);
return get(f);
}
@Override
public void fastRemove(int index) {
get(fastRemoveAsync(index));
get(fastRemoveAsync((long)index));
}
@Override
public RFuture<Void> fastRemoveAsync(int index) {
public RFuture<Void> fastRemoveAsync(long index) {
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_VOID,
"redis.call('lset', KEYS[1], ARGV[1], 'DELETED_BY_REDISSON');" +
"redis.call('lrem', KEYS[1], 1, 'DELETED_BY_REDISSON');",
@ -528,7 +531,7 @@ public class RedissonListMultimapValues<V> extends RedissonExpirable implements
}
@Override
public RFuture<Void> trimAsync(int fromIndex, int toIndex) {
public RFuture<Void> trimAsync(long fromIndex, long toIndex) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.LTRIM, getName(), fromIndex, toIndex);
}

@ -40,7 +40,6 @@ import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
import io.netty.util.internal.PlatformDependent;
/**
@ -121,7 +120,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
}
long threadId = Thread.currentThread().getId();
Future<RedissonLockEntry> future = subscribe(threadId);
RFuture<RedissonLockEntry> future = subscribe(threadId);
get(future);
try {
@ -171,11 +170,11 @@ public class RedissonLock extends RedissonExpirable implements RLock {
return ttlRemainingFuture;
}
private <T> Future<Long> tryAcquireAsync(long leaseTime, TimeUnit unit, long threadId) {
private <T> RFuture<Long> tryAcquireAsync(long leaseTime, TimeUnit unit, long threadId) {
if (leaseTime != -1) {
return tryLockInnerAsync(leaseTime, unit, threadId, RedisCommands.EVAL_LONG);
}
Future<Long> ttlRemainingFuture = tryLockInnerAsync(LOCK_EXPIRATION_INTERVAL_SECONDS, TimeUnit.SECONDS, threadId, RedisCommands.EVAL_LONG);
RFuture<Long> ttlRemainingFuture = tryLockInnerAsync(LOCK_EXPIRATION_INTERVAL_SECONDS, TimeUnit.SECONDS, threadId, RedisCommands.EVAL_LONG);
ttlRemainingFuture.addListener(new FutureListener<Long>() {
@Override
public void operationComplete(Future<Long> future) throws Exception {
@ -206,7 +205,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
Timeout task = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
Future<Boolean> future = expireAsync(internalLockLeaseTime, TimeUnit.MILLISECONDS);
RFuture<Boolean> future = expireAsync(internalLockLeaseTime, TimeUnit.MILLISECONDS);
future.addListener(new FutureListener<Boolean>() {
@Override
public void operationComplete(Future<Boolean> future) throws Exception {
@ -265,14 +264,14 @@ public class RedissonLock extends RedissonExpirable implements RLock {
}
final long threadId = Thread.currentThread().getId();
Future<RedissonLockEntry> future = subscribe(threadId);
if (!await(future, time, TimeUnit.MILLISECONDS)) {
if (!future.cancel(false)) {
future.addListener(new FutureListener<RedissonLockEntry>() {
final RFuture<RedissonLockEntry> subscribeFuture = subscribe(threadId);
if (!await(subscribeFuture, time, TimeUnit.MILLISECONDS)) {
if (!subscribeFuture.cancel(false)) {
subscribeFuture.addListener(new FutureListener<RedissonLockEntry>() {
@Override
public void operationComplete(Future<RedissonLockEntry> future) throws Exception {
if (future.isSuccess()) {
unsubscribe(future, threadId);
if (subscribeFuture.isSuccess()) {
unsubscribe(subscribeFuture, threadId);
}
}
});
@ -304,7 +303,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
time -= elapsed;
}
} finally {
unsubscribe(future, threadId);
unsubscribe(subscribeFuture, threadId);
}
// return get(tryLockAsync(waitTime, leaseTime, unit));
}
@ -313,11 +312,11 @@ public class RedissonLock extends RedissonExpirable implements RLock {
return PUBSUB.getEntry(getEntryName());
}
protected Future<RedissonLockEntry> subscribe(long threadId) {
protected RFuture<RedissonLockEntry> subscribe(long threadId) {
return PUBSUB.subscribe(getEntryName(), getChannelName(), commandExecutor.getConnectionManager());
}
protected void unsubscribe(Future<RedissonLockEntry> future, long threadId) {
protected void unsubscribe(RFuture<RedissonLockEntry> future, long threadId) {
PUBSUB.unsubscribe(future.getNow(), getEntryName(), getChannelName(), commandExecutor.getConnectionManager());
}
@ -421,7 +420,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
public RFuture<Void> unlockAsync(final long threadId) {
final RPromise<Void> result = newPromise();
Future<Boolean> future = commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
RFuture<Boolean> future = commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
"if (redis.call('exists', KEYS[1]) == 0) then " +
"redis.call('publish', KEYS[2], ARGV[1]); " +
"return 1; " +
@ -477,7 +476,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
public RFuture<Void> lockAsync(final long leaseTime, final TimeUnit unit, final long currentThreadId) {
final RPromise<Void> result = newPromise();
Future<Long> ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId);
RFuture<Long> ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId);
ttlFuture.addListener(new FutureListener<Long>() {
@Override
public void operationComplete(Future<Long> future) throws Exception {
@ -494,7 +493,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
return;
}
final Future<RedissonLockEntry> subscribeFuture = subscribe(currentThreadId);
final RFuture<RedissonLockEntry> subscribeFuture = subscribe(currentThreadId);
subscribeFuture.addListener(new FutureListener<RedissonLockEntry>() {
@Override
public void operationComplete(Future<RedissonLockEntry> future) throws Exception {
@ -514,8 +513,8 @@ public class RedissonLock extends RedissonExpirable implements RLock {
}
private void lockAsync(final long leaseTime, final TimeUnit unit,
final Future<RedissonLockEntry> subscribeFuture, final Promise<Void> result, final long currentThreadId) {
Future<Long> ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId);
final RFuture<RedissonLockEntry> subscribeFuture, final RPromise<Void> result, final long currentThreadId) {
RFuture<Long> ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId);
ttlFuture.addListener(new FutureListener<Long>() {
@Override
public void operationComplete(Future<Long> future) throws Exception {
@ -596,7 +595,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
final RPromise<Boolean> result = newPromise();
final AtomicLong time = new AtomicLong(unit.toMillis(waitTime));
Future<Long> ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId);
RFuture<Long> ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId);
ttlFuture.addListener(new FutureListener<Long>() {
@Override
public void operationComplete(Future<Long> future) throws Exception {
@ -615,7 +614,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
final long current = System.currentTimeMillis();
final AtomicReference<Timeout> futureRef = new AtomicReference<Timeout>();
final Future<RedissonLockEntry> subscribeFuture = subscribe(currentThreadId);
final RFuture<RedissonLockEntry> subscribeFuture = subscribe(currentThreadId);
subscribeFuture.addListener(new FutureListener<RedissonLockEntry>() {
@Override
public void operationComplete(Future<RedissonLockEntry> future) throws Exception {
@ -660,8 +659,8 @@ public class RedissonLock extends RedissonExpirable implements RLock {
}
private void tryLockAsync(final AtomicLong time, final long leaseTime, final TimeUnit unit,
final Future<RedissonLockEntry> subscribeFuture, final Promise<Boolean> result, final long currentThreadId) {
Future<Long> ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId);
final RFuture<RedissonLockEntry> subscribeFuture, final RPromise<Boolean> result, final long currentThreadId) {
RFuture<Long> ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId);
ttlFuture.addListener(new FutureListener<Long>() {
@Override
public void operationComplete(Future<Long> future) throws Exception {

@ -15,20 +15,22 @@
*/
package org.redisson;
import io.netty.util.concurrent.Promise;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Semaphore;
import org.redisson.misc.RPromise;
import io.netty.util.concurrent.Promise;
public class RedissonLockEntry implements PubSubEntry<RedissonLockEntry> {
private int counter;
private final Semaphore latch;
private final Promise<RedissonLockEntry> promise;
private final RPromise<RedissonLockEntry> promise;
private final ConcurrentLinkedQueue<Runnable> listeners = new ConcurrentLinkedQueue<Runnable>();
public RedissonLockEntry(Promise<RedissonLockEntry> promise) {
public RedissonLockEntry(RPromise<RedissonLockEntry> promise) {
super();
this.latch = new Semaphore(0);
this.promise = promise;
@ -42,7 +44,7 @@ public class RedissonLockEntry implements PubSubEntry<RedissonLockEntry> {
return --counter;
}
public Promise<RedissonLockEntry> getPromise() {
public RPromise<RedissonLockEntry> getPromise() {
return promise;
}

@ -534,7 +534,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
MapScanResult<ScanObjectEntry, ScanObjectEntry> scanIterator(String name, InetSocketAddress client, long startPos) {
RedisCommand<MapCacheScanResult<Object, Object>> EVAL_HSCAN = new RedisCommand<MapCacheScanResult<Object, Object>>("EVAL",
new ListMultiDecoder(new LongMultiDecoder(), new ObjectMapDecoder(new ScanCodec(codec)), new ObjectListDecoder(codec), new MapCacheScanResultReplayDecoder()), ValueType.MAP);
Future<MapCacheScanResult<ScanObjectEntry, ScanObjectEntry>> f = commandExecutor.evalReadAsync(client, getName(), codec, EVAL_HSCAN,
RFuture<MapCacheScanResult<ScanObjectEntry, ScanObjectEntry>> f = commandExecutor.evalReadAsync(client, getName(), codec, EVAL_HSCAN,
"local result = {}; "
+ "local idleKeys = {}; "
+ "local res = redis.call('hscan', KEYS[1], ARGV[2]); "

@ -21,8 +21,8 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@ -30,14 +30,15 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import org.redisson.api.RFuture;
import org.redisson.api.RLock;
import org.redisson.misc.RPromise;
import org.redisson.misc.RedissonFuture;
import org.redisson.misc.RedissonPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise;
/**
* Groups multiple independent locks and manages them as one lock.
@ -80,7 +81,7 @@ public class RedissonMultiLock implements Lock {
}
public void lockInterruptibly(long leaseTime, TimeUnit unit) throws InterruptedException {
Promise<Void> promise = ImmediateEventExecutor.INSTANCE.newPromise();
RPromise<Void> promise = new RedissonPromise<Void>(ImmediateEventExecutor.INSTANCE.<Void>newPromise());
long currentThreadId = Thread.currentThread().getId();
Queue<RLock> lockedLocks = new ConcurrentLinkedQueue<RLock>();
@ -94,7 +95,7 @@ public class RedissonMultiLock implements Lock {
lockInterruptibly(-1, null);
}
private void lock(final Promise<Void> promise, final long waitTime, final long leaseTime, final TimeUnit unit,
private void lock(final RPromise<Void> promise, final long waitTime, final long leaseTime, final TimeUnit unit,
final List<RLock> locks, final long currentThreadId, final Queue<RLock> lockedLocks) throws InterruptedException {
final AtomicInteger tryLockRequestsAmount = new AtomicInteger();
final Map<Future<Boolean>, RLock> tryLockFutures = new HashMap<Future<Boolean>, RLock>(locks.size());
@ -145,7 +146,7 @@ public class RedissonMultiLock implements Lock {
}
}
protected void tryLockAgain(final Promise<Void> promise, final long waitTime, final long leaseTime,
protected void tryLockAgain(final RPromise<Void> promise, final long waitTime, final long leaseTime,
final TimeUnit unit, final long currentThreadId, final Map<Future<Boolean>, RLock> tryLockFutures) throws InterruptedException {
lockedLocks.clear();
if (failed.get() != null) {
@ -176,9 +177,9 @@ public class RedissonMultiLock implements Lock {
tryLockRequestsAmount.incrementAndGet();
Future<Boolean> future;
if (waitTime > 0 || leaseTime > 0) {
future = ((RedissonLock)lock).tryLockAsync(waitTime, leaseTime, unit, currentThreadId);
future = ((RedissonPromise)((RedissonLock)lock).tryLockAsync(waitTime, leaseTime, unit, currentThreadId)).getInnerPromise();
} else {
future = ((RedissonLock)lock).tryLockAsync(currentThreadId);
future = ((RedissonPromise)(((RedissonLock)lock).tryLockAsync(currentThreadId))).getInnerPromise();
}
if (future instanceof RedissonPromise) {
@ -197,7 +198,7 @@ public class RedissonMultiLock implements Lock {
@Override
public boolean tryLock() {
Map<RLock, Future<Boolean>> tryLockFutures = new HashMap<RLock, Future<Boolean>>(locks.size());
Map<RLock, RFuture<Boolean>> tryLockFutures = new HashMap<RLock, RFuture<Boolean>>(locks.size());
for (RLock lock : locks) {
tryLockFutures.put(lock, lock.tryLockAsync());
}
@ -205,10 +206,10 @@ public class RedissonMultiLock implements Lock {
return sync(tryLockFutures);
}
protected boolean sync(Map<RLock, Future<Boolean>> tryLockFutures) {
protected boolean sync(Map<RLock, RFuture<Boolean>> tryLockFutures) {
List<RLock> lockedLocks = new ArrayList<RLock>(tryLockFutures.size());
RuntimeException latestException = null;
for (Entry<RLock, Future<Boolean>> entry : tryLockFutures.entrySet()) {
for (Entry<RLock, RFuture<Boolean>> entry : tryLockFutures.entrySet()) {
try {
if (entry.getValue().syncUninterruptibly().getNow()) {
lockedLocks.add(entry.getKey());
@ -230,12 +231,12 @@ public class RedissonMultiLock implements Lock {
}
protected void unlockInner(Collection<RLock> locks) {
List<Future<Void>> futures = new ArrayList<Future<Void>>(locks.size());
List<RFuture<Void>> futures = new ArrayList<RFuture<Void>>(locks.size());
for (RLock lock : locks) {
futures.add(lock.unlockAsync());
}
for (Future<Void> unlockFuture : futures) {
for (RFuture<Void> unlockFuture : futures) {
unlockFuture.awaitUninterruptibly();
}
}
@ -246,7 +247,7 @@ public class RedissonMultiLock implements Lock {
}
public boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException {
Map<RLock, Future<Boolean>> tryLockFutures = new HashMap<RLock, Future<Boolean>>(locks.size());
Map<RLock, RFuture<Boolean>> tryLockFutures = new HashMap<RLock, RFuture<Boolean>>(locks.size());
for (RLock lock : locks) {
tryLockFutures.put(lock, lock.tryLockAsync(waitTime, leaseTime, unit));
}
@ -257,13 +258,13 @@ public class RedissonMultiLock implements Lock {
@Override
public void unlock() {
List<Future<Void>> futures = new ArrayList<Future<Void>>(locks.size());
List<RFuture<Void>> futures = new ArrayList<RFuture<Void>>(locks.size());
for (RLock lock : locks) {
futures.add(lock.unlockAsync());
}
for (Future<Void> future : futures) {
for (RFuture<Void> future : futures) {
future.syncUninterruptibly();
}
}

@ -41,8 +41,6 @@ import org.redisson.client.protocol.decoder.ScanObjectEntry;
import org.redisson.command.CommandAsyncExecutor;
import org.redisson.misc.Hash;
import io.netty.util.concurrent.Future;
/**
* @author Nikita Koksharov
*
@ -250,7 +248,7 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
MapScanResult<ScanObjectEntry, ScanObjectEntry> scanIterator(InetSocketAddress client, long startPos) {
Future<MapScanResult<ScanObjectEntry, ScanObjectEntry>> f = commandExecutor.readAsync(client, getName(), new ScanCodec(codec, StringCodec.INSTANCE), RedisCommands.HSCAN, getName(), startPos);
RFuture<MapScanResult<ScanObjectEntry, ScanObjectEntry>> f = commandExecutor.readAsync(client, getName(), new ScanCodec(codec, StringCodec.INSTANCE), RedisCommands.HSCAN, getName(), startPos);
return get(f);
}

@ -23,6 +23,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.redisson.api.RFuture;
import org.redisson.api.RedissonClient;
import org.redisson.client.RedisConnection;
import org.redisson.config.RedissonNodeConfig;
@ -33,7 +34,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.buffer.ByteBufUtil;
import io.netty.util.concurrent.Future;
import io.netty.util.internal.ThreadLocalRandom;
/**
@ -157,7 +157,7 @@ public class RedissonNode {
private void retrieveAdresses() {
ConnectionManager connectionManager = ((Redisson)redisson).getConnectionManager();
for (MasterSlaveEntry entry : connectionManager.getEntrySet()) {
Future<RedisConnection> readFuture = entry.connectionReadOp();
RFuture<RedisConnection> readFuture = entry.connectionReadOp();
if (readFuture.awaitUninterruptibly((long)connectionManager.getConfig().getConnectTimeout())
&& readFuture.isSuccess()) {
RedisConnection connection = readFuture.getNow();
@ -166,7 +166,7 @@ public class RedissonNode {
localAddress = (InetSocketAddress) connection.getChannel().localAddress();
return;
}
Future<RedisConnection> writeFuture = entry.connectionWriteOp();
RFuture<RedisConnection> writeFuture = entry.connectionWriteOp();
if (writeFuture.awaitUninterruptibly((long)connectionManager.getConfig().getConnectTimeout())
&& writeFuture.isSuccess()) {
RedisConnection connection = writeFuture.getNow();

@ -25,9 +25,6 @@ import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor;
import org.redisson.misc.RPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise;
/**
* Base Redisson object
*
@ -50,11 +47,11 @@ abstract class RedissonObject implements RObject {
this(commandExecutor.getConnectionManager().getCodec(), commandExecutor, name);
}
protected boolean await(Future<?> future, long timeout, TimeUnit timeoutUnit) throws InterruptedException {
protected boolean await(RFuture<?> future, long timeout, TimeUnit timeoutUnit) throws InterruptedException {
return commandExecutor.await(future, timeout, timeoutUnit);
}
protected <V> V get(Future<V> future) {
protected <V> V get(RFuture<V> future) {
return commandExecutor.get(future);
}

@ -18,6 +18,7 @@ package org.redisson;
import java.util.Collections;
import java.util.List;
import org.redisson.api.RFuture;
import org.redisson.api.RPatternTopic;
import org.redisson.api.listener.PatternMessageListener;
import org.redisson.api.listener.PatternStatusListener;
@ -27,8 +28,6 @@ import org.redisson.command.CommandExecutor;
import org.redisson.connection.PubSubConnectionEntry;
import org.redisson.pubsub.AsyncSemaphore;
import io.netty.util.concurrent.Future;
/**
* Distributed topic implementation. Messages are delivered to all message listeners across Redis cluster.
*
@ -64,7 +63,7 @@ public class RedissonPatternTopic<M> implements RPatternTopic<M> {
}
private int addListener(RedisPubSubListener<?> pubSubListener) {
Future<PubSubConnectionEntry> future = commandExecutor.getConnectionManager().psubscribe(name, codec, pubSubListener);
RFuture<PubSubConnectionEntry> future = commandExecutor.getConnectionManager().psubscribe(name, codec, pubSubListener);
future.syncUninterruptibly();
return System.identityHashCode(pubSubListener);
}

@ -28,6 +28,7 @@ import org.redisson.api.RBitSetReactive;
import org.redisson.api.RBlockingQueueReactive;
import org.redisson.api.RBucketReactive;
import org.redisson.api.RDequeReactive;
import org.redisson.api.RFuture;
import org.redisson.api.RHyperLogLogReactive;
import org.redisson.api.RKeysReactive;
import org.redisson.api.RLexSortedSetReactive;
@ -68,8 +69,6 @@ import org.redisson.reactive.RedissonSetCacheReactive;
import org.redisson.reactive.RedissonSetReactive;
import org.redisson.reactive.RedissonTopicReactive;
import io.netty.util.concurrent.Future;
/**
* Main infrastructure class allows to get access
* to all Redisson objects on top of Redis server.
@ -116,7 +115,7 @@ public class RedissonReactive implements RedissonReactiveClient {
@Override
public <V> List<RBucketReactive<V>> findBuckets(String pattern) {
Future<Collection<String>> r = commandExecutor.readAllAsync(RedisCommands.KEYS, pattern);
RFuture<Collection<String>> r = commandExecutor.readAllAsync(RedisCommands.KEYS, pattern);
Collection<String> keys = commandExecutor.get(r);
List<RBucketReactive<V>> buckets = new ArrayList<RBucketReactive<V>>(keys.size());

@ -22,6 +22,7 @@ import java.util.Map.Entry;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicReference;
import org.redisson.api.RFuture;
import org.redisson.api.RLock;
import io.netty.util.concurrent.Future;
@ -47,10 +48,10 @@ public class RedissonRedLock extends RedissonMultiLock {
super(locks);
}
protected boolean sync(Map<RLock, Future<Boolean>> tryLockFutures) {
protected boolean sync(Map<RLock, RFuture<Boolean>> tryLockFutures) {
List<RLock> lockedLocks = new ArrayList<RLock>(tryLockFutures.size());
RuntimeException latestException = null;
for (Entry<RLock, Future<Boolean>> entry : tryLockFutures.entrySet()) {
for (Entry<RLock, RFuture<Boolean>> entry : tryLockFutures.entrySet()) {
try {
if (entry.getValue().syncUninterruptibly().getNow()) {
lockedLocks.add(entry.getKey());

@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicReference;
import org.redisson.api.RBatch;
import org.redisson.api.RBlockingQueue;
import org.redisson.api.RBlockingQueueAsync;
import org.redisson.api.RFuture;
import org.redisson.api.RRemoteService;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.Codec;
@ -107,7 +108,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
private <T> void subscribe(final Class<T> remoteInterface, final RBlockingQueue<RemoteServiceRequest> requestQueue,
final ExecutorService executor) {
Future<RemoteServiceRequest> take = requestQueue.takeAsync();
RFuture<RemoteServiceRequest> take = requestQueue.takeAsync();
take.addListener(new FutureListener<RemoteServiceRequest>() {
@Override
public void operationComplete(Future<RemoteServiceRequest> future) throws Exception {
@ -139,7 +140,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
// send the ack only if expected
if (request.getOptions().isAckExpected()) {
String ackName = getAckName(remoteInterface, request.getRequestId());
Future<Boolean> ackClientsFuture = commandExecutor.evalWriteAsync(responseName,
RFuture<Boolean> ackClientsFuture = commandExecutor.evalWriteAsync(responseName,
LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
"if redis.call('setnx', KEYS[1], 1) == 1 then "
+ "redis.call('pexpire', KEYS[1], ARGV[2]);"
@ -188,7 +189,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
if (executor != null) {
RBlockingQueue<RemoteServiceCancelRequest> cancelRequestQueue =
redisson.getBlockingQueue(getCancelRequestQueueName(remoteInterface, request.getRequestId()), getCodec());
final Future<RemoteServiceCancelRequest> cancelRequestFuture = cancelRequestQueue.takeAsync();
final RFuture<RemoteServiceCancelRequest> cancelRequestFuture = cancelRequestQueue.takeAsync();
final AtomicReference<RRemoteServiceResponse> responseHolder = new AtomicReference<RRemoteServiceResponse>();
@ -230,7 +231,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
private <T> void invokeMethod(final Class<T> remoteInterface,
final RBlockingQueue<RemoteServiceRequest> requestQueue, final RemoteServiceRequest request,
RemoteServiceMethod method, String responseName, final ExecutorService executor,
Future<RemoteServiceCancelRequest> cancelRequestFuture, final AtomicReference<RRemoteServiceResponse> responseHolder) {
RFuture<RemoteServiceCancelRequest> cancelRequestFuture, final AtomicReference<RRemoteServiceResponse> responseHolder) {
try {
if (method.getBean() instanceof RemoteParams) {
((RemoteParams)method.getBean()).setRequestId(request.getRequestId());
@ -258,7 +259,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
timeout = request.getOptions().getExecutionTimeoutInMillis();
}
Future<List<?>> clientsFuture = send(timeout, responseName,
RFuture<List<?>> clientsFuture = send(timeout, responseName,
responseHolder.get());
clientsFuture.addListener(new FutureListener<List<?>>() {
@Override
@ -282,7 +283,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
}
}
private <T extends RRemoteServiceResponse> Future<List<?>> send(long timeout, String responseName, T response) {
private <T extends RRemoteServiceResponse> RFuture<List<?>> send(long timeout, String responseName, T response) {
RBatch batch = redisson.createBatch();
RBlockingQueueAsync<T> queue = batch.getBlockingQueue(responseName, getCodec());
queue.putAsync(response);

@ -33,15 +33,13 @@ import org.redisson.client.codec.Codec;
import org.redisson.client.codec.ScoredCodec;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.RedisCommand.ValueType;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.client.protocol.RedisCommand.ValueType;
import org.redisson.client.protocol.convertor.BooleanReplayConvertor;
import org.redisson.client.protocol.decoder.ListScanResult;
import org.redisson.command.CommandAsyncExecutor;
import io.netty.util.concurrent.Future;
public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RScoredSortedSet<V> {
public RedissonScoredSortedSet(CommandAsyncExecutor commandExecutor, String name) {
@ -253,7 +251,7 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
}
private ListScanResult<V> scanIterator(InetSocketAddress client, long startPos) {
Future<ListScanResult<V>> f = commandExecutor.readAsync(client, getName(), codec, RedisCommands.ZSCAN, getName(), startPos);
RFuture<ListScanResult<V>> f = commandExecutor.readAsync(client, getName(), codec, RedisCommands.ZSCAN, getName(), startPos);
return get(f);
}

@ -35,7 +35,6 @@ import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
/**
* Distributed and concurrent implementation of {@link java.util.concurrent.Semaphore}.
@ -79,7 +78,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
return;
}
Future<RedissonLockEntry> future = subscribe();
RFuture<RedissonLockEntry> future = subscribe();
get(future);
try {
while (true) {
@ -103,7 +102,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
@Override
public RFuture<Void> acquireAsync(final int permits) {
final RPromise<Void> result = newPromise();
Future<Boolean> tryAcquireFuture = tryAcquireAsync(permits);
RFuture<Boolean> tryAcquireFuture = tryAcquireAsync(permits);
tryAcquireFuture.addListener(new FutureListener<Boolean>() {
@Override
public void operationComplete(Future<Boolean> future) throws Exception {
@ -117,7 +116,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
return;
}
final Future<RedissonLockEntry> subscribeFuture = subscribe();
final RFuture<RedissonLockEntry> subscribeFuture = subscribe();
subscribeFuture.addListener(new FutureListener<RedissonLockEntry>() {
@Override
public void operationComplete(Future<RedissonLockEntry> future) throws Exception {
@ -135,8 +134,8 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
return result;
}
private void tryAcquireAsync(final AtomicLong time, final int permits, final Future<RedissonLockEntry> subscribeFuture, final Promise<Boolean> result) {
Future<Boolean> tryAcquireFuture = tryAcquireAsync(permits);
private void tryAcquireAsync(final AtomicLong time, final int permits, final RFuture<RedissonLockEntry> subscribeFuture, final RPromise<Boolean> result) {
RFuture<Boolean> tryAcquireFuture = tryAcquireAsync(permits);
tryAcquireFuture.addListener(new FutureListener<Boolean>() {
@Override
public void operationComplete(Future<Boolean> future) throws Exception {
@ -206,8 +205,8 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
}
private void acquireAsync(final int permits, final Future<RedissonLockEntry> subscribeFuture, final Promise<Void> result) {
Future<Boolean> tryAcquireFuture = tryAcquireAsync(permits);
private void acquireAsync(final int permits, final RFuture<RedissonLockEntry> subscribeFuture, final RPromise<Void> result) {
RFuture<Boolean> tryAcquireFuture = tryAcquireAsync(permits);
tryAcquireFuture.addListener(new FutureListener<Boolean>() {
@Override
public void operationComplete(Future<Boolean> future) throws Exception {
@ -284,7 +283,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
}
long time = unit.toMillis(waitTime);
Future<RedissonLockEntry> future = subscribe();
RFuture<RedissonLockEntry> future = subscribe();
if (!await(future, time, TimeUnit.MILLISECONDS)) {
return false;
}
@ -317,7 +316,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
public RFuture<Boolean> tryAcquireAsync(final int permits, long waitTime, TimeUnit unit) {
final RPromise<Boolean> result = newPromise();
final AtomicLong time = new AtomicLong(unit.toMillis(waitTime));
Future<Boolean> tryAcquireFuture = tryAcquireAsync(permits);
RFuture<Boolean> tryAcquireFuture = tryAcquireAsync(permits);
tryAcquireFuture.addListener(new FutureListener<Boolean>() {
@Override
public void operationComplete(Future<Boolean> future) throws Exception {
@ -333,7 +332,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
final long current = System.currentTimeMillis();
final AtomicReference<Timeout> futureRef = new AtomicReference<Timeout>();
final Future<RedissonLockEntry> subscribeFuture = subscribe();
final RFuture<RedissonLockEntry> subscribeFuture = subscribe();
subscribeFuture.addListener(new FutureListener<RedissonLockEntry>() {
@Override
public void operationComplete(Future<RedissonLockEntry> future) throws Exception {
@ -381,11 +380,11 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
return semaphorePubSub.getEntry(getName());
}
private Future<RedissonLockEntry> subscribe() {
private RFuture<RedissonLockEntry> subscribe() {
return semaphorePubSub.subscribe(getName(), getChannelName(), commandExecutor.getConnectionManager());
}
private void unsubscribe(Future<RedissonLockEntry> future) {
private void unsubscribe(RFuture<RedissonLockEntry> future) {
semaphorePubSub.unsubscribe(future.getNow(), getName(), getChannelName(), commandExecutor.getConnectionManager());
}

@ -323,7 +323,7 @@ public class RedissonSubList<V> extends RedissonList<V> implements RList<V> {
return get(f);
}
private <R> RFuture<R> indexOfAsync(Object o, Convertor<R> convertor) {
public <R> RFuture<R> indexOfAsync(Object o, Convertor<R> convertor) {
return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand<R>("EVAL", convertor, 4),
"local items = redis.call('lrange', KEYS[1], tonumber(ARGV[2]), tonumber(ARGV[3])) " +
"for i=1,#items do " +
@ -470,7 +470,7 @@ public class RedissonSubList<V> extends RedissonList<V> implements RList<V> {
}
@Override
public RFuture<Void> trimAsync(int fromIndex, int toIndex) {
public RFuture<Void> trimAsync(long fromIndex, long toIndex) {
if (fromIndex < this.fromIndex || toIndex >= this.toIndex.get()) {
throw new IndexOutOfBoundsException("fromIndex: " + fromIndex + " toIndex: " + toIndex);
}

@ -29,8 +29,6 @@ import org.redisson.command.CommandAsyncExecutor;
import org.redisson.connection.PubSubConnectionEntry;
import org.redisson.pubsub.AsyncSemaphore;
import io.netty.util.concurrent.Future;
/**
* Distributed topic implementation. Messages are delivered to all message listeners across Redis cluster.
*
@ -80,7 +78,7 @@ public class RedissonTopic<M> implements RTopic<M> {
}
private int addListener(RedisPubSubListener<?> pubSubListener) {
Future<PubSubConnectionEntry> future = commandExecutor.getConnectionManager().subscribe(codec, name, pubSubListener);
RFuture<PubSubConnectionEntry> future = commandExecutor.getConnectionManager().subscribe(codec, name, pubSubListener);
future.syncUninterruptibly();
return System.identityHashCode(pubSubListener);
}

@ -15,7 +15,9 @@
*/
package org.redisson.api;
import io.netty.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import io.netty.util.concurrent.FutureListener;
/**
* Represents the result of an asynchronous computation
@ -24,6 +26,77 @@ import io.netty.util.concurrent.Future;
*
* @param <V>
*/
public interface RFuture<V> extends Future<V> {
public interface RFuture<V> extends java.util.concurrent.Future<V> {
/**
* Returns {@code true} if and only if the I/O operation was completed
* successfully.
*/
boolean isSuccess();
/**
* Returns the cause of the failed I/O operation if the I/O operation has
* failed.
*
* @return the cause of the failure.
* {@code null} if succeeded or this future is not
* completed yet.
*/
Throwable cause();
/**
* Return the result without blocking. If the future is not done yet this will return {@code null}.
*
* As it is possible that a {@code null} value is used to mark the future as successful you also need to check
* if the future is really done with {@link #isDone()} and not relay on the returned {@code null} value.
*/
V getNow();
/**
* Waits for this future to be completed within the
* specified time limit.
*
* @return {@code true} if and only if the future was completed within
* the specified time limit
*
* @throws InterruptedException
* if the current thread was interrupted
*/
boolean await(long timeout, TimeUnit unit) throws InterruptedException;
/**
* Waits for this future to be completed within the
* specified time limit.
*
* @return {@code true} if and only if the future was completed within
* the specified time limit
*
* @throws InterruptedException
* if the current thread was interrupted
*/
boolean await(long timeoutMillis) throws InterruptedException;
RFuture<V> addListener(FutureListener<? super V> listener);
RFuture<V> addListeners(FutureListener<? super V>... listeners);
RFuture<V> removeListener(FutureListener<? super V> listener);
RFuture<V> removeListeners(FutureListener<? super V>... listeners);
boolean isCancellable();
RFuture<V> sync() throws InterruptedException;
RFuture<V> syncUninterruptibly();
RFuture<V> await() throws InterruptedException;
RFuture<V> awaitUninterruptibly();
boolean awaitUninterruptibly(long timeout, TimeUnit unit);
boolean awaitUninterruptibly(long timeoutMillis);
}

@ -81,8 +81,10 @@ public interface RListAsync<V> extends RCollectionAsync<V>, RandomAccess {
* @param toIndex
* @return
*/
RFuture<Void> trimAsync(int fromIndex, int toIndex);
RFuture<Void> trimAsync(long fromIndex, long toIndex);
RFuture<Void> fastRemoveAsync(int index);
RFuture<Void> fastRemoveAsync(long index);
RFuture<V> removeAsync(long index);
}

@ -15,10 +15,10 @@
*/
package org.redisson.client;
import io.netty.util.concurrent.Promise;
import org.redisson.misc.RPromise;
public interface ReconnectListener {
void onReconnect(RedisConnection redisConnection, Promise<RedisConnection> connectionFuture) throws RedisException;
void onReconnect(RedisConnection redisConnection, RPromise<RedisConnection> connectionFuture) throws RedisException;
}

@ -19,12 +19,15 @@ import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Map;
import org.redisson.api.RFuture;
import org.redisson.client.handler.CommandBatchEncoder;
import org.redisson.client.handler.CommandDecoder;
import org.redisson.client.handler.CommandEncoder;
import org.redisson.client.handler.CommandsQueue;
import org.redisson.client.handler.ConnectionWatchdog;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.misc.RPromise;
import org.redisson.misc.RedissonPromise;
import org.redisson.misc.URIBuilder;
import io.netty.bootstrap.Bootstrap;
@ -43,10 +46,9 @@ import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise;
/**
* Low-level Redis client
@ -128,8 +130,8 @@ public class RedisClient {
}
}
public Future<RedisConnection> connectAsync() {
final Promise<RedisConnection> f = ImmediateEventExecutor.INSTANCE.newPromise();
public RFuture<RedisConnection> connectAsync() {
final RPromise<RedisConnection> f = new RedissonPromise<RedisConnection>(ImmediateEventExecutor.INSTANCE.<RedisConnection>newPromise());
ChannelFuture channelFuture = bootstrap.connect();
channelFuture.addListener(new ChannelFutureListener() {
@Override
@ -155,8 +157,8 @@ public class RedisClient {
}
}
public Future<RedisPubSubConnection> connectPubSubAsync() {
final Promise<RedisPubSubConnection> f = ImmediateEventExecutor.INSTANCE.newPromise();
public RFuture<RedisPubSubConnection> connectPubSubAsync() {
final RPromise<RedisPubSubConnection> f = new RedissonPromise<RedisPubSubConnection>(ImmediateEventExecutor.INSTANCE.<RedisPubSubConnection>newPromise());
ChannelFuture channelFuture = bootstrap.connect();
channelFuture.addListener(new ChannelFutureListener() {
@Override
@ -206,12 +208,12 @@ public class RedisClient {
* @return A future for a map extracted from each response line splitting by
* ':' symbol
*/
public Future<Map<String, String>> serverInfoAsync() {
public RFuture<Map<String, String>> serverInfoAsync() {
final RedisConnection connection = connect();
Promise<Map<String, String>> async = (Promise) connection.async(RedisCommands.SERVER_INFO);
async.addListener(new GenericFutureListener<Promise<Map<String, String>>>() {
RFuture<Map<String, String>> async = connection.async(RedisCommands.SERVER_INFO);
async.addListener(new FutureListener<Map<String, String>>() {
@Override
public void operationComplete(Promise<Map<String, String>> future) throws Exception {
public void operationComplete(Future<Map<String, String>> future) throws Exception {
connection.closeAsync();
}
});

@ -18,6 +18,7 @@ package org.redisson.client;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.redisson.api.RFuture;
import org.redisson.client.codec.Codec;
import org.redisson.client.handler.CommandsQueue;
import org.redisson.client.protocol.CommandData;
@ -26,6 +27,9 @@ import org.redisson.client.protocol.QueueCommand;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.RedisStrictCommand;
import org.redisson.misc.RPromise;
import org.redisson.misc.RedissonFuture;
import org.redisson.misc.RedissonPromise;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
@ -49,7 +53,7 @@ public class RedisConnection implements RedisCommands {
private ReconnectListener reconnectListener;
private long lastUsageTime;
private final Future<?> acquireFuture = ImmediateEventExecutor.INSTANCE.newSucceededFuture(this);
private final RFuture<?> acquireFuture = new RedissonFuture(ImmediateEventExecutor.INSTANCE.newSucceededFuture(this));
public RedisConnection(RedisClient redisClient, Channel channel) {
super();
@ -109,7 +113,7 @@ public class RedisConnection implements RedisCommands {
return redisClient;
}
public <R> R await(Future<R> future) {
public <R> R await(RFuture<R> future) {
final CountDownLatch l = new CountDownLatch(1);
future.addListener(new FutureListener<R>() {
@Override
@ -151,25 +155,25 @@ public class RedisConnection implements RedisCommands {
}
public <T, R> R sync(Codec encoder, RedisCommand<T> command, Object ... params) {
Promise<R> promise = ImmediateEventExecutor.INSTANCE.newPromise();
RPromise<R> promise = new RedissonPromise<R>(ImmediateEventExecutor.INSTANCE.<R>newPromise());
send(new CommandData<T, R>(promise, encoder, command, params));
return await(promise);
}
public <T, R> Future<R> async(RedisCommand<T> command, Object ... params) {
public <T, R> RFuture<R> async(RedisCommand<T> command, Object ... params) {
return async(null, command, params);
}
public <T, R> Future<R> async(long timeout, RedisCommand<T> command, Object ... params) {
public <T, R> RFuture<R> async(long timeout, RedisCommand<T> command, Object ... params) {
return async(null, command, params);
}
public <T, R> Future<R> async(Codec encoder, RedisCommand<T> command, Object ... params) {
public <T, R> RFuture<R> async(Codec encoder, RedisCommand<T> command, Object ... params) {
return async(-1, encoder, command, params);
}
public <T, R> Future<R> async(long timeout, Codec encoder, RedisCommand<T> command, Object ... params) {
final Promise<R> promise = ImmediateEventExecutor.INSTANCE.newPromise();
public <T, R> RFuture<R> async(long timeout, Codec encoder, RedisCommand<T> command, Object ... params) {
final RPromise<R> promise = new RedissonPromise<R>(ImmediateEventExecutor.INSTANCE.<R>newPromise());
if (timeout == -1) {
timeout = redisClient.getCommandTimeout();
}
@ -193,7 +197,7 @@ public class RedisConnection implements RedisCommands {
}
public <T, R> CommandData<T, R> create(Codec encoder, RedisCommand<T> command, Object ... params) {
Promise<R> promise = ImmediateEventExecutor.INSTANCE.newPromise();
RPromise<R> promise = new RedissonPromise<R>(ImmediateEventExecutor.INSTANCE.<R>newPromise());
return new CommandData<T, R>(promise, encoder, command, params);
}
@ -237,7 +241,7 @@ public class RedisConnection implements RedisCommands {
return getClass().getSimpleName() + "@" + System.identityHashCode(this) + " [redisClient=" + redisClient + ", channel=" + channel + "]";
}
public Future<?> getAcquireFuture() {
public RFuture<?> getAcquireFuture() {
return acquireFuture;
}

@ -43,6 +43,7 @@ import org.redisson.client.protocol.pubsub.Message;
import org.redisson.client.protocol.pubsub.PubSubMessage;
import org.redisson.client.protocol.pubsub.PubSubPatternMessage;
import org.redisson.client.protocol.pubsub.PubSubStatusMessage;
import org.redisson.misc.RPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -51,7 +52,6 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.Promise;
import io.netty.util.internal.PlatformDependent;
/**
@ -192,7 +192,7 @@ public class CommandDecoder extends ReplayingDecoder<State> {
}
if (i == commandBatch.getCommands().size()) {
Promise<Void> promise = commandBatch.getPromise();
RPromise<Void> promise = commandBatch.getPromise();
if (error != null) {
if (!promise.tryFailure(error) && promise.cause() instanceof RedisTimeoutException) {
log.warn("response has been skipped due to timeout! channel: {}, command: {}", ctx.channel(), data);

@ -23,6 +23,8 @@ import org.redisson.client.RedisException;
import org.redisson.client.RedisPubSubConnection;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.CommandData;
import org.redisson.misc.RPromise;
import org.redisson.misc.RedissonPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -39,7 +41,6 @@ import io.netty.util.TimerTask;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise;
public class ConnectionWatchdog extends ChannelInboundHandlerAdapter {
@ -125,7 +126,7 @@ public class ConnectionWatchdog extends ChannelInboundHandlerAdapter {
if (connection.getReconnectListener() != null) {
// new connection used only for channel init
RedisConnection rc = new RedisConnection(connection.getRedisClient(), channel);
Promise<RedisConnection> connectionFuture = ImmediateEventExecutor.INSTANCE.newPromise();
RPromise<RedisConnection> connectionFuture = new RedissonPromise<RedisConnection>(ImmediateEventExecutor.INSTANCE.<RedisConnection>newPromise());
connection.getReconnectListener().onReconnect(rc, connectionFuture);
connectionFuture.addListener(new FutureListener<RedisConnection>() {
@Override

@ -19,15 +19,14 @@ import java.util.concurrent.atomic.AtomicReference;
import org.redisson.client.RedisRedirectException;
import org.redisson.client.codec.Codec;
import io.netty.util.concurrent.Promise;
import org.redisson.misc.RPromise;
public class BatchCommandData<T, R> extends CommandData<T, R> implements Comparable<BatchCommandData<T, R>> {
private final int index;
private final AtomicReference<RedisRedirectException> redirectError = new AtomicReference<RedisRedirectException>();
public BatchCommandData(Promise<R> promise, Codec codec, RedisCommand<T> command, Object[] params, int index) {
public BatchCommandData(RPromise<R> promise, Codec codec, RedisCommand<T> command, Object[] params, int index) {
super(promise, codec, command, params);
this.index = index;
}

@ -21,22 +21,21 @@ import java.util.List;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.util.concurrent.Promise;
import org.redisson.misc.RPromise;
public class CommandData<T, R> implements QueueCommand {
final Promise<R> promise;
final RPromise<R> promise;
final RedisCommand<T> command;
final Object[] params;
final Codec codec;
final MultiDecoder<Object> messageDecoder;
public CommandData(Promise<R> promise, Codec codec, RedisCommand<T> command, Object[] params) {
public CommandData(RPromise<R> promise, Codec codec, RedisCommand<T> command, Object[] params) {
this(promise, null, codec, command, params);
}
public CommandData(Promise<R> promise, MultiDecoder<Object> messageDecoder, Codec codec, RedisCommand<T> command, Object[] params) {
public CommandData(RPromise<R> promise, MultiDecoder<Object> messageDecoder, Codec codec, RedisCommand<T> command, Object[] params) {
this.promise = promise;
this.command = command;
this.params = params;
@ -56,7 +55,7 @@ public class CommandData<T, R> implements QueueCommand {
return messageDecoder;
}
public Promise<R> getPromise() {
public RPromise<R> getPromise() {
return promise;
}

@ -18,20 +18,20 @@ package org.redisson.client.protocol;
import java.util.ArrayList;
import java.util.List;
import io.netty.util.concurrent.Promise;
import org.redisson.misc.RPromise;
public class CommandsData implements QueueCommand {
private final List<CommandData<?, ?>> commands;
private final Promise<Void> promise;
private final RPromise<Void> promise;
public CommandsData(Promise<Void> promise, List<CommandData<?, ?>> commands) {
public CommandsData(RPromise<Void> promise, List<CommandData<?, ?>> commands) {
super();
this.promise = promise;
this.commands = commands;
}
public Promise<Void> getPromise() {
public RPromise<Void> getPromise() {
return promise;
}

@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.redisson.api.RFuture;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisConnectionException;
@ -46,13 +47,13 @@ import org.redisson.connection.ClientConnectionsEntry.FreezeReason;
import org.redisson.connection.MasterSlaveConnectionManager;
import org.redisson.connection.MasterSlaveEntry;
import org.redisson.connection.SingleEntry;
import org.redisson.misc.RPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.Promise;
import io.netty.util.concurrent.ScheduledFuture;
import io.netty.util.internal.PlatformDependent;
@ -77,7 +78,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
Exception lastException = null;
for (URI addr : cfg.getNodeAddresses()) {
Future<RedisConnection> connectionFuture = connect(cfg, addr);
RFuture<RedisConnection> connectionFuture = connect(cfg, addr);
try {
RedisConnection connection = connectionFuture.syncUninterruptibly().getNow();
List<ClusterNodeInfo> nodes = connection.sync(RedisCommands.CLUSTER_NODES);
@ -93,21 +94,21 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
lastClusterNode = addr;
Collection<ClusterPartition> partitions = parsePartitions(nodes);
List<Future<Collection<Future<Void>>>> futures = new ArrayList<Future<Collection<Future<Void>>>>();
List<RFuture<Collection<RFuture<Void>>>> futures = new ArrayList<RFuture<Collection<RFuture<Void>>>>();
for (ClusterPartition partition : partitions) {
if (partition.isMasterFail()) {
continue;
}
Future<Collection<Future<Void>>> masterFuture = addMasterEntry(partition, cfg);
RFuture<Collection<RFuture<Void>>> masterFuture = addMasterEntry(partition, cfg);
futures.add(masterFuture);
}
for (Future<Collection<Future<Void>>> masterFuture : futures) {
for (RFuture<Collection<RFuture<Void>>> masterFuture : futures) {
masterFuture.awaitUninterruptibly();
if (!masterFuture.isSuccess()) {
continue;
}
for (Future<Void> future : masterFuture.getNow()) {
for (RFuture<Void> future : masterFuture.getNow()) {
future.awaitUninterruptibly();
if (!future.isSuccess()) {
continue;
@ -140,15 +141,15 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
}
}
private Future<RedisConnection> connect(ClusterServersConfig cfg, final URI addr) {
private RFuture<RedisConnection> connect(ClusterServersConfig cfg, final URI addr) {
RedisConnection connection = nodeConnections.get(addr);
if (connection != null) {
return newSucceededFuture(connection);
}
RedisClient client = createClient(addr.getHost(), addr.getPort(), cfg.getConnectTimeout(), cfg.getRetryInterval() * cfg.getRetryAttempts());
final Promise<RedisConnection> result = newPromise();
Future<RedisConnection> future = client.connectAsync();
final RPromise<RedisConnection> result = newPromise();
RFuture<RedisConnection> future = client.connectAsync();
future.addListener(new FutureListener<RedisConnection>() {
@Override
public void operationComplete(Future<RedisConnection> future) throws Exception {
@ -158,7 +159,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
}
RedisConnection connection = future.getNow();
Promise<RedisConnection> promise = newPromise();
RPromise<RedisConnection> promise = newPromise();
connectListener.onConnect(promise, connection, null, config);
promise.addListener(new FutureListener<RedisConnection>() {
@Override
@ -188,7 +189,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
protected void initEntry(MasterSlaveServersConfig config) {
}
private Future<Collection<Future<Void>>> addMasterEntry(final ClusterPartition partition, final ClusterServersConfig cfg) {
private RFuture<Collection<RFuture<Void>>> addMasterEntry(final ClusterPartition partition, final ClusterServersConfig cfg) {
if (partition.isMasterFail()) {
RedisException e = new RedisException("Failed to add master: " +
partition.getMasterAddress() + " for slot ranges: " +
@ -201,8 +202,8 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
return newFailedFuture(e);
}
final Promise<Collection<Future<Void>>> result = newPromise();
Future<RedisConnection> connectionFuture = connect(cfg, partition.getMasterAddress());
final RPromise<Collection<RFuture<Void>>> result = newPromise();
RFuture<RedisConnection> connectionFuture = connect(cfg, partition.getMasterAddress());
connectionFuture.addListener(new FutureListener<RedisConnection>() {
@Override
public void operationComplete(Future<RedisConnection> future) throws Exception {
@ -213,7 +214,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
}
final RedisConnection connection = future.getNow();
Future<Map<String, String>> clusterFuture = connection.async(RedisCommands.CLUSTER_INFO);
RFuture<Map<String, String>> clusterFuture = connection.async(RedisCommands.CLUSTER_INFO);
clusterFuture.addListener(new FutureListener<Map<String, String>>() {
@Override
@ -238,7 +239,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
config.setMasterAddress(partition.getMasterAddress());
final MasterSlaveEntry e;
List<Future<Void>> futures = new ArrayList<Future<Void>>();
List<RFuture<Void>> futures = new ArrayList<RFuture<Void>>();
if (config.getReadMode() == ReadMode.MASTER) {
e = new SingleEntry(partition.getSlotRanges(), ClusterConnectionManager.this, config);
} else {
@ -246,7 +247,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
e = new MasterSlaveEntry(partition.getSlotRanges(), ClusterConnectionManager.this, config);
List<Future<Void>> fs = e.initSlaveBalancer(partition.getFailedSlaveAddresses());
List<RFuture<Void>> fs = e.initSlaveBalancer(partition.getFailedSlaveAddresses());
futures.addAll(fs);
if (!partition.getSlaveAddresses().isEmpty()) {
log.info("slaves: {} added for slot ranges: {}", partition.getSlaveAddresses(), partition.getSlotRanges());
@ -256,8 +257,8 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
}
}
Future<Void> f = e.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
final Promise<Void> initFuture = newPromise();
RFuture<Void> f = e.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
final RPromise<Void> initFuture = newPromise();
futures.add(initFuture);
f.addListener(new FutureListener<Void>() {
@Override
@ -327,7 +328,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
return;
}
final URI uri = iterator.next();
Future<RedisConnection> connectionFuture = connect(cfg, uri);
RFuture<RedisConnection> connectionFuture = connect(cfg, uri);
connectionFuture.addListener(new FutureListener<RedisConnection>() {
@Override
public void operationComplete(Future<RedisConnection> future) throws Exception {
@ -344,7 +345,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
}
private void updateClusterState(final ClusterServersConfig cfg, final RedisConnection connection, final Iterator<URI> iterator, final URI uri) {
Future<List<ClusterNodeInfo>> future = connection.async(RedisCommands.CLUSTER_NODES);
RFuture<List<ClusterNodeInfo>> future = connection.async(RedisCommands.CLUSTER_NODES);
future.addListener(new FutureListener<List<ClusterNodeInfo>>() {
@Override
public void operationComplete(Future<List<ClusterNodeInfo>> future) throws Exception {
@ -367,7 +368,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
}
final Collection<ClusterPartition> newPartitions = parsePartitions(nodes);
Future<Void> masterFuture = checkMasterNodesChange(cfg, newPartitions);
RFuture<Void> masterFuture = checkMasterNodesChange(cfg, newPartitions);
checkSlaveNodesChange(newPartitions);
masterFuture.addListener(new FutureListener<Void>() {
@Override
@ -434,7 +435,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
Set<URI> addedSlaves = new HashSet<URI>(newPart.getSlaveAddresses());
addedSlaves.removeAll(currentPart.getSlaveAddresses());
for (final URI uri : addedSlaves) {
Future<Void> future = entry.addSlave(uri.getHost(), uri.getPort());
RFuture<Void> future = entry.addSlave(uri.getHost(), uri.getPort());
future.addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
@ -470,7 +471,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
return null;
}
private Future<Void> checkMasterNodesChange(ClusterServersConfig cfg, Collection<ClusterPartition> newPartitions) {
private RFuture<Void> checkMasterNodesChange(ClusterServersConfig cfg, Collection<ClusterPartition> newPartitions) {
List<ClusterPartition> newMasters = new ArrayList<ClusterPartition>();
for (final ClusterPartition newPart : newPartitions) {
boolean masterFound = false;
@ -509,21 +510,21 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
return newSucceededFuture(null);
}
final Promise<Void> result = newPromise();
final RPromise<Void> result = newPromise();
final AtomicInteger masters = new AtomicInteger(newMasters.size());
final Queue<Future<Void>> futures = new ConcurrentLinkedQueue<Future<Void>>();
final Queue<RFuture<Void>> futures = new ConcurrentLinkedQueue<RFuture<Void>>();
for (ClusterPartition newPart : newMasters) {
Future<Collection<Future<Void>>> future = addMasterEntry(newPart, cfg);
future.addListener(new FutureListener<Collection<Future<Void>>>() {
RFuture<Collection<RFuture<Void>>> future = addMasterEntry(newPart, cfg);
future.addListener(new FutureListener<Collection<RFuture<Void>>>() {
@Override
public void operationComplete(Future<Collection<Future<Void>>> future) throws Exception {
public void operationComplete(Future<Collection<RFuture<Void>>> future) throws Exception {
if (future.isSuccess()) {
futures.addAll(future.getNow());
}
if (masters.decrementAndGet() == 0) {
final AtomicInteger nodes = new AtomicInteger(futures.size());
for (Future<Void> nodeFuture : futures) {
for (RFuture<Void> nodeFuture : futures) {
nodeFuture.addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {

@ -17,32 +17,32 @@ package org.redisson.command;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.redisson.api.RFuture;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisException;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.decoder.MultiDecoder;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.NodeSource;
import org.redisson.misc.RPromise;
import io.netty.channel.ChannelFuture;
import io.netty.util.Timeout;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise;
public class AsyncDetails<V, R> {
static final ConcurrentLinkedQueue<AsyncDetails> queue = new ConcurrentLinkedQueue<AsyncDetails>();
Future<RedisConnection> connectionFuture;
RFuture<RedisConnection> connectionFuture;
ConnectionManager connectionManager;
Promise<R> attemptPromise;
RPromise<R> attemptPromise;
boolean readOnlyMode;
NodeSource source;
Codec codec;
RedisCommand<V> command;
Object[] params;
Promise<R> mainPromise;
RPromise<R> mainPromise;
int attempt;
@ -69,10 +69,10 @@ public class AsyncDetails<V, R> {
// queue.add(details);
}
public void init(Future<RedisConnection> connectionFuture,
Promise<R> attemptPromise, boolean readOnlyMode, NodeSource source,
public void init(RFuture<RedisConnection> connectionFuture,
RPromise<R> attemptPromise, boolean readOnlyMode, NodeSource source,
Codec codec, RedisCommand<V> command, Object[] params,
Promise<R> mainPromise, int attempt) {
RPromise<R> mainPromise, int attempt) {
this.connectionFuture = connectionFuture;
this.attemptPromise = attemptPromise;
this.readOnlyMode = readOnlyMode;
@ -108,11 +108,11 @@ public class AsyncDetails<V, R> {
this.timeout = timeout;
}
public Future<RedisConnection> getConnectionFuture() {
public RFuture<RedisConnection> getConnectionFuture() {
return connectionFuture;
}
public Promise<R> getAttemptPromise() {
public RPromise<R> getAttemptPromise() {
return attemptPromise;
}
@ -136,7 +136,7 @@ public class AsyncDetails<V, R> {
return params;
}
public Promise<R> getMainPromise() {
public RPromise<R> getMainPromise() {
return mainPromise;
}

@ -28,8 +28,6 @@ import org.redisson.client.protocol.RedisCommand;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.MasterSlaveEntry;
import io.netty.util.concurrent.Future;
/**
*
* @author Nikita Koksharov
@ -39,11 +37,11 @@ public interface CommandAsyncExecutor {
ConnectionManager getConnectionManager();
<V> RedisException convertException(Future<V> RFuture);
<V> RedisException convertException(RFuture<V> RFuture);
boolean await(Future<?> RFuture, long timeout, TimeUnit timeoutUnit) throws InterruptedException;
boolean await(RFuture<?> RFuture, long timeout, TimeUnit timeoutUnit) throws InterruptedException;
<V> V get(Future<V> RFuture);
<V> V get(RFuture<V> RFuture);
<T, R> RFuture<R> writeAsync(MasterSlaveEntry entry, Codec codec, RedisCommand<T> command, Object ... params);

@ -59,7 +59,6 @@ import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
/**
*
@ -82,7 +81,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
}
@Override
public <V> V get(Future<V> future) {
public <V> V get(RFuture<V> future) {
final CountDownLatch l = new CountDownLatch(1);
future.addListener(new FutureListener<V>() {
@Override
@ -114,7 +113,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
}
@Override
public boolean await(Future<?> future, long timeout, TimeUnit timeoutUnit) throws InterruptedException {
public boolean await(RFuture<?> future, long timeout, TimeUnit timeoutUnit) throws InterruptedException {
final CountDownLatch l = new CountDownLatch(1);
future.addListener(new FutureListener<Object>() {
@Override
@ -173,7 +172,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
};
for (MasterSlaveEntry entry : nodes) {
Promise<R> promise = connectionManager.newPromise();
RPromise<R> promise = connectionManager.newPromise();
promise.addListener(listener);
async(true, new NodeSource(entry), connectionManager.getCodec(), command, params, promise, 0);
}
@ -190,7 +189,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
return mainPromise;
}
private <R, T> void retryReadRandomAsync(final RedisCommand<T> command, final Promise<R> mainPromise,
private <R, T> void retryReadRandomAsync(final RedisCommand<T> command, final RPromise<R> mainPromise,
final List<MasterSlaveEntry> nodes, final Object... params) {
final RPromise<R> attemptPromise = connectionManager.newPromise();
attemptPromise.addListener(new FutureListener<R>() {
@ -257,14 +256,14 @@ public class CommandAsyncService implements CommandAsyncExecutor {
};
for (MasterSlaveEntry entry : nodes) {
Promise<T> promise = connectionManager.newPromise();
RPromise<T> promise = connectionManager.newPromise();
promise.addListener(listener);
async(readOnlyMode, new NodeSource(entry), connectionManager.getCodec(), command, params, promise, 0);
}
return mainPromise;
}
public <V> RedisException convertException(Future<V> future) {
public <V> RedisException convertException(RFuture<V> future) {
return future.cause() instanceof RedisException ?
(RedisException) future.cause() :
new RedisException("Unexpected exception while processing command", future.cause());
@ -385,7 +384,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
args.addAll(keys);
args.addAll(Arrays.asList(params));
for (MasterSlaveEntry entry : entries) {
Promise<T> promise = connectionManager.newPromise();
RPromise<T> promise = connectionManager.newPromise();
promise.addListener(listener);
async(readOnlyMode, new NodeSource(entry), connectionManager.getCodec(), command, args.toArray(), promise, 0);
}
@ -417,7 +416,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
}
protected <V, R> void async(final boolean readOnlyMode, final NodeSource source, final Codec codec,
final RedisCommand<V> command, final Object[] params, final Promise<R> mainPromise, final int attempt) {
final RedisCommand<V> command, final Object[] params, final RPromise<R> mainPromise, final int attempt) {
if (mainPromise.isCancelled()) {
return;
}
@ -427,9 +426,9 @@ public class CommandAsyncService implements CommandAsyncExecutor {
return;
}
final Promise<R> attemptPromise = connectionManager.newPromise();
final RPromise<R> attemptPromise = connectionManager.newPromise();
final Future<RedisConnection> connectionFuture;
final RFuture<RedisConnection> connectionFuture;
if (readOnlyMode) {
connectionFuture = connectionManager.connectionReadOp(source, command);
} else {
@ -499,22 +498,22 @@ public class CommandAsyncService implements CommandAsyncExecutor {
if (!connFuture.isSuccess()) {
connectionManager.getShutdownLatch().release();
details.setException(convertException(connFuture));
details.setException(convertException(connectionFuture));
return;
}
if (details.getAttemptPromise().isDone() || details.getMainPromise().isDone()) {
releaseConnection(source, connFuture, details.isReadOnlyMode(), details.getAttemptPromise(), details);
releaseConnection(source, connectionFuture, details.isReadOnlyMode(), details.getAttemptPromise(), details);
return;
}
final RedisConnection connection = connFuture.getNow();
if (details.getSource().getRedirect() == Redirect.ASK) {
List<CommandData<?, ?>> list = new ArrayList<CommandData<?, ?>>(2);
Promise<Void> promise = connectionManager.newPromise();
RPromise<Void> promise = connectionManager.newPromise();
list.add(new CommandData<Void, Void>(promise, details.getCodec(), RedisCommands.ASKING, new Object[] {}));
list.add(new CommandData<V, R>(details.getAttemptPromise(), details.getCodec(), details.getCommand(), details.getParams()));
Promise<Void> main = connectionManager.newPromise();
RPromise<Void> main = connectionManager.newPromise();
ChannelFuture future = connection.send(new CommandsData(main, list));
details.setWriteFuture(future);
} else {
@ -533,7 +532,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
}
});
releaseConnection(source, connFuture, details.isReadOnlyMode(), details.getAttemptPromise(), details);
releaseConnection(source, connectionFuture, details.isReadOnlyMode(), details.getAttemptPromise(), details);
}
});
@ -647,8 +646,8 @@ public class CommandAsyncService implements CommandAsyncExecutor {
}
}
protected <V, R> void releaseConnection(final NodeSource source, final Future<RedisConnection> connectionFuture,
final boolean isReadOnly, Promise<R> attemptPromise, final AsyncDetails<V, R> details) {
protected <V, R> void releaseConnection(final NodeSource source, final RFuture<RedisConnection> connectionFuture,
final boolean isReadOnly, RPromise<R> attemptPromise, final AsyncDetails<V, R> details) {
attemptPromise.addListener(new FutureListener<R>() {
@Override
public void operationComplete(Future<R> future) throws Exception {

@ -93,7 +93,7 @@ public class CommandBatchService extends CommandReactiveService {
@Override
protected <V, R> void async(boolean readOnlyMode, NodeSource nodeSource,
Codec codec, RedisCommand<V> command, Object[] params, Promise<R> mainPromise, int attempt) {
Codec codec, RedisCommand<V> command, Object[] params, RPromise<R> mainPromise, int attempt) {
if (executed) {
throw new IllegalStateException("Batch already has been executed!");
}
@ -153,7 +153,7 @@ public class CommandBatchService extends CommandReactiveService {
}
executed = true;
Promise<Void> voidPromise = connectionManager.newPromise();
RPromise<Void> voidPromise = connectionManager.newPromise();
final RPromise<List<?>> promise = connectionManager.newPromise();
voidPromise.addListener(new FutureListener<Void>() {
@Override
@ -185,7 +185,7 @@ public class CommandBatchService extends CommandReactiveService {
return promise;
}
public void execute(final Entry entry, final NodeSource source, final Promise<Void> mainPromise, final AtomicInteger slots, final int attempt) {
public void execute(final Entry entry, final NodeSource source, final RPromise<Void> mainPromise, final AtomicInteger slots, final int attempt) {
if (mainPromise.isCancelled()) {
return;
}
@ -195,11 +195,11 @@ public class CommandBatchService extends CommandReactiveService {
return;
}
final Promise<Void> attemptPromise = connectionManager.newPromise();
final RPromise<Void> attemptPromise = connectionManager.newPromise();
final AsyncDetails details = new AsyncDetails();
final Future<RedisConnection> connectionFuture;
final RFuture<RedisConnection> connectionFuture;
if (entry.isReadOnlyMode()) {
connectionFuture = connectionManager.connectionReadOp(source, null);
} else {
@ -254,7 +254,7 @@ public class CommandBatchService extends CommandReactiveService {
connectionFuture.addListener(new FutureListener<RedisConnection>() {
@Override
public void operationComplete(Future<RedisConnection> connFuture) throws Exception {
checkConnectionFuture(entry, source, mainPromise, attemptPromise, details, connFuture);
checkConnectionFuture(entry, source, mainPromise, attemptPromise, details, connectionFuture);
}
});
}
@ -296,7 +296,7 @@ public class CommandBatchService extends CommandReactiveService {
});
}
private void checkWriteFuture(final Promise<Void> attemptPromise, AsyncDetails details,
private void checkWriteFuture(final RPromise<Void> attemptPromise, AsyncDetails details,
final RedisConnection connection, ChannelFuture future) {
if (attemptPromise.isDone() || future.isCancelled()) {
return;
@ -319,8 +319,8 @@ public class CommandBatchService extends CommandReactiveService {
}
private void checkConnectionFuture(final Entry entry, final NodeSource source,
final Promise<Void> mainPromise, final Promise<Void> attemptPromise, final AsyncDetails details,
Future<RedisConnection> connFuture) {
final RPromise<Void> mainPromise, final RPromise<Void> attemptPromise, final AsyncDetails details,
RFuture<RedisConnection> connFuture) {
if (attemptPromise.isDone() || mainPromise.isCancelled() || connFuture.isCancelled()) {
return;
}
@ -335,7 +335,7 @@ public class CommandBatchService extends CommandReactiveService {
List<CommandData<?, ?>> list = new ArrayList<CommandData<?, ?>>(entry.getCommands().size() + 1);
if (source.getRedirect() == Redirect.ASK) {
Promise<Void> promise = connectionManager.newPromise();
RPromise<Void> promise = connectionManager.newPromise();
list.add(new CommandData<Void, Void>(promise, StringCodec.INSTANCE, RedisCommands.ASKING, new Object[] {}));
}
for (BatchCommandData<?, ?> c : entry.getCommands()) {

@ -21,13 +21,12 @@ import java.util.List;
import org.reactivestreams.Publisher;
import org.redisson.SlotCallback;
import org.redisson.api.RFuture;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.MasterSlaveEntry;
import io.netty.util.concurrent.Future;
/**
*
* @author Nikita Koksharov
@ -35,7 +34,7 @@ import io.netty.util.concurrent.Future;
*/
public interface CommandReactiveExecutor extends CommandAsyncExecutor {
<R> Publisher<R> reactive(Future<R> future);
<R> Publisher<R> reactive(RFuture<R> future);
ConnectionManager getConnectionManager();

@ -21,14 +21,13 @@ import java.util.List;
import org.reactivestreams.Publisher;
import org.redisson.SlotCallback;
import org.redisson.api.RFuture;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.MasterSlaveEntry;
import org.redisson.reactive.NettyFuturePublisher;
import io.netty.util.concurrent.Future;
/**
*
* @author Nikita Koksharov
@ -42,29 +41,29 @@ public class CommandReactiveService extends CommandAsyncService implements Comma
@Override
public <T, R> Publisher<R> evalWriteAllReactive(RedisCommand<T> command, SlotCallback<T, R> callback, String script, List<Object> keys, Object ... params) {
Future<R> f = evalWriteAllAsync(command, callback, script, keys, params);
RFuture<R> f = evalWriteAllAsync(command, callback, script, keys, params);
return new NettyFuturePublisher<R>(f);
}
public <R> Publisher<R> reactive(Future<R> future) {
public <R> Publisher<R> reactive(RFuture<R> future) {
return new NettyFuturePublisher<R>(future);
}
@Override
public <T, R> Publisher<Collection<R>> readAllReactive(RedisCommand<T> command, Object ... params) {
Future<Collection<R>> f = readAllAsync(command, params);
RFuture<Collection<R>> f = readAllAsync(command, params);
return new NettyFuturePublisher<Collection<R>>(f);
}
@Override
public <T, R> Publisher<R> readRandomReactive(RedisCommand<T> command, Object ... params) {
Future<R> f = readRandomAsync(command, params);
RFuture<R> f = readRandomAsync(command, params);
return new NettyFuturePublisher<R>(f);
}
@Override
public <T, R> Publisher<R> readReactive(InetSocketAddress client, String key, Codec codec, RedisCommand<T> command, Object ... params) {
Future<R> f = readAsync(client, key, codec, command, params);
RFuture<R> f = readAsync(client, key, codec, command, params);
return new NettyFuturePublisher<R>(f);
}
@ -75,13 +74,13 @@ public class CommandReactiveService extends CommandAsyncService implements Comma
@Override
public <T, R> Publisher<R> writeReactive(String key, Codec codec, RedisCommand<T> command, Object ... params) {
Future<R> f = writeAsync(key, codec, command, params);
RFuture<R> f = writeAsync(key, codec, command, params);
return new NettyFuturePublisher<R>(f);
}
@Override
public <T, R> Publisher<R> writeReactive(MasterSlaveEntry entry, Codec codec, RedisCommand<T> command, Object ... params) {
Future<R> f = writeAsync(entry, codec, command, params);
RFuture<R> f = writeAsync(entry, codec, command, params);
return new NettyFuturePublisher<R>(f);
}
@ -92,21 +91,21 @@ public class CommandReactiveService extends CommandAsyncService implements Comma
@Override
public <T, R> Publisher<R> readReactive(String key, Codec codec, RedisCommand<T> command, Object ... params) {
Future<R> f = readAsync(key, codec, command, params);
RFuture<R> f = readAsync(key, codec, command, params);
return new NettyFuturePublisher<R>(f);
}
@Override
public <T, R> Publisher<R> evalReadReactive(String key, Codec codec, RedisCommand<T> evalCommandType,
String script, List<Object> keys, Object... params) {
Future<R> f = evalReadAsync(key, codec, evalCommandType, script, keys, params);
RFuture<R> f = evalReadAsync(key, codec, evalCommandType, script, keys, params);
return new NettyFuturePublisher<R>(f);
}
@Override
public <T, R> Publisher<R> evalReadReactive(InetSocketAddress client, String key, Codec codec, RedisCommand<T> evalCommandType,
String script, List<Object> keys, Object ... params) {
Future<R> f = evalReadAsync(client, key, codec, evalCommandType, script, keys, params);
RFuture<R> f = evalReadAsync(client, key, codec, evalCommandType, script, keys, params);
return new NettyFuturePublisher<R>(f);
}
@ -114,19 +113,19 @@ public class CommandReactiveService extends CommandAsyncService implements Comma
@Override
public <T, R> Publisher<R> evalWriteReactive(String key, Codec codec, RedisCommand<T> evalCommandType,
String script, List<Object> keys, Object... params) {
Future<R> f = evalWriteAsync(key, codec, evalCommandType, script, keys, params);
RFuture<R> f = evalWriteAsync(key, codec, evalCommandType, script, keys, params);
return new NettyFuturePublisher<R>(f);
}
@Override
public <T> Publisher<Void> writeAllReactive(RedisCommand<T> command, Object ... params) {
Future<Void> f = writeAllAsync(command, params);
RFuture<Void> f = writeAllAsync(command, params);
return new NettyFuturePublisher<Void>(f);
}
@Override
public <R, T> Publisher<R> writeAllReactive(RedisCommand<T> command, SlotCallback<T, R> callback, Object ... params) {
Future<R> f = writeAllAsync(command, callback, params);
RFuture<R> f = writeAllAsync(command, callback, params);
return new NettyFuturePublisher<R>(f);
}

@ -18,12 +18,11 @@ package org.redisson.command;
import java.net.InetSocketAddress;
import java.util.List;
import org.redisson.api.RFuture;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.connection.ConnectionManager;
import io.netty.util.concurrent.Future;
/**
*
* @author Nikita Koksharov
@ -31,7 +30,7 @@ import io.netty.util.concurrent.Future;
*/
public interface CommandSyncExecutor {
<V> V get(Future<V> future);
<V> V get(RFuture<V> future);
<T, R> R write(Integer slot, Codec codec, RedisCommand<T> command, Object ... params);

@ -18,14 +18,13 @@ package org.redisson.command;
import java.net.InetSocketAddress;
import java.util.List;
import org.redisson.api.RFuture;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.connection.ConnectionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.util.concurrent.Future;
/**
*
* @author Nikita Koksharov
@ -46,19 +45,19 @@ public class CommandSyncService extends CommandAsyncService implements CommandEx
@Override
public <T, R> R read(String key, Codec codec, RedisCommand<T> command, Object ... params) {
Future<R> res = readAsync(key, codec, command, params);
RFuture<R> res = readAsync(key, codec, command, params);
return get(res);
}
@Override
public <T, R> R read(InetSocketAddress client, String key, RedisCommand<T> command, Object ... params) {
Future<R> res = readAsync(client, key, connectionManager.getCodec(), command, params);
RFuture<R> res = readAsync(client, key, connectionManager.getCodec(), command, params);
return get(res);
}
@Override
public <T, R> R read(InetSocketAddress client, String key, Codec codec, RedisCommand<T> command, Object ... params) {
Future<R> res = readAsync(client, key, codec, command, params);
RFuture<R> res = readAsync(client, key, codec, command, params);
return get(res);
}
@ -69,7 +68,7 @@ public class CommandSyncService extends CommandAsyncService implements CommandEx
@Override
public <T, R> R evalRead(String key, Codec codec, RedisCommand<T> evalCommandType, String script, List<Object> keys, Object ... params) {
Future<R> res = evalReadAsync(key, codec, evalCommandType, script, keys, params);
RFuture<R> res = evalReadAsync(key, codec, evalCommandType, script, keys, params);
return get(res);
}
@ -80,25 +79,25 @@ public class CommandSyncService extends CommandAsyncService implements CommandEx
@Override
public <T, R> R evalWrite(String key, Codec codec, RedisCommand<T> evalCommandType, String script, List<Object> keys, Object ... params) {
Future<R> res = evalWriteAsync(key, codec, evalCommandType, script, keys, params);
RFuture<R> res = evalWriteAsync(key, codec, evalCommandType, script, keys, params);
return get(res);
}
@Override
public <T, R> R write(Integer slot, Codec codec, RedisCommand<T> command, Object ... params) {
Future<R> res = writeAsync(slot, codec, command, params);
RFuture<R> res = writeAsync(slot, codec, command, params);
return get(res);
}
@Override
public <T, R> R write(String key, Codec codec, RedisCommand<T> command, Object ... params) {
Future<R> res = writeAsync(key, codec, command, params);
RFuture<R> res = writeAsync(key, codec, command, params);
return get(res);
}
@Override
public <T, R> R write(String key, RedisCommand<T> command, Object ... params) {
Future<R> res = writeAsync(key, command, params);
RFuture<R> res = writeAsync(key, command, params);
return get(res);
}

@ -20,17 +20,18 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import org.redisson.api.NodeType;
import org.redisson.api.RFuture;
import org.redisson.client.ReconnectListener;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisPubSubConnection;
import org.redisson.config.MasterSlaveServersConfig;
import org.redisson.misc.RPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise;
public class ClientConnectionsEntry {
@ -138,9 +139,9 @@ public class ClientConnectionsEntry {
freeConnections.add(connection);
}
public Future<RedisConnection> connect() {
final Promise<RedisConnection> connectionFuture = connectionManager.newPromise();
Future<RedisConnection> future = client.connectAsync();
public RFuture<RedisConnection> connect() {
final RPromise<RedisConnection> connectionFuture = connectionManager.newPromise();
RFuture<RedisConnection> future = client.connectAsync();
future.addListener(new FutureListener<RedisConnection>() {
@Override
public void operationComplete(Future<RedisConnection> future) throws Exception {
@ -158,18 +159,18 @@ public class ClientConnectionsEntry {
return connectionFuture;
}
private <T extends RedisConnection> void addReconnectListener(Promise<T> connectionFuture, T conn) {
private <T extends RedisConnection> void addReconnectListener(RPromise<T> connectionFuture, T conn) {
addFireEventListener(conn, connectionFuture);
conn.setReconnectListener(new ReconnectListener() {
@Override
public void onReconnect(RedisConnection conn, Promise<RedisConnection> connectionFuture) {
public void onReconnect(RedisConnection conn, RPromise<RedisConnection> connectionFuture) {
addFireEventListener(conn, connectionFuture);
}
});
}
private <T extends RedisConnection> void addFireEventListener(T conn, Promise<T> connectionFuture) {
private <T extends RedisConnection> void addFireEventListener(T conn, RPromise<T> connectionFuture) {
connectionManager.getConnectListener().onConnect(connectionFuture, conn, nodeType, connectionManager.getConfig());
if (connectionFuture.isSuccess()) {
@ -191,9 +192,9 @@ public class ClientConnectionsEntry {
return connectionManager.getConfig();
}
public Future<RedisPubSubConnection> connectPubSub() {
final Promise<RedisPubSubConnection> connectionFuture = connectionManager.newPromise();
Future<RedisPubSubConnection> future = client.connectPubSubAsync();
public RFuture<RedisPubSubConnection> connectPubSub() {
final RPromise<RedisPubSubConnection> connectionFuture = connectionManager.newPromise();
RFuture<RedisPubSubConnection> future = client.connectPubSubAsync();
future.addListener(new FutureListener<RedisPubSubConnection>() {
@Override
public void operationComplete(Future<RedisPubSubConnection> future) throws Exception {

@ -18,11 +18,10 @@ package org.redisson.connection;
import org.redisson.api.NodeType;
import org.redisson.client.RedisConnection;
import org.redisson.config.MasterSlaveServersConfig;
import io.netty.util.concurrent.Promise;
import org.redisson.misc.RPromise;
public interface ConnectionInitializer {
<T extends RedisConnection> void onConnect(Promise<T> connectionFuture, T conn, NodeType nodeType, MasterSlaveServersConfig config);
<T extends RedisConnection> void onConnect(RPromise<T> connectionFuture, T conn, NodeType nodeType, MasterSlaveServersConfig config);
}

@ -36,7 +36,6 @@ import org.redisson.pubsub.AsyncSemaphore;
import io.netty.channel.EventLoopGroup;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import io.netty.util.concurrent.Future;
/**
*
@ -59,9 +58,9 @@ public interface ConnectionManager {
boolean isShuttingDown();
Future<PubSubConnectionEntry> subscribe(Codec codec, String channelName, RedisPubSubListener<?> listener);
RFuture<PubSubConnectionEntry> subscribe(Codec codec, String channelName, RedisPubSubListener<?> listener);
Future<PubSubConnectionEntry> subscribe(Codec codec, String channelName, RedisPubSubListener<?> listener, AsyncSemaphore semaphore);
RFuture<PubSubConnectionEntry> subscribe(Codec codec, String channelName, RedisPubSubListener<?> listener, AsyncSemaphore semaphore);
ConnectionInitializer getConnectListener();
@ -89,9 +88,9 @@ public interface ConnectionManager {
void releaseWrite(NodeSource source, RedisConnection connection);
Future<RedisConnection> connectionReadOp(NodeSource source, RedisCommand<?> command);
RFuture<RedisConnection> connectionReadOp(NodeSource source, RedisCommand<?> command);
Future<RedisConnection> connectionWriteOp(NodeSource source, RedisCommand<?> command);
RFuture<RedisConnection> connectionWriteOp(NodeSource source, RedisCommand<?> command);
RedisClient createClient(String host, int port, int timeout, int commandTimeout);
@ -101,9 +100,9 @@ public interface ConnectionManager {
PubSubConnectionEntry getPubSubEntry(String channelName);
Future<PubSubConnectionEntry> psubscribe(String pattern, Codec codec, RedisPubSubListener<?> listener);
RFuture<PubSubConnectionEntry> psubscribe(String pattern, Codec codec, RedisPubSubListener<?> listener);
Future<PubSubConnectionEntry> psubscribe(String pattern, Codec codec, RedisPubSubListener<?> listener, AsyncSemaphore semaphore);
RFuture<PubSubConnectionEntry> psubscribe(String pattern, Codec codec, RedisPubSubListener<?> listener, AsyncSemaphore semaphore);
Codec unsubscribe(String channelName, AsyncSemaphore lock);
@ -123,6 +122,6 @@ public interface ConnectionManager {
InfinitySemaphoreLatch getShutdownLatch();
Future<Boolean> getShutdownPromise();
RFuture<Boolean> getShutdownPromise();
}

@ -20,12 +20,11 @@ import org.redisson.client.RedisConnection;
import org.redisson.client.RedisException;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.config.MasterSlaveServersConfig;
import io.netty.util.concurrent.Promise;
import org.redisson.misc.RPromise;
public class DefaultConnectionListener implements ConnectionInitializer {
public final <T extends RedisConnection> void onConnect(Promise<T> connectionFuture, T conn, NodeType nodeType, MasterSlaveServersConfig config) {
public final <T extends RedisConnection> void onConnect(RPromise<T> connectionFuture, T conn, NodeType nodeType, MasterSlaveServersConfig config) {
FutureConnectionListener<T> listener = new FutureConnectionListener<T>(connectionFuture, conn);
doConnect(config, nodeType, listener);
listener.executeCommands();

@ -30,11 +30,11 @@ import org.redisson.config.BaseMasterSlaveServersConfig;
import org.redisson.config.Config;
import org.redisson.config.ElasticacheServersConfig;
import org.redisson.config.MasterSlaveServersConfig;
import org.redisson.misc.RPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.Promise;
import io.netty.util.concurrent.ScheduledFuture;
/**
@ -110,7 +110,7 @@ public class ElasticacheConnectionManager extends MasterSlaveConnectionManager {
RedisClient client = createClient(addr.getHost(), addr.getPort(), cfg.getConnectTimeout(), cfg.getRetryInterval() * cfg.getRetryAttempts());
try {
connection = client.connect();
Promise<RedisConnection> future = newPromise();
RPromise<RedisConnection> future = newPromise();
connectListener.onConnect(future, connection, null, config);
future.syncUninterruptibly();
nodeConnections.put(addr, connection);

@ -19,22 +19,23 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.redisson.api.RFuture;
import org.redisson.client.RedisConnection;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.misc.RPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
public class FutureConnectionListener<T extends RedisConnection> implements FutureListener<Object> {
private final AtomicInteger commandsCounter = new AtomicInteger();
private final Promise<T> connectionPromise;
private final RPromise<T> connectionPromise;
private final T connection;
private final List<Runnable> commands = new ArrayList<Runnable>(4);
public FutureConnectionListener(Promise<T> connectionFuture, T connection) {
public FutureConnectionListener(RPromise<T> connectionFuture, T connection) {
super();
this.connectionPromise = connectionFuture;
this.connection = connection;
@ -45,7 +46,7 @@ public class FutureConnectionListener<T extends RedisConnection> implements Futu
commands.add(new Runnable() {
@Override
public void run() {
Future<Object> future = connection.async(command, params);
RFuture<Object> future = connection.async(command, params);
future.addListener(FutureConnectionListener.this);
}
});

@ -70,7 +70,6 @@ import io.netty.util.TimerTask;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise;
import io.netty.util.internal.PlatformDependent;
/**
@ -131,7 +130,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
private final Map<Integer, MasterSlaveEntry> entries = PlatformDependent.newConcurrentHashMap();
private final Promise<Boolean> shutdownPromise;
private final RPromise<Boolean> shutdownPromise;
private final InfinitySemaphoreLatch shutdownLatch = new InfinitySemaphoreLatch();
@ -245,7 +244,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
MasterSlaveEntry entry;
if (config.getReadMode() == ReadMode.MASTER) {
entry = new SingleEntry(slots, this, config);
Future<Void> f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
RFuture<Void> f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
f.syncUninterruptibly();
} else {
entry = createMasterSlaveEntry(config, slots);
@ -259,11 +258,11 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
protected MasterSlaveEntry createMasterSlaveEntry(MasterSlaveServersConfig config,
HashSet<ClusterSlotRange> slots) {
MasterSlaveEntry entry = new MasterSlaveEntry(slots, this, config);
List<Future<Void>> fs = entry.initSlaveBalancer(java.util.Collections.<URI>emptySet());
for (Future<Void> future : fs) {
List<RFuture<Void>> fs = entry.initSlaveBalancer(java.util.Collections.<URI>emptySet());
for (RFuture<Void> future : fs) {
future.syncUninterruptibly();
}
Future<Void> f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
RFuture<Void> f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
f.syncUninterruptibly();
return entry;
}
@ -322,40 +321,40 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
}
@Override
public Future<PubSubConnectionEntry> psubscribe(final String channelName, final Codec codec, final RedisPubSubListener<?> listener) {
public RFuture<PubSubConnectionEntry> psubscribe(final String channelName, final Codec codec, final RedisPubSubListener<?> listener) {
final AsyncSemaphore lock = getSemaphore(channelName);
final Promise<PubSubConnectionEntry> result = newPromise();
final RPromise<PubSubConnectionEntry> result = newPromise();
lock.acquire(new Runnable() {
@Override
public void run() {
Future<PubSubConnectionEntry> future = psubscribe(channelName, codec, listener, lock);
RFuture<PubSubConnectionEntry> future = psubscribe(channelName, codec, listener, lock);
future.addListener(new TransferListener<PubSubConnectionEntry>(result));
}
});
return result;
}
public Future<PubSubConnectionEntry> psubscribe(String channelName, Codec codec, RedisPubSubListener<?> listener, AsyncSemaphore semaphore) {
Promise<PubSubConnectionEntry> promise = newPromise();
public RFuture<PubSubConnectionEntry> psubscribe(String channelName, Codec codec, RedisPubSubListener<?> listener, AsyncSemaphore semaphore) {
RPromise<PubSubConnectionEntry> promise = newPromise();
subscribe(codec, channelName, listener, promise, PubSubType.PSUBSCRIBE, semaphore);
return promise;
}
public Future<PubSubConnectionEntry> subscribe(final Codec codec, final String channelName, final RedisPubSubListener<?> listener) {
public RFuture<PubSubConnectionEntry> subscribe(final Codec codec, final String channelName, final RedisPubSubListener<?> listener) {
final AsyncSemaphore lock = getSemaphore(channelName);
final Promise<PubSubConnectionEntry> result = newPromise();
final RPromise<PubSubConnectionEntry> result = newPromise();
lock.acquire(new Runnable() {
@Override
public void run() {
Future<PubSubConnectionEntry> future = subscribe(codec, channelName, listener, lock);
RFuture<PubSubConnectionEntry> future = subscribe(codec, channelName, listener, lock);
future.addListener(new TransferListener<PubSubConnectionEntry>(result));
}
});
return result;
}
public Future<PubSubConnectionEntry> subscribe(Codec codec, String channelName, RedisPubSubListener<?> listener, AsyncSemaphore semaphore) {
Promise<PubSubConnectionEntry> promise = newPromise();
public RFuture<PubSubConnectionEntry> subscribe(Codec codec, String channelName, RedisPubSubListener<?> listener, AsyncSemaphore semaphore) {
RPromise<PubSubConnectionEntry> promise = newPromise();
subscribe(codec, channelName, listener, promise, PubSubType.SUBSCRIBE, semaphore);
return promise;
}
@ -365,7 +364,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
}
private void subscribe(final Codec codec, final String channelName, final RedisPubSubListener<?> listener,
final Promise<PubSubConnectionEntry> promise, final PubSubType type, final AsyncSemaphore lock) {
final RPromise<PubSubConnectionEntry> promise, final PubSubType type, final AsyncSemaphore lock) {
final PubSubConnectionEntry сonnEntry = name2PubSubConnection.get(channelName);
if (сonnEntry != null) {
сonnEntry.addListener(channelName, listener);
@ -439,9 +438,9 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
}
private void connect(final Codec codec, final String channelName, final RedisPubSubListener<?> listener,
final Promise<PubSubConnectionEntry> promise, final PubSubType type, final AsyncSemaphore lock) {
final RPromise<PubSubConnectionEntry> promise, final PubSubType type, final AsyncSemaphore lock) {
final int slot = calcSlot(channelName);
Future<RedisPubSubConnection> connFuture = nextPubSubConnection(slot);
RFuture<RedisPubSubConnection> connFuture = nextPubSubConnection(slot);
connFuture.addListener(new FutureListener<RedisPubSubConnection>() {
@Override
@ -614,7 +613,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
}
@Override
public Future<RedisConnection> connectionWriteOp(NodeSource source, RedisCommand<?> command) {
public RFuture<RedisConnection> connectionWriteOp(NodeSource source, RedisCommand<?> command) {
MasterSlaveEntry entry = source.getEntry();
if (entry == null) {
entry = getEntry(source);
@ -640,7 +639,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
}
@Override
public Future<RedisConnection> connectionReadOp(NodeSource source, RedisCommand<?> command) {
public RFuture<RedisConnection> connectionReadOp(NodeSource source, RedisCommand<?> command) {
MasterSlaveEntry entry = source.getEntry();
if (entry == null && source.getSlot() != null) {
entry = getEntry(source.getSlot());
@ -651,7 +650,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
return entry.connectionReadOp();
}
Future<RedisPubSubConnection> nextPubSubConnection(int slot) {
RFuture<RedisPubSubConnection> nextPubSubConnection(int slot) {
return getEntry(slot).nextPubSubConnection();
}
@ -746,7 +745,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
}
@Override
public Future<Boolean> getShutdownPromise() {
public RFuture<Boolean> getShutdownPromise() {
return shutdownPromise;
}

@ -25,6 +25,7 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.redisson.api.NodeType;
import org.redisson.api.RFuture;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisPubSubConnection;
@ -79,13 +80,13 @@ public class MasterSlaveEntry {
writeConnectionHolder = new MasterConnectionPool(config, connectionManager, this);
}
public List<Future<Void>> initSlaveBalancer(Collection<URI> disconnectedNodes) {
public List<RFuture<Void>> initSlaveBalancer(Collection<URI> disconnectedNodes) {
boolean freezeMasterAsSlave = !config.getSlaveAddresses().isEmpty()
&& config.getReadMode() == ReadMode.SLAVE
&& disconnectedNodes.size() < config.getSlaveAddresses().size();
List<Future<Void>> result = new LinkedList<Future<Void>>();
Future<Void> f = addSlave(config.getMasterAddress().getHost(), config.getMasterAddress().getPort(), freezeMasterAsSlave, NodeType.MASTER);
List<RFuture<Void>> result = new LinkedList<RFuture<Void>>();
RFuture<Void> f = addSlave(config.getMasterAddress().getHost(), config.getMasterAddress().getPort(), freezeMasterAsSlave, NodeType.MASTER);
result.add(f);
for (URI address : config.getSlaveAddresses()) {
f = addSlave(address.getHost(), address.getPort(), disconnectedNodes.contains(address), NodeType.SLAVE);
@ -94,7 +95,7 @@ public class MasterSlaveEntry {
return result;
}
public Future<Void> setupMasterEntry(String host, int port) {
public RFuture<Void> setupMasterEntry(String host, int port) {
RedisClient client = connectionManager.createClient(NodeType.MASTER, host, port);
masterEntry = new ClientConnectionsEntry(client, config.getMasterConnectionMinimumIdleSize(), config.getMasterConnectionPoolSize(),
0, 0, connectionManager, NodeType.MASTER);
@ -180,7 +181,7 @@ public class MasterSlaveEntry {
return;
}
Future<PubSubConnectionEntry> subscribeFuture = connectionManager.subscribe(subscribeCodec, channelName, null);
RFuture<PubSubConnectionEntry> subscribeFuture = connectionManager.subscribe(subscribeCodec, channelName, null);
subscribeFuture.addListener(new FutureListener<PubSubConnectionEntry>() {
@Override
@ -203,7 +204,7 @@ public class MasterSlaveEntry {
final Collection<RedisPubSubListener<?>> listeners) {
Codec subscribeCodec = connectionManager.punsubscribe(channelName);
if (!listeners.isEmpty()) {
Future<PubSubConnectionEntry> future = connectionManager.psubscribe(channelName, subscribeCodec, null);
RFuture<PubSubConnectionEntry> future = connectionManager.psubscribe(channelName, subscribeCodec, null);
future.addListener(new FutureListener<PubSubConnectionEntry>() {
@Override
public void operationComplete(Future<PubSubConnectionEntry> future)
@ -231,7 +232,7 @@ public class MasterSlaveEntry {
return;
}
Future<RedisConnection> newConnection = connectionReadOp();
RFuture<RedisConnection> newConnection = connectionReadOp();
newConnection.addListener(new FutureListener<RedisConnection>() {
@Override
public void operationComplete(Future<RedisConnection> future) throws Exception {
@ -268,11 +269,11 @@ public class MasterSlaveEntry {
});
}
public Future<Void> addSlave(String host, int port) {
public RFuture<Void> addSlave(String host, int port) {
return addSlave(host, port, true, NodeType.SLAVE);
}
private Future<Void> addSlave(String host, int port, boolean freezed, NodeType mode) {
private RFuture<Void> addSlave(String host, int port, boolean freezed, NodeType mode) {
RedisClient client = connectionManager.createClient(NodeType.SLAVE, host, port);
ClientConnectionsEntry entry = new ClientConnectionsEntry(client,
this.config.getSlaveConnectionMinimumIdleSize(),
@ -356,20 +357,19 @@ public class MasterSlaveEntry {
slaveBalancer.shutdownAsync();
}
public Future<RedisConnection> connectionWriteOp() {
public RFuture<RedisConnection> connectionWriteOp() {
return writeConnectionHolder.get();
}
public Future<RedisConnection> connectionReadOp() {
public RFuture<RedisConnection> connectionReadOp() {
return slaveBalancer.nextConnection();
}
public Future<RedisConnection> connectionReadOp(InetSocketAddress addr) {
public RFuture<RedisConnection> connectionReadOp(InetSocketAddress addr) {
return slaveBalancer.getConnection(addr);
}
Future<RedisPubSubConnection> nextPubSubConnection() {
RFuture<RedisPubSubConnection> nextPubSubConnection() {
return slaveBalancer.nextPubSubConnection();
}

@ -15,16 +15,15 @@
*/
package org.redisson.connection;
import io.netty.util.concurrent.Promise;
import java.net.InetSocketAddress;
import java.util.Map;
import org.redisson.api.ClusterNode;
import org.redisson.api.NodeType;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.protocol.RedisCommands;
import java.net.InetSocketAddress;
import java.util.Map;
import org.redisson.misc.RPromise;
public class RedisClientEntry implements ClusterNode {
@ -55,7 +54,7 @@ public class RedisClientEntry implements ClusterNode {
private RedisConnection connect() {
RedisConnection c = client.connect();
Promise<RedisConnection> future = manager.newPromise();
RPromise<RedisConnection> future = manager.newPromise();
manager.getConnectListener().onConnect(future, c, null, manager.getConfig());
future.syncUninterruptibly();
return future.getNow();

@ -25,6 +25,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicReference;
import org.redisson.api.RFuture;
import org.redisson.client.BaseRedisPubSubListener;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
@ -115,13 +116,13 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
}
init(c);
List<Future<RedisPubSubConnection>> connectionFutures = new ArrayList<Future<RedisPubSubConnection>>(cfg.getSentinelAddresses().size());
List<RFuture<RedisPubSubConnection>> connectionFutures = new ArrayList<RFuture<RedisPubSubConnection>>(cfg.getSentinelAddresses().size());
for (URI addr : cfg.getSentinelAddresses()) {
Future<RedisPubSubConnection> future = registerSentinel(cfg, addr, c);
RFuture<RedisPubSubConnection> future = registerSentinel(cfg, addr, c);
connectionFutures.add(future);
}
for (Future<RedisPubSubConnection> future : connectionFutures) {
for (RFuture<RedisPubSubConnection> future : connectionFutures) {
future.awaitUninterruptibly();
}
}
@ -130,23 +131,23 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
protected MasterSlaveEntry createMasterSlaveEntry(MasterSlaveServersConfig config,
HashSet<ClusterSlotRange> slots) {
MasterSlaveEntry entry = new MasterSlaveEntry(slots, this, config);
List<Future<Void>> fs = entry.initSlaveBalancer(disconnectedSlaves);
for (Future<Void> future : fs) {
List<RFuture<Void>> fs = entry.initSlaveBalancer(disconnectedSlaves);
for (RFuture<Void> future : fs) {
future.syncUninterruptibly();
}
Future<Void> f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
RFuture<Void> f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
f.syncUninterruptibly();
return entry;
}
private Future<RedisPubSubConnection> registerSentinel(final SentinelServersConfig cfg, final URI addr, final MasterSlaveServersConfig c) {
private RFuture<RedisPubSubConnection> registerSentinel(final SentinelServersConfig cfg, final URI addr, final MasterSlaveServersConfig c) {
RedisClient client = createClient(addr.getHost(), addr.getPort(), c.getConnectTimeout(), c.getRetryInterval() * c.getRetryAttempts());
RedisClient oldClient = sentinels.putIfAbsent(addr.getHost() + ":" + addr.getPort(), client);
if (oldClient != null) {
return newSucceededFuture(null);
}
Future<RedisPubSubConnection> pubsubFuture = client.connectPubSubAsync();
RFuture<RedisPubSubConnection> pubsubFuture = client.connectPubSubAsync();
pubsubFuture.addListener(new FutureListener<RedisPubSubConnection>() {
@Override
public void operationComplete(Future<RedisPubSubConnection> future) throws Exception {
@ -218,7 +219,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
// to avoid addition twice
if (slaves.putIfAbsent(slaveAddr, true) == null && config.getReadMode() != ReadMode.MASTER) {
Future<Void> future = getEntry(singleSlotRange.getStartSlot()).addSlave(ip, Integer.valueOf(port));
RFuture<Void> future = getEntry(singleSlotRange.getStartSlot()).addSlave(ip, Integer.valueOf(port));
future.addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {

@ -20,6 +20,7 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.redisson.api.NodeType;
import org.redisson.api.RFuture;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisPubSubConnection;
@ -27,10 +28,10 @@ import org.redisson.cluster.ClusterSlotRange;
import org.redisson.config.MasterSlaveServersConfig;
import org.redisson.connection.pool.PubSubConnectionPool;
import org.redisson.connection.pool.SinglePubSubConnectionPool;
import org.redisson.misc.RPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
public class SingleEntry extends MasterSlaveEntry {
@ -42,16 +43,16 @@ public class SingleEntry extends MasterSlaveEntry {
}
@Override
public Future<Void> setupMasterEntry(String host, int port) {
public RFuture<Void> setupMasterEntry(String host, int port) {
RedisClient masterClient = connectionManager.createClient(NodeType.MASTER, host, port);
masterEntry = new ClientConnectionsEntry(masterClient,
config.getMasterConnectionMinimumIdleSize(),
config.getMasterConnectionPoolSize(),
config.getSlaveConnectionMinimumIdleSize(),
config.getSlaveSubscriptionConnectionPoolSize(), connectionManager, NodeType.MASTER);
final Promise<Void> res = connectionManager.newPromise();
Future<Void> f = writeConnectionHolder.add(masterEntry);
Future<Void> s = pubSubConnectionHolder.add(masterEntry);
final RPromise<Void> res = connectionManager.newPromise();
RFuture<Void> f = writeConnectionHolder.add(masterEntry);
RFuture<Void> s = pubSubConnectionHolder.add(masterEntry);
FutureListener<Void> listener = new FutureListener<Void>() {
AtomicInteger counter = new AtomicInteger(2);
@Override
@ -71,7 +72,7 @@ public class SingleEntry extends MasterSlaveEntry {
}
@Override
Future<RedisPubSubConnection> nextPubSubConnection() {
RFuture<RedisPubSubConnection> nextPubSubConnection() {
return pubSubConnectionHolder.get();
}
@ -81,12 +82,12 @@ public class SingleEntry extends MasterSlaveEntry {
}
@Override
public Future<RedisConnection> connectionReadOp(InetSocketAddress addr) {
public RFuture<RedisConnection> connectionReadOp(InetSocketAddress addr) {
return super.connectionWriteOp();
}
@Override
public Future<RedisConnection> connectionReadOp() {
public RFuture<RedisConnection> connectionReadOp() {
return super.connectionWriteOp();
}

@ -17,16 +17,15 @@ package org.redisson.connection.balancer;
import java.net.InetSocketAddress;
import org.redisson.api.RFuture;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisPubSubConnection;
import org.redisson.connection.ClientConnectionsEntry;
import org.redisson.connection.ClientConnectionsEntry.FreezeReason;
import io.netty.util.concurrent.Future;
public interface LoadBalancerManager {
Future<RedisConnection> getConnection(InetSocketAddress addr);
RFuture<RedisConnection> getConnection(InetSocketAddress addr);
int getAvailableClients();
@ -40,11 +39,11 @@ public interface LoadBalancerManager {
ClientConnectionsEntry freeze(String host, int port, FreezeReason freezeReason);
Future<Void> add(ClientConnectionsEntry entry);
RFuture<Void> add(ClientConnectionsEntry entry);
Future<RedisConnection> nextConnection();
RFuture<RedisConnection> nextConnection();
Future<RedisPubSubConnection> nextPubSubConnection();
RFuture<RedisPubSubConnection> nextPubSubConnection();
void returnConnection(RedisConnection connection);

@ -19,6 +19,7 @@ import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.redisson.api.RFuture;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisConnectionException;
import org.redisson.client.RedisPubSubConnection;
@ -29,12 +30,12 @@ import org.redisson.connection.ConnectionManager;
import org.redisson.connection.MasterSlaveEntry;
import org.redisson.connection.pool.PubSubConnectionPool;
import org.redisson.connection.pool.SlaveConnectionPool;
import org.redisson.misc.RPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
import io.netty.util.internal.PlatformDependent;
public class LoadBalancerManagerImpl implements LoadBalancerManager {
@ -52,8 +53,8 @@ public class LoadBalancerManagerImpl implements LoadBalancerManager {
pubSubConnectionPool = new PubSubConnectionPool(config, connectionManager, entry);
}
public Future<Void> add(final ClientConnectionsEntry entry) {
final Promise<Void> result = connectionManager.newPromise();
public RFuture<Void> add(final ClientConnectionsEntry entry) {
final RPromise<Void> result = connectionManager.newPromise();
FutureListener<Void> listener = new FutureListener<Void>() {
AtomicInteger counter = new AtomicInteger(2);
@Override
@ -69,9 +70,9 @@ public class LoadBalancerManagerImpl implements LoadBalancerManager {
}
};
Future<Void> slaveFuture = slaveConnectionPool.add(entry);
RFuture<Void> slaveFuture = slaveConnectionPool.add(entry);
slaveFuture.addListener(listener);
Future<Void> pubSubFuture = pubSubConnectionPool.add(entry);
RFuture<Void> pubSubFuture = pubSubConnectionPool.add(entry);
pubSubFuture.addListener(listener);
return result;
}
@ -136,11 +137,11 @@ public class LoadBalancerManagerImpl implements LoadBalancerManager {
return connectionEntry;
}
public Future<RedisPubSubConnection> nextPubSubConnection() {
public RFuture<RedisPubSubConnection> nextPubSubConnection() {
return pubSubConnectionPool.get();
}
public Future<RedisConnection> getConnection(InetSocketAddress addr) {
public RFuture<RedisConnection> getConnection(InetSocketAddress addr) {
ClientConnectionsEntry entry = addr2Entry.get(addr);
if (entry != null) {
return slaveConnectionPool.get(entry);
@ -149,7 +150,7 @@ public class LoadBalancerManagerImpl implements LoadBalancerManager {
return connectionManager.newFailedFuture(exception);
}
public Future<RedisConnection> nextConnection() {
public RFuture<RedisConnection> nextConnection() {
return slaveConnectionPool.get();
}

@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.redisson.api.NodeType;
import org.redisson.api.RFuture;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisConnectionException;
import org.redisson.client.protocol.RedisCommands;
@ -31,6 +32,7 @@ import org.redisson.connection.ClientConnectionsEntry;
import org.redisson.connection.ClientConnectionsEntry.FreezeReason;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.MasterSlaveEntry;
import org.redisson.misc.RPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,7 +40,6 @@ import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
abstract class ConnectionPool<T extends RedisConnection> {
@ -58,8 +59,8 @@ abstract class ConnectionPool<T extends RedisConnection> {
this.connectionManager = connectionManager;
}
public Future<Void> add(final ClientConnectionsEntry entry) {
final Promise<Void> promise = connectionManager.newPromise();
public RFuture<Void> add(final ClientConnectionsEntry entry) {
final RPromise<Void> promise = connectionManager.newPromise();
promise.addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
@ -70,7 +71,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
return promise;
}
private void initConnections(final ClientConnectionsEntry entry, final Promise<Void> initPromise, boolean checkFreezed) {
private void initConnections(final ClientConnectionsEntry entry, final RPromise<Void> initPromise, boolean checkFreezed) {
final int minimumIdleSize = getMinimumIdleSize(entry);
if (minimumIdleSize == 0 || (checkFreezed && entry.isFreezed())) {
@ -86,7 +87,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
}
}
private void createConnection(final boolean checkFreezed, final AtomicInteger requests, final ClientConnectionsEntry entry, final Promise<Void> initPromise,
private void createConnection(final boolean checkFreezed, final AtomicInteger requests, final ClientConnectionsEntry entry, final RPromise<Void> initPromise,
final int minimumIdleSize, final AtomicInteger initializedConnections) {
if ((checkFreezed && entry.isFreezed()) || !tryAcquireConnection(entry)) {
@ -97,7 +98,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
return;
}
Future<T> promise = createConnection(entry);
RFuture<T> promise = createConnection(entry);
promise.addListener(new FutureListener<T>() {
@Override
public void operationComplete(Future<T> future) throws Exception {
@ -135,7 +136,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
return config.getLoadBalancer().getEntry(entries);
}
public Future<T> get() {
public RFuture<T> get() {
for (int j = entries.size() - 1; j >= 0; j--) {
ClientConnectionsEntry entry = getEntry();
if (!entry.isFreezed() && tryAcquireConnection(entry)) {
@ -165,7 +166,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
return connectionManager.newFailedFuture(exception);
}
public Future<T> get(ClientConnectionsEntry entry) {
public RFuture<T> get(ClientConnectionsEntry entry) {
if (((entry.getNodeType() == NodeType.MASTER && entry.getFreezeReason() == FreezeReason.SYSTEM) || !entry.isFreezed())
&& tryAcquireConnection(entry)) {
return connectTo(entry);
@ -184,11 +185,11 @@ abstract class ConnectionPool<T extends RedisConnection> {
return (T) entry.pollConnection();
}
protected Future<T> connect(ClientConnectionsEntry entry) {
return (Future<T>) entry.connect();
protected RFuture<T> connect(ClientConnectionsEntry entry) {
return (RFuture<T>) entry.connect();
}
private Future<T> connectTo(ClientConnectionsEntry entry) {
private RFuture<T> connectTo(ClientConnectionsEntry entry) {
T conn = poll(entry);
if (conn != null) {
if (!conn.isActive()) {
@ -201,9 +202,9 @@ abstract class ConnectionPool<T extends RedisConnection> {
return createConnection(entry);
}
private Future<T> createConnection(final ClientConnectionsEntry entry) {
final Promise<T> promise = connectionManager.newPromise();
Future<T> connFuture = connect(entry);
private RFuture<T> createConnection(final ClientConnectionsEntry entry) {
final RPromise<T> promise = connectionManager.newPromise();
RFuture<T> connFuture = connect(entry);
connFuture.addListener(new FutureListener<T>() {
@Override
public void operationComplete(Future<T> future) throws Exception {
@ -226,7 +227,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
return promise;
}
private void promiseSuccessful(ClientConnectionsEntry entry, Promise<T> promise, T conn) {
private void promiseSuccessful(ClientConnectionsEntry entry, RPromise<T> promise, T conn) {
entry.resetFailedAttempts();
if (!promise.trySuccess(conn)) {
releaseConnection(entry, conn);
@ -234,12 +235,12 @@ abstract class ConnectionPool<T extends RedisConnection> {
}
}
private Future<T> promiseSuccessful(ClientConnectionsEntry entry, T conn) {
private RFuture<T> promiseSuccessful(ClientConnectionsEntry entry, T conn) {
entry.resetFailedAttempts();
return (Future<T>) conn.getAcquireFuture();
return (RFuture<T>) conn.getAcquireFuture();
}
private void promiseFailure(ClientConnectionsEntry entry, Promise<T> promise, Throwable cause) {
private void promiseFailure(ClientConnectionsEntry entry, RPromise<T> promise, Throwable cause) {
if (entry.incFailedAttempts() == config.getFailedAttempts()) {
checkForReconnect(entry);
}
@ -247,7 +248,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
promise.tryFailure(cause);
}
private void promiseFailure(ClientConnectionsEntry entry, Promise<T> promise, T conn) {
private void promiseFailure(ClientConnectionsEntry entry, RPromise<T> promise, T conn) {
int attempts = entry.incFailedAttempts();
if (attempts == config.getFailedAttempts()) {
checkForReconnect(entry);
@ -261,7 +262,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
promise.tryFailure(cause);
}
private Future<T> promiseFailure(ClientConnectionsEntry entry, T conn) {
private RFuture<T> promiseFailure(ClientConnectionsEntry entry, T conn) {
int attempts = entry.incFailedAttempts();
if (attempts == config.getFailedAttempts()) {
checkForReconnect(entry);
@ -301,7 +302,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
return;
}
Future<RedisConnection> connectionFuture = entry.getClient().connectAsync();
RFuture<RedisConnection> connectionFuture = entry.getClient().connectAsync();
connectionFuture.addListener(new FutureListener<RedisConnection>() {
@Override
public void operationComplete(Future<RedisConnection> future) throws Exception {
@ -332,7 +333,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
if (future.isSuccess() && "PONG".equals(future.getNow())) {
entry.resetFailedAttempts();
Promise<Void> promise = connectionManager.newPromise();
RPromise<Void> promise = connectionManager.newPromise();
promise.addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future)
@ -362,7 +363,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
};
if (entry.getConfig().getPassword() != null) {
Future<Void> temp = c.async(RedisCommands.AUTH, config.getPassword());
RFuture<Void> temp = c.async(RedisCommands.AUTH, config.getPassword());
FutureListener<Void> listener = new FutureListener<Void> () {
@Override public void operationComplete (Future < Void > future)throws Exception {
@ -381,7 +382,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
}
private void ping(RedisConnection c, final FutureListener<String> pingListener) {
Future<String> f = c.async(RedisCommands.PING);
RFuture<String> f = c.async(RedisCommands.PING);
f.addListener(pingListener);
}

@ -15,13 +15,12 @@
*/
package org.redisson.connection.pool;
import org.redisson.api.RFuture;
import org.redisson.client.RedisPubSubConnection;
import org.redisson.config.MasterSlaveServersConfig;
import org.redisson.connection.ClientConnectionsEntry;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.MasterSlaveEntry;
import org.redisson.connection.ClientConnectionsEntry;
import io.netty.util.concurrent.Future;
public class PubSubConnectionPool extends ConnectionPool<RedisPubSubConnection> {
@ -40,7 +39,7 @@ public class PubSubConnectionPool extends ConnectionPool<RedisPubSubConnection>
}
@Override
protected Future<RedisPubSubConnection> connect(ClientConnectionsEntry entry) {
protected RFuture<RedisPubSubConnection> connect(ClientConnectionsEntry entry) {
return entry.connectPubSub();
}

@ -26,11 +26,11 @@ import org.redisson.client.codec.Codec;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandExecutor;
import org.redisson.misc.RPromise;
import org.redisson.remote.RemoteServiceRequest;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
/**
*
@ -60,10 +60,10 @@ public class ExecutorRemoteService extends BaseRemoteService {
}
@Override
protected final Future<Boolean> addAsync(RBlockingQueue<RemoteServiceRequest> requestQueue,
protected final RFuture<Boolean> addAsync(RBlockingQueue<RemoteServiceRequest> requestQueue,
RemoteServiceRequest request, RemotePromise<Object> result) {
final Promise<Boolean> promise = commandExecutor.getConnectionManager().newPromise();
Future<Boolean> future = addAsync(requestQueue, request);
final RPromise<Boolean> promise = commandExecutor.getConnectionManager().newPromise();
RFuture<Boolean> future = addAsync(requestQueue, request);
result.setAddFuture(future);
future.addListener(new FutureListener<Boolean>() {

@ -19,7 +19,7 @@ import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
import org.redisson.api.RScheduledFuture;
import org.redisson.misc.RedissonFuture;
import org.redisson.misc.PromiseDelegator;
/**
*
@ -27,7 +27,7 @@ import org.redisson.misc.RedissonFuture;
*
* @param <V>
*/
public class RedissonScheduledFuture<V> extends RedissonFuture<V> implements RScheduledFuture<V> {
public class RedissonScheduledFuture<V> extends PromiseDelegator<V> implements RScheduledFuture<V> {
private final long scheduledExecutionTime;
private final String taskId;

@ -15,10 +15,9 @@
*/
package org.redisson.executor;
import org.redisson.api.RFuture;
import org.redisson.misc.PromiseDelegator;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise;
import org.redisson.misc.RPromise;
/**
*
@ -28,9 +27,9 @@ import io.netty.util.concurrent.Promise;
public class RemotePromise<T> extends PromiseDelegator<T> {
private String requestId;
private Future<Boolean> addFuture;
private RFuture<Boolean> addFuture;
public RemotePromise(Promise<T> promise) {
public RemotePromise(RPromise<T> promise) {
super(promise);
}
@ -41,10 +40,10 @@ public class RemotePromise<T> extends PromiseDelegator<T> {
return requestId;
}
public void setAddFuture(Future<Boolean> addFuture) {
public void setAddFuture(RFuture<Boolean> addFuture) {
this.addFuture = addFuture;
}
public Future<Boolean> getAddFuture() {
public RFuture<Boolean> getAddFuture() {
return addFuture;
}

@ -19,24 +19,23 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
public class PromiseDelegator<T> implements RPromise<T> {
private final Promise<T> promise;
private final RPromise<T> promise;
public PromiseDelegator(Promise<T> promise) {
public PromiseDelegator(RPromise<T> promise) {
super();
this.promise = promise;
}
public Promise<T> getInnerPromise() {
public RPromise<T> getInnerPromise() {
return promise;
}
public Promise<T> setSuccess(T result) {
public RPromise<T> setSuccess(T result) {
return promise.setSuccess(result);
}
@ -68,35 +67,35 @@ public class PromiseDelegator<T> implements RPromise<T> {
return promise.setUncancellable();
}
public Promise<T> addListener(GenericFutureListener<? extends Future<? super T>> listener) {
public RPromise<T> addListener(FutureListener<? super T> listener) {
return promise.addListener(listener);
}
public Promise<T> addListeners(GenericFutureListener<? extends Future<? super T>>... listeners) {
public RPromise<T> addListeners(FutureListener<? super T>... listeners) {
return promise.addListeners(listeners);
}
public Promise<T> removeListener(GenericFutureListener<? extends Future<? super T>> listener) {
public RPromise<T> removeListener(FutureListener<? super T> listener) {
return promise.removeListener(listener);
}
public Promise<T> removeListeners(GenericFutureListener<? extends Future<? super T>>... listeners) {
public RPromise<T> removeListeners(FutureListener<? super T>... listeners) {
return promise.removeListeners(listeners);
}
public Promise<T> await() throws InterruptedException {
public RPromise<T> await() throws InterruptedException {
return promise.await();
}
public Promise<T> awaitUninterruptibly() {
public RPromise<T> awaitUninterruptibly() {
return promise.awaitUninterruptibly();
}
public Promise<T> sync() throws InterruptedException {
public RPromise<T> sync() throws InterruptedException {
return promise.sync();
}
public Promise<T> syncUninterruptibly() {
public RPromise<T> syncUninterruptibly() {
return promise.syncUninterruptibly();
}

@ -17,6 +17,7 @@ package org.redisson.misc;
import org.redisson.api.RFuture;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
/**
@ -25,6 +26,74 @@ import io.netty.util.concurrent.Promise;
*
* @param <T>
*/
public interface RPromise<T> extends Promise<T>, RFuture<T> {
public interface RPromise<T> extends RFuture<T> {
/**
* Marks this future as a success and notifies all
* listeners.
*
* If it is success or failed already it will throw an {@link IllegalStateException}.
*/
RPromise<T> setSuccess(T result);
/**
* Marks this future as a success and notifies all
* listeners.
*
* @return {@code true} if and only if successfully marked this future as
* a success. Otherwise {@code false} because this future is
* already marked as either a success or a failure.
*/
boolean trySuccess(T result);
/**
* Marks this future as a failure and notifies all
* listeners.
*
* If it is success or failed already it will throw an {@link IllegalStateException}.
*/
Promise<T> setFailure(Throwable cause);
/**
* Marks this future as a failure and notifies all
* listeners.
*
* @return {@code true} if and only if successfully marked this future as
* a failure. Otherwise {@code false} because this future is
* already marked as either a success or a failure.
*/
boolean tryFailure(Throwable cause);
/**
* Make this future impossible to cancel.
*
* @return {@code true} if and only if successfully marked this future as uncancellable or it is already done
* without being cancelled. {@code false} if this future has been cancelled already.
*/
boolean setUncancellable();
@Override
RPromise<T> addListener(FutureListener<? super T> listener);
@Override
RPromise<T> addListeners(FutureListener<? super T>... listeners);
@Override
RPromise<T> removeListener(FutureListener<? super T> listener);
@Override
RPromise<T> removeListeners(FutureListener<? super T>... listeners);
@Override
RPromise<T> await() throws InterruptedException;
@Override
RPromise<T> awaitUninterruptibly();
@Override
RPromise<T> sync() throws InterruptedException;
@Override
RPromise<T> syncUninterruptibly();
}

@ -22,7 +22,7 @@ import java.util.concurrent.TimeoutException;
import org.redisson.api.RFuture;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.FutureListener;
/**
*
@ -55,36 +55,44 @@ public class RedissonFuture<T> implements RFuture<T> {
return future.cause();
}
public Future<T> addListener(GenericFutureListener<? extends Future<? super T>> listener) {
return future.addListener(listener);
public RFuture<T> addListener(FutureListener<? super T> listener) {
future.addListener(listener);
return this;
}
public Future<T> addListeners(GenericFutureListener<? extends Future<? super T>>... listeners) {
return future.addListeners(listeners);
public RFuture<T> addListeners(FutureListener<? super T>... listeners) {
future.addListeners(listeners);
return this;
}
public Future<T> removeListener(GenericFutureListener<? extends Future<? super T>> listener) {
return future.removeListener(listener);
public RFuture<T> removeListener(FutureListener<? super T> listener) {
future.removeListener(listener);
return this;
}
public Future<T> removeListeners(GenericFutureListener<? extends Future<? super T>>... listeners) {
return future.removeListeners(listeners);
public RFuture<T> removeListeners(FutureListener<? super T>... listeners) {
future.removeListeners(listeners);
return this;
}
public Future<T> sync() throws InterruptedException {
return future.sync();
public RFuture<T> sync() throws InterruptedException {
future.sync();
return this;
}
public Future<T> syncUninterruptibly() {
return future.syncUninterruptibly();
public RFuture<T> syncUninterruptibly() {
future.syncUninterruptibly();
return this;
}
public Future<T> await() throws InterruptedException {
return future.await();
public RFuture<T> await() throws InterruptedException {
future.await();
return this;
}
public Future<T> awaitUninterruptibly() {
return future.awaitUninterruptibly();
public RFuture<T> awaitUninterruptibly() {
future.awaitUninterruptibly();
return this;
}
public boolean await(long timeout, TimeUnit unit) throws InterruptedException {

@ -15,6 +15,11 @@
*/
package org.redisson.misc;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
/**
@ -23,10 +28,155 @@ import io.netty.util.concurrent.Promise;
*
* @param <T>
*/
public class RedissonPromise<T> extends PromiseDelegator<T> implements RPromise<T> {
public class RedissonPromise<T> implements RPromise<T> {
private final Promise<T> promise;
public RedissonPromise(Promise<T> promise) {
super(promise);
this.promise = promise;
}
public Promise<T> getInnerPromise() {
return promise;
}
@Override
public RPromise<T> setSuccess(T result) {
promise.setSuccess(result);
return this;
}
@Override
public boolean isSuccess() {
return promise.isSuccess();
}
@Override
public boolean trySuccess(T result) {
return promise.trySuccess(result);
}
@Override
public boolean isCancellable() {
return promise.isCancellable();
}
@Override
public Throwable cause() {
return promise.cause();
}
@Override
public Promise<T> setFailure(Throwable cause) {
return promise.setFailure(cause);
}
@Override
public boolean tryFailure(Throwable cause) {
return promise.tryFailure(cause);
}
@Override
public boolean setUncancellable() {
return promise.setUncancellable();
}
@Override
public RPromise<T> addListener(FutureListener<? super T> listener) {
promise.addListener(listener);
return this;
}
@Override
public RPromise<T> addListeners(FutureListener<? super T>... listeners) {
promise.addListeners(listeners);
return this;
}
@Override
public RPromise<T> removeListener(FutureListener<? super T> listener) {
promise.removeListener(listener);
return this;
}
@Override
public RPromise<T> removeListeners(FutureListener<? super T>... listeners) {
promise.removeListeners(listeners);
return this;
}
@Override
public RPromise<T> await() throws InterruptedException {
promise.await();
return this;
}
@Override
public RPromise<T> awaitUninterruptibly() {
promise.awaitUninterruptibly();
return this;
}
@Override
public RPromise<T> sync() throws InterruptedException {
promise.sync();
return this;
}
@Override
public RPromise<T> syncUninterruptibly() {
promise.syncUninterruptibly();
return this;
}
@Override
public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
return promise.await(timeout, unit);
}
@Override
public boolean isCancelled() {
return promise.isCancelled();
}
@Override
public boolean isDone() {
return promise.isDone();
}
@Override
public boolean await(long timeoutMillis) throws InterruptedException {
return promise.await(timeoutMillis);
}
@Override
public T get() throws InterruptedException, ExecutionException {
return promise.get();
}
@Override
public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
return promise.awaitUninterruptibly(timeout, unit);
}
@Override
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return promise.get(timeout, unit);
}
@Override
public boolean awaitUninterruptibly(long timeoutMillis) {
return promise.awaitUninterruptibly(timeoutMillis);
}
@Override
public T getNow() {
return promise.getNow();
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return promise.cancel(mayInterruptIfRunning);
}
}

@ -17,13 +17,12 @@ package org.redisson.pubsub;
import org.redisson.RedissonCountDownLatch;
import org.redisson.RedissonCountDownLatchEntry;
import io.netty.util.concurrent.Promise;
import org.redisson.misc.RPromise;
public class CountDownLatchPubSub extends PublishSubscribe<RedissonCountDownLatchEntry> {
@Override
protected RedissonCountDownLatchEntry createEntry(Promise<RedissonCountDownLatchEntry> newPromise) {
protected RedissonCountDownLatchEntry createEntry(RPromise<RedissonCountDownLatchEntry> newPromise) {
return new RedissonCountDownLatchEntry(newPromise);
}

@ -16,15 +16,14 @@
package org.redisson.pubsub;
import org.redisson.RedissonLockEntry;
import io.netty.util.concurrent.Promise;
import org.redisson.misc.RPromise;
public class LockPubSub extends PublishSubscribe<RedissonLockEntry> {
public static final Long unlockMessage = 0L;
@Override
protected RedissonLockEntry createEntry(Promise<RedissonLockEntry> newPromise) {
protected RedissonLockEntry createEntry(RPromise<RedissonLockEntry> newPromise) {
return new RedissonLockEntry(newPromise);
}

@ -19,15 +19,15 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicReference;
import org.redisson.PubSubEntry;
import org.redisson.api.RFuture;
import org.redisson.client.BaseRedisPubSubListener;
import org.redisson.client.RedisPubSubListener;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.protocol.pubsub.PubSubType;
import org.redisson.connection.ConnectionManager;
import org.redisson.misc.PromiseDelegator;
import org.redisson.misc.RPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise;
import io.netty.util.internal.PlatformDependent;
abstract class PublishSubscribe<E extends PubSubEntry<E>> {
@ -58,10 +58,10 @@ abstract class PublishSubscribe<E extends PubSubEntry<E>> {
return entries.get(entryName);
}
public Future<E> subscribe(final String entryName, final String channelName, final ConnectionManager connectionManager) {
public RFuture<E> subscribe(final String entryName, final String channelName, final ConnectionManager connectionManager) {
final AtomicReference<Runnable> listenerHolder = new AtomicReference<Runnable>();
final AsyncSemaphore semaphore = connectionManager.getSemaphore(channelName);
final Promise<E> newPromise = new PromiseDelegator<E>(connectionManager.<E>newPromise()) {
final RPromise<E> newPromise = new PromiseDelegator<E>(connectionManager.<E>newPromise()) {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return semaphore.remove(listenerHolder.get());
@ -101,7 +101,7 @@ abstract class PublishSubscribe<E extends PubSubEntry<E>> {
return newPromise;
}
protected abstract E createEntry(Promise<E> newPromise);
protected abstract E createEntry(RPromise<E> newPromise);
protected abstract void onMessage(E value, Long message);

@ -16,13 +16,12 @@
package org.redisson.pubsub;
import org.redisson.RedissonLockEntry;
import io.netty.util.concurrent.Promise;
import org.redisson.misc.RPromise;
public class SemaphorePubSub extends PublishSubscribe<RedissonLockEntry> {
@Override
protected RedissonLockEntry createEntry(Promise<RedissonLockEntry> newPromise) {
protected RedissonLockEntry createEntry(RPromise<RedissonLockEntry> newPromise) {
return new RedissonLockEntry(newPromise);
}

@ -15,9 +15,10 @@
*/
package org.redisson.pubsub;
import org.redisson.misc.RPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
/**
*
@ -27,9 +28,9 @@ import io.netty.util.concurrent.Promise;
*/
public class TransferListener<T> implements FutureListener<T> {
private Promise<T> promise;
private RPromise<T> promise;
public TransferListener(Promise<T> promise) {
public TransferListener(RPromise<T> promise) {
super();
this.promise = promise;
}

@ -16,6 +16,7 @@
package org.redisson.reactive;
import org.reactivestreams.Subscriber;
import org.redisson.api.RFuture;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
@ -26,9 +27,9 @@ import reactor.rx.subscription.ReactiveSubscription;
public class NettyFuturePublisher<T> extends Stream<T> {
private final Future<? extends T> that;
private final RFuture<? extends T> that;
public NettyFuturePublisher(Future<? extends T> that) {
public NettyFuturePublisher(RFuture<? extends T> that) {
this.that = that;
}

@ -15,10 +15,8 @@
*/
package org.redisson.reactive;
import static org.redisson.client.protocol.RedisCommands.EVAL_OBJECT;
import static org.redisson.client.protocol.RedisCommands.LINDEX;
import static org.redisson.client.protocol.RedisCommands.LLEN;
import static org.redisson.client.protocol.RedisCommands.LPOP;
import static org.redisson.client.protocol.RedisCommands.LREM_SINGLE;
import static org.redisson.client.protocol.RedisCommands.RPUSH;
@ -36,7 +34,6 @@ import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.RedisCommand.ValueType;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.convertor.Convertor;
import org.redisson.client.protocol.convertor.LongReplayConvertor;
import org.redisson.command.CommandReactiveExecutor;
@ -259,17 +256,7 @@ public class RedissonListReactive<V> extends RedissonExpirableReactive implement
@Override
public Publisher<V> remove(long index) {
if (index == 0) {
return commandExecutor.writeReactive(getName(), codec, LPOP, getName());
}
return commandExecutor.evalWriteReactive(getName(), codec, EVAL_OBJECT,
"local v = redis.call('lindex', KEYS[1], ARGV[1]); " +
"local tail = redis.call('lrange', KEYS[1], ARGV[1]);" +
"redis.call('ltrim', KEYS[1], 0, ARGV[1] - 1);" +
"for i, v in ipairs(tail) do redis.call('rpush', KEYS[1], v) end;" +
"return v",
Collections.<Object>singletonList(getName()), index);
return reactive(instance.removeAsync(index));
}
@Override
@ -277,38 +264,14 @@ public class RedissonListReactive<V> extends RedissonExpirableReactive implement
return reactive(instance.containsAsync(o));
}
private <R> Publisher<R> indexOf(Object o, Convertor<R> convertor) {
return commandExecutor.evalReadReactive(getName(), codec, new RedisCommand<R>("EVAL", convertor, 4),
"local key = KEYS[1] " +
"local obj = ARGV[1] " +
"local items = redis.call('lrange', key, 0, -1) " +
"for i=1,#items do " +
"if items[i] == obj then " +
"return i - 1 " +
"end " +
"end " +
"return -1",
Collections.<Object>singletonList(getName()), o);
}
@Override
public Publisher<Long> indexOf(Object o) {
return indexOf(o, new LongReplayConvertor());
return reactive(instance.indexOfAsync(o, new LongReplayConvertor()));
}
@Override
public Publisher<Long> lastIndexOf(Object o) {
return commandExecutor.evalReadReactive(getName(), codec, new RedisCommand<Integer>("EVAL", 4),
"local key = KEYS[1] " +
"local obj = ARGV[1] " +
"local items = redis.call('lrange', key, 0, -1) " +
"for i = table.getn(items), 0, -1 do " +
"if items[i] == obj then " +
"return i - 1 " +
"end " +
"end " +
"return -1",
Collections.<Object>singletonList(getName()), o);
return reactive(instance.lastIndexOfAsync(o, new LongReplayConvertor()));
}
@Override

@ -16,12 +16,12 @@
package org.redisson.reactive;
import org.reactivestreams.Publisher;
import org.redisson.api.RFuture;
import org.redisson.api.RObjectReactive;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandReactiveExecutor;
import io.netty.util.concurrent.Future;
import reactor.rx.Stream;
import reactor.rx.Streams;
@ -43,7 +43,7 @@ abstract class RedissonObjectReactive implements RObjectReactive {
this.commandExecutor = commandExecutor;
}
public <R> Publisher<R> reactive(Future<R> future) {
public <R> Publisher<R> reactive(RFuture<R> future) {
return commandExecutor.reactive(future);
}

@ -21,6 +21,7 @@ import java.util.List;
import org.reactivestreams.Publisher;
import org.redisson.PubSubPatternMessageListener;
import org.redisson.PubSubPatternStatusListener;
import org.redisson.api.RFuture;
import org.redisson.api.RPatternTopicReactive;
import org.redisson.api.listener.PatternMessageListener;
import org.redisson.api.listener.PatternStatusListener;
@ -28,11 +29,11 @@ import org.redisson.client.RedisPubSubListener;
import org.redisson.client.codec.Codec;
import org.redisson.command.CommandReactiveExecutor;
import org.redisson.connection.PubSubConnectionEntry;
import org.redisson.misc.RPromise;
import org.redisson.pubsub.AsyncSemaphore;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
/**
* Distributed topic implementation. Messages are delivered to all message listeners across Redis cluster.
@ -59,21 +60,21 @@ public class RedissonPatternTopicReactive<M> implements RPatternTopicReactive<M>
@Override
public Publisher<Integer> addListener(PatternStatusListener listener) {
Promise<Integer> promise = commandExecutor.getConnectionManager().newPromise();
RPromise<Integer> promise = commandExecutor.getConnectionManager().newPromise();
addListener(new PubSubPatternStatusListener(listener, name), promise);
return new NettyFuturePublisher<Integer>(promise);
};
@Override
public Publisher<Integer> addListener(PatternMessageListener<M> listener) {
Promise<Integer> promise = commandExecutor.getConnectionManager().newPromise();
RPromise<Integer> promise = commandExecutor.getConnectionManager().newPromise();
PubSubPatternMessageListener<M> pubSubListener = new PubSubPatternMessageListener<M>(listener, name);
addListener(pubSubListener, promise);
return new NettyFuturePublisher<Integer>(promise);
}
private void addListener(final RedisPubSubListener<M> pubSubListener, final Promise<Integer> promise) {
Future<PubSubConnectionEntry> future = commandExecutor.getConnectionManager().psubscribe(name, codec, pubSubListener);
private void addListener(final RedisPubSubListener<M> pubSubListener, final RPromise<Integer> promise) {
RFuture<PubSubConnectionEntry> future = commandExecutor.getConnectionManager().psubscribe(name, codec, pubSubListener);
future.addListener(new FutureListener<PubSubConnectionEntry>() {
@Override
public void operationComplete(Future<PubSubConnectionEntry> future) throws Exception {

@ -21,6 +21,7 @@ import java.util.List;
import org.reactivestreams.Publisher;
import org.redisson.PubSubMessageListener;
import org.redisson.PubSubStatusListener;
import org.redisson.api.RFuture;
import org.redisson.api.RTopicReactive;
import org.redisson.api.listener.MessageListener;
import org.redisson.api.listener.StatusListener;
@ -29,11 +30,11 @@ import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandReactiveExecutor;
import org.redisson.connection.PubSubConnectionEntry;
import org.redisson.misc.RPromise;
import org.redisson.pubsub.AsyncSemaphore;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
/**
* Distributed topic implementation. Messages are delivered to all message listeners across Redis cluster.
@ -80,8 +81,8 @@ public class RedissonTopicReactive<M> implements RTopicReactive<M> {
}
private Publisher<Integer> addListener(final RedisPubSubListener<?> pubSubListener) {
final Promise<Integer> promise = commandExecutor.getConnectionManager().newPromise();
Future<PubSubConnectionEntry> future = commandExecutor.getConnectionManager().subscribe(codec, name, pubSubListener);
final RPromise<Integer> promise = commandExecutor.getConnectionManager().newPromise();
RFuture<PubSubConnectionEntry> future = commandExecutor.getConnectionManager().subscribe(codec, name, pubSubListener);
future.addListener(new FutureListener<PubSubConnectionEntry>() {
@Override
public void operationComplete(Future<PubSubConnectionEntry> future) throws Exception {

@ -6,6 +6,7 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.redisson.api.RedissonClient;
import org.redisson.codec.MsgPackJacksonCodec;
import org.redisson.config.Config;
public abstract class BaseTest {
@ -24,8 +25,8 @@ public abstract class BaseTest {
@AfterClass
public static void afterClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.shutDownDefaultRedisServerInstance();
defaultRedisson.shutdown();
RedisRunner.shutDownDefaultRedisServerInstance();
}
}

@ -18,6 +18,7 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.redisson.api.RFuture;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisPubSubConnection;
@ -28,10 +29,11 @@ import org.redisson.client.protocol.CommandData;
import org.redisson.client.protocol.CommandsData;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.pubsub.PubSubType;
import org.redisson.misc.RPromise;
import org.redisson.misc.RedissonPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
import io.netty.util.concurrent.ImmediateEventExecutor;
public class RedisClientTest {
@ -66,7 +68,7 @@ public class RedisClientTest {
@Test
public void testConnectAsync() throws InterruptedException {
RedisClient c = new RedisClient("localhost", 6379);
Future<RedisConnection> f = c.connectAsync();
RFuture<RedisConnection> f = c.connectAsync();
final CountDownLatch l = new CountDownLatch(1);
f.addListener((FutureListener<RedisConnection>) future -> {
RedisConnection conn = future.get();
@ -143,7 +145,7 @@ public class RedisClientTest {
CommandData<String, String> cmd4 = conn.create(null, RedisCommands.PING);
commands.add(cmd4);
Promise<Void> p = c.getBootstrap().group().next().newPromise();
RPromise<Void> p = new RedissonPromise<Void>(ImmediateEventExecutor.INSTANCE.newPromise());
conn.send(new CommandsData(p, commands));
assertThat(cmd1.getPromise().get()).isEqualTo("PONG");
@ -180,7 +182,7 @@ public class RedisClientTest {
commands.add(cmd1);
}
Promise<Void> p = c.getBootstrap().group().next().newPromise();
RPromise<Void> p = new RedissonPromise<Void>(ImmediateEventExecutor.INSTANCE.newPromise());
conn.send(new CommandsData(p, commands));
for (CommandData<?, ?> commandData : commands) {

@ -12,14 +12,13 @@ import java.util.concurrent.atomic.AtomicLong;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.api.RBatch;
import org.redisson.api.RFuture;
import org.redisson.api.RListAsync;
import org.redisson.api.RScript;
import org.redisson.api.RScript.Mode;
import org.redisson.client.RedisException;
import org.redisson.client.codec.StringCodec;
import io.netty.util.concurrent.Future;
public class RedissonBatchTest extends BaseTest {
// @Test
@ -56,8 +55,8 @@ public class RedissonBatchTest extends BaseTest {
RBatch b = redisson.createBatch();
b.getMap("test1").putAsync("1", "2");
b.getMap("test2", StringCodec.INSTANCE).putAsync("21", "3");
Future<Object> val1 = b.getMap("test1").getAsync("1");
Future<Object> val2 = b.getMap("test2", StringCodec.INSTANCE).getAsync("21");
RFuture<Object> val1 = b.getMap("test1").getAsync("1");
RFuture<Object> val2 = b.getMap("test2", StringCodec.INSTANCE).getAsync("21");
b.execute();
Assert.assertEquals("2", val1.getNow());
@ -117,7 +116,7 @@ public class RedissonBatchTest extends BaseTest {
ExecutorService e = Executors.newFixedThreadPool(16);
final RBatch batch = redisson.createBatch();
final AtomicLong index = new AtomicLong(-1);
final List<Future<Long>> futures = new CopyOnWriteArrayList<>();
final List<RFuture<Long>> futures = new CopyOnWriteArrayList<>();
for (int i = 0; i < 500; i++) {
futures.add(null);
}
@ -129,7 +128,7 @@ public class RedissonBatchTest extends BaseTest {
synchronized (RedissonBatchTest.this) {
int i = (int) index.incrementAndGet();
int ind = j % 3;
Future<Long> f1 = batch.getAtomicLong("test" + ind).addAndGetAsync(j);
RFuture<Long> f1 = batch.getAtomicLong("test" + ind).addAndGetAsync(j);
futures.set(i, f1);
}
}
@ -141,7 +140,7 @@ public class RedissonBatchTest extends BaseTest {
int i = 0;
for (Object element : s) {
Future<Long> a = futures.get(i);
RFuture<Long> a = futures.get(i);
Assert.assertEquals(a.getNow(), element);
i++;
}

@ -1,5 +1,8 @@
package org.redisson;
import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
@ -19,14 +22,10 @@ import org.junit.Assert;
import org.junit.Test;
import org.redisson.RedisRunner.RedisProcess;
import org.redisson.api.RBlockingQueue;
import org.redisson.api.RFuture;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import io.netty.util.concurrent.Future;
import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
public class RedissonBlockingQueueTest extends BaseTest {
@Test
@ -41,7 +40,7 @@ public class RedissonBlockingQueueTest extends BaseTest {
config.useSingleServer().setAddress("127.0.0.1:6319");
RedissonClient redisson = Redisson.create(config);
final RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("queue:pollTimeout");
Future<Integer> f = queue1.pollAsync(5, TimeUnit.SECONDS);
RFuture<Integer> f = queue1.pollAsync(5, TimeUnit.SECONDS);
Assert.assertFalse(f.await(1, TimeUnit.SECONDS));
runner.stop();
@ -116,7 +115,7 @@ public class RedissonBlockingQueueTest extends BaseTest {
RedissonClient redisson = Redisson.create(config);
RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("queue:pollany");
Future<Integer> f = queue1.pollAsync(10, TimeUnit.SECONDS);
RFuture<Integer> f = queue1.pollAsync(10, TimeUnit.SECONDS);
f.await(1, TimeUnit.SECONDS);
runner.stop();
@ -151,7 +150,7 @@ public class RedissonBlockingQueueTest extends BaseTest {
config.useSingleServer().setAddress("127.0.0.1:6319");
RedissonClient redisson = Redisson.create(config);
RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("testTakeReattach");
Future<Integer> f = queue1.takeAsync();
RFuture<Integer> f = queue1.takeAsync();
f.await(1, TimeUnit.SECONDS);
runner.stop();
@ -181,7 +180,7 @@ public class RedissonBlockingQueueTest extends BaseTest {
RedissonClient redisson = Redisson.create(config);
RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("testTakeAsyncCancel");
for (int i = 0; i < 10; i++) {
Future<Integer> f = queue1.takeAsync();
RFuture<Integer> f = queue1.takeAsync();
f.cancel(true);
}
assertThat(queue1.add(1)).isTrue();
@ -199,7 +198,7 @@ public class RedissonBlockingQueueTest extends BaseTest {
RedissonClient redisson = Redisson.create(config);
RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("queue:pollany");
for (int i = 0; i < 10; i++) {
Future<Integer> f = queue1.pollAsync(1, TimeUnit.SECONDS);
RFuture<Integer> f = queue1.pollAsync(1, TimeUnit.SECONDS);
f.cancel(true);
}
assertThat(queue1.add(1)).isTrue();

@ -23,6 +23,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.redisson.RedisRunner.RedisProcess;
import org.redisson.api.RBoundedBlockingQueue;
import org.redisson.api.RFuture;
import org.redisson.api.RedissonClient;
import org.redisson.client.RedisException;
import org.redisson.config.Config;
@ -229,7 +230,7 @@ public class RedissonBoundedBlockingQueueTest extends BaseTest {
RedissonClient redisson = Redisson.create(config);
final RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("bounded-queue:pollTimeout");
assertThat(queue1.trySetCapacity(5)).isTrue();
Future<Integer> f = queue1.pollAsync(5, TimeUnit.SECONDS);
RFuture<Integer> f = queue1.pollAsync(5, TimeUnit.SECONDS);
Assert.assertFalse(f.await(1, TimeUnit.SECONDS));
runner.stop();
@ -307,7 +308,7 @@ public class RedissonBoundedBlockingQueueTest extends BaseTest {
RedissonClient redisson = Redisson.create(config);
RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("queue:pollany");
Future<Integer> f = queue1.pollAsync(10, TimeUnit.SECONDS);
RFuture<Integer> f = queue1.pollAsync(10, TimeUnit.SECONDS);
f.await(1, TimeUnit.SECONDS);
runner.stop();
@ -346,7 +347,7 @@ public class RedissonBoundedBlockingQueueTest extends BaseTest {
RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("testTakeReattach");
assertThat(queue1.trySetCapacity(15)).isTrue();
Future<Integer> f = queue1.takeAsync();
RFuture<Integer> f = queue1.takeAsync();
f.await(1, TimeUnit.SECONDS);
runner.stop();
@ -380,7 +381,7 @@ public class RedissonBoundedBlockingQueueTest extends BaseTest {
RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("testTakeAsyncCancel");
assertThat(queue1.trySetCapacity(15)).isTrue();
for (int i = 0; i < 10; i++) {
Future<Integer> f = queue1.takeAsync();
RFuture<Integer> f = queue1.takeAsync();
f.cancel(true);
}
assertThat(queue1.add(1)).isTrue();
@ -401,7 +402,7 @@ public class RedissonBoundedBlockingQueueTest extends BaseTest {
RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("queue:pollany");
assertThat(queue1.trySetCapacity(15)).isTrue();
for (int i = 0; i < 10; i++) {
Future<Integer> f = queue1.pollAsync(1, TimeUnit.SECONDS);
RFuture<Integer> f = queue1.pollAsync(1, TimeUnit.SECONDS);
f.cancel(true);
}
assertThat(queue1.add(1)).isTrue();

@ -16,6 +16,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.api.RFuture;
import org.redisson.api.RMapCache;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.MsgPackJacksonCodec;
@ -571,12 +572,12 @@ public class RedissonMapCacheTest extends BaseTest {
@Test
public void testPutAsync() throws InterruptedException, ExecutionException {
RMapCache<Integer, Integer> map = redisson.getMapCache("simple");
Future<Integer> future = map.putAsync(2, 3);
RFuture<Integer> future = map.putAsync(2, 3);
Assert.assertNull(future.get());
Assert.assertEquals((Integer) 3, map.get(2));
Future<Integer> future1 = map.putAsync(2, 4);
RFuture<Integer> future1 = map.putAsync(2, 4);
Assert.assertEquals((Integer) 3, future1.get());
Assert.assertEquals((Integer) 4, map.get(2));

@ -16,14 +16,13 @@ import java.util.concurrent.ExecutionException;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.api.RFuture;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import io.netty.util.concurrent.Future;
public class RedissonMapTest extends BaseTest {
public static class SimpleKey implements Serializable {
@ -596,12 +595,12 @@ public class RedissonMapTest extends BaseTest {
@Test
public void testPutAsync() throws InterruptedException, ExecutionException {
RMap<Integer, Integer> map = redisson.getMap("simple");
Future<Integer> future = map.putAsync(2, 3);
RFuture<Integer> future = map.putAsync(2, 3);
Assert.assertNull(future.get());
Assert.assertEquals((Integer) 3, map.get(2));
Future<Integer> future1 = map.putAsync(2, 4);
RFuture<Integer> future1 = map.putAsync(2, 4);
Assert.assertEquals((Integer) 3, future1.get());
Assert.assertEquals((Integer) 4, map.get(2));

@ -198,7 +198,7 @@ public class RedissonRemoteServiceTest extends BaseTest {
RedissonClient r2 = createInstance();
RemoteInterfaceAsync ri = r2.getRemoteSerivce().get(RemoteInterfaceAsync.class);
Future<Void> f = ri.cancelMethod();
RFuture<Void> f = ri.cancelMethod();
Thread.sleep(500);
assertThat(f.cancel(true)).isTrue();
@ -230,9 +230,9 @@ public class RedissonRemoteServiceTest extends BaseTest {
RedissonClient r2 = createInstance();
RemoteInterfaceAsync ri = r2.getRemoteSerivce().get(RemoteInterfaceAsync.class);
Future<Void> f = ri.voidMethod("someName", 100L);
RFuture<Void> f = ri.voidMethod("someName", 100L);
f.sync();
Future<Long> resFuture = ri.resultMethod(100L);
RFuture<Long> resFuture = ri.resultMethod(100L);
resFuture.sync();
assertThat(resFuture.getNow()).isEqualTo(200);
@ -249,9 +249,9 @@ public class RedissonRemoteServiceTest extends BaseTest {
RedissonClient r2 = createInstance();
RemoteInterfaceAsync ri = r2.getRemoteSerivce().get(RemoteInterfaceAsync.class);
Future<Void> f = ri.voidMethod("someName", 100L);
RFuture<Void> f = ri.voidMethod("someName", 100L);
f.sync();
Future<Long> resFuture = ri.resultMethod(100L);
RFuture<Long> resFuture = ri.resultMethod(100L);
resFuture.sync();
assertThat(resFuture.getNow()).isEqualTo(200);

@ -16,14 +16,13 @@ import java.util.concurrent.ExecutionException;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.redisson.api.RFuture;
import org.redisson.api.RLexSortedSet;
import org.redisson.api.RScoredSortedSet;
import org.redisson.api.RSortedSet;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.ScoredEntry;
import io.netty.util.concurrent.Future;
public class RedissonScoredSortedSetTest extends BaseTest {
@Test
@ -206,9 +205,9 @@ public class RedissonScoredSortedSetTest extends BaseTest {
@Test
public void testAddAsync() throws InterruptedException, ExecutionException {
RScoredSortedSet<Integer> set = redisson.getScoredSortedSet("simple");
Future<Boolean> future = set.addAsync(0.323, 2);
RFuture<Boolean> future = set.addAsync(0.323, 2);
Assert.assertTrue(future.get());
Future<Boolean> future2 = set.addAsync(0.323, 2);
RFuture<Boolean> future2 = set.addAsync(0.323, 2);
Assert.assertFalse(future2.get());
Assert.assertTrue(set.contains(2));

@ -1,13 +1,13 @@
package org.redisson;
import io.netty.util.concurrent.Future;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.*;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.api.RFuture;
import org.redisson.api.RScript;
import org.redisson.api.RScript.Mode;
import org.redisson.client.RedisException;
@ -24,7 +24,7 @@ public class RedissonScriptTest extends BaseTest {
@Test
public void testEvalAsync() {
RScript script = redisson.getScript();
Future<List<Object>> res = script.evalAsync(RScript.Mode.READ_ONLY, "return {1,2,3.3333,'\"foo\"',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList());
RFuture<List<Object>> res = script.evalAsync(RScript.Mode.READ_ONLY, "return {1,2,3.3333,'\"foo\"',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList());
assertThat(res.awaitUninterruptibly().getNow()).containsExactly(1L, 2L, 3L, "foo");
}
@ -73,7 +73,7 @@ public class RedissonScriptTest extends BaseTest {
@Test
public void testScriptLoadAsync() {
redisson.getBucket("foo").set("bar");
Future<String> r = redisson.getScript().scriptLoadAsync("return redis.call('get', 'foo')");
RFuture<String> r = redisson.getScript().scriptLoadAsync("return redis.call('get', 'foo')");
Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", r.awaitUninterruptibly().getNow());
String r1 = redisson.getScript().evalSha(Mode.READ_ONLY, "282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
Assert.assertEquals("bar", r1);
@ -99,7 +99,7 @@ public class RedissonScriptTest extends BaseTest {
redisson.getBucket("foo").set("bar");
String r = redisson.getScript().eval(Mode.READ_ONLY, "return redis.call('get', 'foo')", RScript.ReturnType.VALUE);
Assert.assertEquals("bar", r);
Future<Object> r1 = redisson.getScript().evalShaAsync(Mode.READ_ONLY, "282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
RFuture<Object> r1 = redisson.getScript().evalShaAsync(Mode.READ_ONLY, "282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
Assert.assertEquals("bar", r1.awaitUninterruptibly().getNow());
}

@ -12,10 +12,8 @@ import java.util.concurrent.ExecutionException;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.api.RFuture;
import org.redisson.api.RSet;
import org.redisson.api.RSetCache;
import io.netty.util.concurrent.Future;
public class RedissonSetTest extends BaseTest {
@ -89,7 +87,7 @@ public class RedissonSetTest extends BaseTest {
@Test
public void testAddAsync() throws InterruptedException, ExecutionException {
RSet<Integer> set = redisson.getSet("simple");
Future<Boolean> future = set.addAsync(2);
RFuture<Boolean> future = set.addAsync(2);
Assert.assertTrue(future.get());
Assert.assertTrue(set.contains(2));

@ -1,7 +1,5 @@
package org.redisson;
import io.netty.util.concurrent.Future;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
@ -15,6 +13,7 @@ import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.api.RFuture;
import org.redisson.api.RSortedSet;
public class RedissonSortedSetTest extends BaseTest {
@ -22,7 +21,7 @@ public class RedissonSortedSetTest extends BaseTest {
@Test
public void testAddAsync() throws InterruptedException, ExecutionException {
RSortedSet<Integer> set = redisson.getSortedSet("simple");
Future<Boolean> future = set.addAsync(2);
RFuture<Boolean> future = set.addAsync(2);
Assert.assertTrue(future.get());
Assert.assertTrue(set.contains(2));

@ -1,16 +1,16 @@
package org.redisson;
import io.netty.util.concurrent.Future;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.redisson.api.RFuture;
import org.redisson.api.RMap;
import org.redisson.api.RTopic;
import org.redisson.api.listener.MessageListener;
import io.netty.util.concurrent.Future;
public class TimeoutTest extends BaseTest {
// @Test
@ -59,15 +59,15 @@ public class TimeoutTest extends BaseTest {
// @Test
public void testPutAsyncTimeout() throws InterruptedException, ExecutionException {
RMap<Integer, Integer> map = redisson.getMap("simple");
List<Future<Integer>> futures = new ArrayList<Future<Integer>>();
List<RFuture<Integer>> futures = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
Future<Integer> future = map.putAsync(i, i*1000);
RFuture<Integer> future = map.putAsync(i, i*1000);
Thread.sleep(1000);
futures.add(future);
System.out.println(i);
}
for (Future<Integer> future : futures) {
for (RFuture<Integer> future : futures) {
future.get();
}
@ -80,19 +80,19 @@ public class TimeoutTest extends BaseTest {
// @Test
public void testGetAsyncTimeout() throws InterruptedException, ExecutionException {
RMap<Integer, Integer> map = redisson.getMap("simple");
List<Future<Integer>> futures = new ArrayList<Future<Integer>>();
List<RFuture<Integer>> futures = new ArrayList<>();
for (int i = 0; i < 10; i++) {
map.put(i, i*1000);
}
for (int i = 0; i < 10; i++) {
Future<Integer> future = map.getAsync(i);
RFuture<Integer> future = map.getAsync(i);
Thread.sleep(1000);
System.out.println(i);
futures.add(future);
}
for (Future<Integer> future : futures) {
for (RFuture<Integer> future : futures) {
Integer res = future.get();
System.out.println(res);
}

Loading…
Cancel
Save