diff --git a/redisson/src/main/java/org/redisson/BaseRemoteService.java b/redisson/src/main/java/org/redisson/BaseRemoteService.java index a0fcf2d0a..60eae501d 100644 --- a/redisson/src/main/java/org/redisson/BaseRemoteService.java +++ b/redisson/src/main/java/org/redisson/BaseRemoteService.java @@ -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 future = commandExecutor.evalWriteAsync(responseName, LongCodec.INSTANCE, + RFuture 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 addFuture = addAsync(requestQueue, request, result); + RFuture addFuture = addAsync(requestQueue, request, result); addFuture.addListener(new FutureListener() { @Override @@ -262,7 +262,7 @@ public abstract class BaseRemoteService { if (optionsCopy.isAckExpected()) { final RBlockingQueue responseQueue = redisson.getBlockingQueue(responseName, getCodec()); - Future ackFuture = responseQueue.pollAsync(optionsCopy.getAckTimeoutInMillis(), TimeUnit.MILLISECONDS); + RFuture ackFuture = responseQueue.pollAsync(optionsCopy.getAckTimeoutInMillis(), TimeUnit.MILLISECONDS); ackFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -273,7 +273,7 @@ public abstract class BaseRemoteService { RemoteServiceAck ack = future.getNow(); if (ack == null) { - Future ackFutureAttempt = + RFuture ackFutureAttempt = tryPollAckAgainAsync(optionsCopy, responseQueue, ackName); ackFutureAttempt.addListener(new FutureListener() { @@ -318,7 +318,7 @@ public abstract class BaseRemoteService { private void awaitResultAsync(final RemoteInvocationOptions optionsCopy, final RemotePromise result, final RemoteServiceRequest request, final String responseName, final String ackName) { - Future deleteFuture = redisson.getBucket(ackName).deleteAsync(); + RFuture deleteFuture = redisson.getBucket(ackName).deleteAsync(); deleteFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -340,7 +340,7 @@ public abstract class BaseRemoteService { } RBlockingQueue responseQueue = redisson.getBlockingQueue(responseName, getCodec()); - Future responseFuture = responseQueue + RFuture responseFuture = responseQueue .pollAsync(optionsCopy.getExecutionTimeoutInMillis(), TimeUnit.MILLISECONDS); responseFuture.addListener(new FutureListener() { @@ -448,7 +448,7 @@ public abstract class BaseRemoteService { private RemoteServiceAck tryPollAckAgain(RemoteInvocationOptions optionsCopy, RBlockingQueue responseQueue, String ackName) throws InterruptedException { - Future ackClientsFuture = commandExecutor.evalWriteAsync(ackName, LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, + RFuture 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 tryPollAckAgainAsync(RemoteInvocationOptions optionsCopy, + private RFuture tryPollAckAgainAsync(RemoteInvocationOptions optionsCopy, final RBlockingQueue responseQueue, String ackName) throws InterruptedException { - final Promise promise = commandExecutor.getConnectionManager().newPromise(); - Future ackClientsFuture = commandExecutor.evalWriteAsync(ackName, LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, + final RPromise promise = commandExecutor.getConnectionManager().newPromise(); + RFuture 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 pollFuture = responseQueue.pollAsync(); + RFuture pollFuture = responseQueue.pollAsync(); pollFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -512,9 +512,9 @@ public abstract class BaseRemoteService { return ByteBufUtil.hexDump(id); } - protected Future addAsync(RBlockingQueue requestQueue, RemoteServiceRequest request, + protected RFuture addAsync(RBlockingQueue requestQueue, RemoteServiceRequest request, RemotePromise result) { - Future future = requestQueue.addAsync(request); + RFuture future = requestQueue.addAsync(request); result.setAddFuture(future); return future; } diff --git a/redisson/src/main/java/org/redisson/EvictionScheduler.java b/redisson/src/main/java/org/redisson/EvictionScheduler.java index f72d72cb3..dee26b056 100644 --- a/redisson/src/main/java/org/redisson/EvictionScheduler.java +++ b/redisson/src/main/java/org/redisson/EvictionScheduler.java @@ -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 future = cleanupExpiredEntires(name, timeoutSetName, maxIdleSetName, keysLimit, multimap); + RFuture future = cleanupExpiredEntires(name, timeoutSetName, maxIdleSetName, keysLimit, multimap); future.addListener(new FutureListener() { @Override @@ -169,7 +170,7 @@ public class EvictionScheduler { return; } - Future future = cleanupExpiredEntires(name, timeoutSetName, null, valuesAmountToClean, false); + RFuture future = cleanupExpiredEntires(name, timeoutSetName, null, valuesAmountToClean, false); future.addListener(new FutureListener() { @Override @@ -189,7 +190,7 @@ public class EvictionScheduler { }); } - private Future cleanupExpiredEntires(String name, String timeoutSetName, String maxIdleSetName, int keysLimit, boolean multimap) { + private RFuture 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]); " diff --git a/redisson/src/main/java/org/redisson/PubSubEntry.java b/redisson/src/main/java/org/redisson/PubSubEntry.java index 5685d2a3d..a11915eb1 100644 --- a/redisson/src/main/java/org/redisson/PubSubEntry.java +++ b/redisson/src/main/java/org/redisson/PubSubEntry.java @@ -15,7 +15,7 @@ */ package org.redisson; -import io.netty.util.concurrent.Promise; +import org.redisson.misc.RPromise; public interface PubSubEntry { @@ -23,6 +23,6 @@ public interface PubSubEntry { int release(); - Promise getPromise(); + RPromise getPromise(); } diff --git a/redisson/src/main/java/org/redisson/RedisNodes.java b/redisson/src/main/java/org/redisson/RedisNodes.java index 057790008..c953b66c6 100644 --- a/redisson/src/main/java/org/redisson/RedisNodes.java +++ b/redisson/src/main/java/org/redisson/RedisNodes.java @@ -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 implements NodesGroup { @@ -65,21 +66,21 @@ public class RedisNodes implements NodesGroup { @Override public boolean pingAll() { List clients = new ArrayList(connectionManager.getClients()); - final Map> result = new ConcurrentHashMap>(clients.size()); + final Map> result = new ConcurrentHashMap>(clients.size()); final CountDownLatch latch = new CountDownLatch(clients.size()); for (RedisClientEntry entry : clients) { - Future f = entry.getClient().connectAsync(); + RFuture f = entry.getClient().connectAsync(); f.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { if (future.isSuccess()) { final RedisConnection c = future.getNow(); - Promise connectionFuture = connectionManager.newPromise(); + RPromise connectionFuture = connectionManager.newPromise(); connectionManager.getConnectListener().onConnect(connectionFuture, c, null, connectionManager.getConfig()); connectionFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { - Future r = c.async(connectionManager.getConfig().getPingTimeout(), RedisCommands.PING); + RFuture r = c.async(connectionManager.getConfig().getPingTimeout(), RedisCommands.PING); result.put(c, r); latch.countDown(); } @@ -99,7 +100,7 @@ public class RedisNodes implements NodesGroup { } if (System.currentTimeMillis() - time >= connectionManager.getConfig().getConnectTimeout()) { - for (Entry> entry : result.entrySet()) { + for (Entry> entry : result.entrySet()) { entry.getKey().closeAsync(); } return false; @@ -107,8 +108,8 @@ public class RedisNodes implements NodesGroup { time = System.currentTimeMillis(); boolean res = true; - for (Entry> entry : result.entrySet()) { - Future f = entry.getValue(); + for (Entry> entry : result.entrySet()) { + RFuture f = entry.getValue(); f.awaitUninterruptibly(); if (!"PONG".equals(f.getNow())) { res = false; diff --git a/redisson/src/main/java/org/redisson/RedissonBatch.java b/redisson/src/main/java/org/redisson/RedissonBatch.java index 554e9366b..dbc6698bf 100644 --- a/redisson/src/main/java/org/redisson/RedissonBatch.java +++ b/redisson/src/main/java/org/redisson/RedissonBatch.java @@ -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; - /** * * diff --git a/redisson/src/main/java/org/redisson/RedissonBlockingQueue.java b/redisson/src/main/java/org/redisson/RedissonBlockingQueue.java index 997ea8bf4..a11919f58 100644 --- a/redisson/src/main/java/org/redisson/RedissonBlockingQueue.java +++ b/redisson/src/main/java/org/redisson/RedissonBlockingQueue.java @@ -93,7 +93,7 @@ public class RedissonBlockingQueue extends RedissonQueue implements RBlock */ @Override public V take() throws InterruptedException { - Future res = takeAsync(); + RFuture res = takeAsync(); return res.await().getNow(); } @@ -108,7 +108,7 @@ public class RedissonBlockingQueue extends RedissonQueue implements RBlock */ @Override public V poll(long timeout, TimeUnit unit) throws InterruptedException { - Future res = pollAsync(timeout, unit); + RFuture res = pollAsync(timeout, unit); return res.await().getNow(); } @@ -118,7 +118,7 @@ public class RedissonBlockingQueue extends RedissonQueue implements RBlock */ @Override public V pollFromAny(long timeout, TimeUnit unit, String ... queueNames) throws InterruptedException { - Future res = pollFromAnyAsync(timeout, unit, queueNames); + RFuture res = pollFromAnyAsync(timeout, unit, queueNames); return res.await().getNow(); } @@ -144,7 +144,7 @@ public class RedissonBlockingQueue extends RedissonQueue implements RBlock @Override public V pollLastAndOfferFirstTo(String queueName, long timeout, TimeUnit unit) throws InterruptedException { - Future res = pollLastAndOfferFirstToAsync(queueName, timeout, unit); + RFuture res = pollLastAndOfferFirstToAsync(queueName, timeout, unit); return res.await().getNow(); } diff --git a/redisson/src/main/java/org/redisson/RedissonBloomFilter.java b/redisson/src/main/java/org/redisson/RedissonBloomFilter.java index 430889c7c..7609707e2 100644 --- a/redisson/src/main/java/org/redisson/RedissonBloomFilter.java +++ b/redisson/src/main/java/org/redisson/RedissonBloomFilter.java @@ -178,9 +178,9 @@ public class RedissonBloomFilter extends RedissonExpirable implements RBloomF @Override public int count() { CommandBatchService executorService = new CommandBatchService(commandExecutor.getConnectionManager()); - Future> configFuture = executorService.readAsync(getConfigName(), StringCodec.INSTANCE, + RFuture> configFuture = executorService.readAsync(getConfigName(), StringCodec.INSTANCE, new RedisCommand>("HGETALL", new ObjectMapReplayDecoder()), getConfigName()); - Future cardinalityFuture = executorService.readAsync(getName(), codec, RedisCommands.BITCOUNT, getName()); + RFuture cardinalityFuture = executorService.readAsync(getName(), codec, RedisCommands.BITCOUNT, getName()); executorService.execute(); readConfig(configFuture.getNow()); @@ -194,7 +194,7 @@ public class RedissonBloomFilter extends RedissonExpirable implements RBloomF } private void readConfig() { - Future> future = commandExecutor.readAsync(getConfigName(), StringCodec.INSTANCE, + RFuture> future = commandExecutor.readAsync(getConfigName(), StringCodec.INSTANCE, new RedisCommand>("HGETALL", new ObjectMapReplayDecoder()), getConfigName()); Map config = commandExecutor.get(future); diff --git a/redisson/src/main/java/org/redisson/RedissonBuckets.java b/redisson/src/main/java/org/redisson/RedissonBuckets.java index 492dc0c31..0abe91b5b 100644 --- a/redisson/src/main/java/org/redisson/RedissonBuckets.java +++ b/redisson/src/main/java/org/redisson/RedissonBuckets.java @@ -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> command = new RedisCommand>("MGET", new MapGetAllDecoder(Arrays.asList(keys), 0), ValueType.OBJECTS); - Future> future = commandExecutor.readAsync(keys[0], new DelegateDecoderCodec(codec), command, keys); + RFuture> future = commandExecutor.readAsync(keys[0], new DelegateDecoderCodec(codec), command, keys); return commandExecutor.get(future); } diff --git a/redisson/src/main/java/org/redisson/RedissonCountDownLatch.java b/redisson/src/main/java/org/redisson/RedissonCountDownLatch.java index 6eddbf960..b27c2dfb6 100644 --- a/redisson/src/main/java/org/redisson/RedissonCountDownLatch.java +++ b/redisson/src/main/java/org/redisson/RedissonCountDownLatch.java @@ -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 promise = subscribe(); + RFuture 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 promise = subscribe(); + RFuture 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 subscribe() { + private RFuture subscribe() { return PUBSUB.subscribe(getEntryName(), getChannelName(), commandExecutor.getConnectionManager()); } - private void unsubscribe(Future future) { + private void unsubscribe(RFuture future) { PUBSUB.unsubscribe(future.getNow(), getEntryName(), getChannelName(), commandExecutor.getConnectionManager()); } diff --git a/redisson/src/main/java/org/redisson/RedissonCountDownLatchEntry.java b/redisson/src/main/java/org/redisson/RedissonCountDownLatchEntry.java index 2e16d115f..e0f5be1f8 100644 --- a/redisson/src/main/java/org/redisson/RedissonCountDownLatchEntry.java +++ b/redisson/src/main/java/org/redisson/RedissonCountDownLatchEntry.java @@ -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 { private int counter; private final ReclosableLatch latch; - private final Promise promise; + private final RPromise promise; - public RedissonCountDownLatchEntry(Promise promise) { + public RedissonCountDownLatchEntry(RPromise promise) { super(); this.latch = new ReclosableLatch(); this.promise = promise; @@ -40,7 +39,7 @@ public class RedissonCountDownLatchEntry implements PubSubEntry getPromise() { + public RPromise getPromise() { return promise; } diff --git a/redisson/src/main/java/org/redisson/RedissonExecutorService.java b/redisson/src/main/java/org/redisson/RedissonExecutorService.java index c978c5695..92bda305c 100644 --- a/redisson/src/main/java/org/redisson/RedissonExecutorService.java +++ b/redisson/src/main/java/org/redisson/RedissonExecutorService.java @@ -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 void execute(RemotePromise promise) { - io.netty.util.concurrent.Future addFuture = promise.getAddFuture(); + RFuture addFuture = promise.getAddFuture(); addFuture.syncUninterruptibly(); Boolean res = addFuture.getNow(); if (!res) { @@ -451,9 +450,9 @@ public class RedissonExecutorService implements RScheduledExecutorService { } @Override - public Future submit(Runnable task, final T result) { - final Promise resultFuture = connectionManager.newPromise(); - io.netty.util.concurrent.Future future = (io.netty.util.concurrent.Future) submit(task); + public RFuture submit(Runnable task, final T result) { + final RPromise resultFuture = connectionManager.newPromise(); + RFuture future = (RFuture) submit(task); future.addListener(new FutureListener() { @Override public void operationComplete(io.netty.util.concurrent.Future 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 ScheduledFuture schedule(Callable task, long delay, TimeUnit unit) { RedissonScheduledFuture future = (RedissonScheduledFuture) scheduleAsync(task, delay, unit); - execute((RemotePromise)future.getInnerFuture()); + execute((RemotePromise)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 cancelledFuture = connectionManager.newPromise(); + RPromise cancelledFuture = connectionManager.newPromise(); cancelledFuture.cancel(true); futures.add(cancelledFuture); diff --git a/redisson/src/main/java/org/redisson/RedissonFairLock.java b/redisson/src/main/java/org/redisson/RedissonFairLock.java index 824deb5a7..14e23e2b7 100644 --- a/redisson/src/main/java/org/redisson/RedissonFairLock.java +++ b/redisson/src/main/java/org/redisson/RedissonFairLock.java @@ -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.
@@ -63,13 +61,13 @@ public class RedissonFairLock extends RedissonLock implements RLock { } @Override - protected Future subscribe(long threadId) { + protected RFuture subscribe(long threadId) { return PUBSUB.subscribe(getEntryName() + ":" + threadId, getChannelName() + ":" + getLockName(threadId), commandExecutor.getConnectionManager()); } @Override - protected void unsubscribe(Future future, long threadId) { + protected void unsubscribe(RFuture future, long threadId) { PUBSUB.unsubscribe(future.getNow(), getEntryName() + ":" + threadId, getChannelName() + ":" + getLockName(threadId), commandExecutor.getConnectionManager()); } diff --git a/redisson/src/main/java/org/redisson/RedissonKeys.java b/redisson/src/main/java/org/redisson/RedissonKeys.java index e726deffc..f19108910 100644 --- a/redisson/src/main/java/org/redisson/RedissonKeys.java +++ b/redisson/src/main/java/org/redisson/RedissonKeys.java @@ -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> future = executorService.executeAsync(); + RFuture> 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 result, final AtomicReference failed, + private void checkExecution(final RPromise result, final AtomicReference failed, final AtomicLong count, final AtomicLong executed) { if (executed.decrementAndGet() == 0) { if (failed.get() != null) { diff --git a/redisson/src/main/java/org/redisson/RedissonList.java b/redisson/src/main/java/org/redisson/RedissonList.java index af1f3a911..6020d77bf 100644 --- a/redisson/src/main/java/org/redisson/RedissonList.java +++ b/redisson/src/main/java/org/redisson/RedissonList.java @@ -339,19 +339,26 @@ public class RedissonList extends RedissonExpirable implements RList { @Override public V remove(int index) { + return remove((long) index); + } + + public V remove(long index) { + return get(removeAsync(index)); + } + + public RFuture removeAsync(long index) { if (index == 0) { - RFuture f = commandExecutor.writeAsync(getName(), codec, LPOP, getName()); - return get(f); + return commandExecutor.writeAsync(getName(), codec, LPOP, getName()); } - RFuture 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.singletonList(getName()), index); - return get(f); } + @Override public void fastRemove(int index) { @@ -359,7 +366,7 @@ public class RedissonList extends RedissonExpirable implements RList { } @Override - public RFuture fastRemoveAsync(int index) { + public RFuture 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 extends RedissonExpirable implements RList { return indexOfAsync(o, new BooleanNumberReplayConvertor(-1L)); } - private RFuture indexOfAsync(Object o, Convertor convertor) { + public RFuture indexOfAsync(Object o, Convertor convertor) { return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand("EVAL", convertor, 4), "local key = KEYS[1] " + "local obj = ARGV[1] " + @@ -414,6 +421,20 @@ public class RedissonList extends RedissonExpirable implements RList { "return -1", Collections.singletonList(getName()), o); } + + public RFuture lastIndexOfAsync(Object o, Convertor convertor) { + return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand("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.singletonList(getName()), o); + } @Override public void trim(int fromIndex, int toIndex) { @@ -421,7 +442,7 @@ public class RedissonList extends RedissonExpirable implements RList { } @Override - public RFuture trimAsync(int fromIndex, int toIndex) { + public RFuture trimAsync(long fromIndex, long toIndex) { return commandExecutor.writeAsync(getName(), codec, RedisCommands.LTRIM, getName(), fromIndex, toIndex); } diff --git a/redisson/src/main/java/org/redisson/RedissonListMultimapValues.java b/redisson/src/main/java/org/redisson/RedissonListMultimapValues.java index a84e1a197..1a43bba4d 100644 --- a/redisson/src/main/java/org/redisson/RedissonListMultimapValues.java +++ b/redisson/src/main/java/org/redisson/RedissonListMultimapValues.java @@ -432,27 +432,30 @@ public class RedissonListMultimapValues extends RedissonExpirable implements @Override public V remove(int index) { + return get(removeAsync(index)); + } + + @Override + public RFuture removeAsync(long index) { if (index == 0) { - RFuture f = commandExecutor.writeAsync(getName(), codec, LPOP, getName()); - return get(f); + return commandExecutor.writeAsync(getName(), codec, LPOP, getName()); } - RFuture 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.singletonList(getName()), index); - return get(f); } @Override public void fastRemove(int index) { - get(fastRemoveAsync(index)); + get(fastRemoveAsync((long)index)); } @Override - public RFuture fastRemoveAsync(int index) { + public RFuture 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 extends RedissonExpirable implements } @Override - public RFuture trimAsync(int fromIndex, int toIndex) { + public RFuture trimAsync(long fromIndex, long toIndex) { return commandExecutor.writeAsync(getName(), codec, RedisCommands.LTRIM, getName(), fromIndex, toIndex); } diff --git a/redisson/src/main/java/org/redisson/RedissonLock.java b/redisson/src/main/java/org/redisson/RedissonLock.java index 35b9badbd..48178e5b1 100644 --- a/redisson/src/main/java/org/redisson/RedissonLock.java +++ b/redisson/src/main/java/org/redisson/RedissonLock.java @@ -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 future = subscribe(threadId); + RFuture future = subscribe(threadId); get(future); try { @@ -171,11 +170,11 @@ public class RedissonLock extends RedissonExpirable implements RLock { return ttlRemainingFuture; } - private Future tryAcquireAsync(long leaseTime, TimeUnit unit, long threadId) { + private RFuture tryAcquireAsync(long leaseTime, TimeUnit unit, long threadId) { if (leaseTime != -1) { return tryLockInnerAsync(leaseTime, unit, threadId, RedisCommands.EVAL_LONG); } - Future ttlRemainingFuture = tryLockInnerAsync(LOCK_EXPIRATION_INTERVAL_SECONDS, TimeUnit.SECONDS, threadId, RedisCommands.EVAL_LONG); + RFuture ttlRemainingFuture = tryLockInnerAsync(LOCK_EXPIRATION_INTERVAL_SECONDS, TimeUnit.SECONDS, threadId, RedisCommands.EVAL_LONG); ttlRemainingFuture.addListener(new FutureListener() { @Override public void operationComplete(Future 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 future = expireAsync(internalLockLeaseTime, TimeUnit.MILLISECONDS); + RFuture future = expireAsync(internalLockLeaseTime, TimeUnit.MILLISECONDS); future.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -265,14 +264,14 @@ public class RedissonLock extends RedissonExpirable implements RLock { } final long threadId = Thread.currentThread().getId(); - Future future = subscribe(threadId); - if (!await(future, time, TimeUnit.MILLISECONDS)) { - if (!future.cancel(false)) { - future.addListener(new FutureListener() { + final RFuture subscribeFuture = subscribe(threadId); + if (!await(subscribeFuture, time, TimeUnit.MILLISECONDS)) { + if (!subscribeFuture.cancel(false)) { + subscribeFuture.addListener(new FutureListener() { @Override public void operationComplete(Future 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 subscribe(long threadId) { + protected RFuture subscribe(long threadId) { return PUBSUB.subscribe(getEntryName(), getChannelName(), commandExecutor.getConnectionManager()); } - protected void unsubscribe(Future future, long threadId) { + protected void unsubscribe(RFuture future, long threadId) { PUBSUB.unsubscribe(future.getNow(), getEntryName(), getChannelName(), commandExecutor.getConnectionManager()); } @@ -421,7 +420,7 @@ public class RedissonLock extends RedissonExpirable implements RLock { public RFuture unlockAsync(final long threadId) { final RPromise result = newPromise(); - Future future = commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, + RFuture 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 lockAsync(final long leaseTime, final TimeUnit unit, final long currentThreadId) { final RPromise result = newPromise(); - Future ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId); + RFuture ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId); ttlFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -494,7 +493,7 @@ public class RedissonLock extends RedissonExpirable implements RLock { return; } - final Future subscribeFuture = subscribe(currentThreadId); + final RFuture subscribeFuture = subscribe(currentThreadId); subscribeFuture.addListener(new FutureListener() { @Override public void operationComplete(Future 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 subscribeFuture, final Promise result, final long currentThreadId) { - Future ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId); + final RFuture subscribeFuture, final RPromise result, final long currentThreadId) { + RFuture ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId); ttlFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -596,7 +595,7 @@ public class RedissonLock extends RedissonExpirable implements RLock { final RPromise result = newPromise(); final AtomicLong time = new AtomicLong(unit.toMillis(waitTime)); - Future ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId); + RFuture ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId); ttlFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -615,7 +614,7 @@ public class RedissonLock extends RedissonExpirable implements RLock { final long current = System.currentTimeMillis(); final AtomicReference futureRef = new AtomicReference(); - final Future subscribeFuture = subscribe(currentThreadId); + final RFuture subscribeFuture = subscribe(currentThreadId); subscribeFuture.addListener(new FutureListener() { @Override public void operationComplete(Future 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 subscribeFuture, final Promise result, final long currentThreadId) { - Future ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId); + final RFuture subscribeFuture, final RPromise result, final long currentThreadId) { + RFuture ttlFuture = tryAcquireAsync(leaseTime, unit, currentThreadId); ttlFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { diff --git a/redisson/src/main/java/org/redisson/RedissonLockEntry.java b/redisson/src/main/java/org/redisson/RedissonLockEntry.java index 0535dd2d5..ce563d714 100644 --- a/redisson/src/main/java/org/redisson/RedissonLockEntry.java +++ b/redisson/src/main/java/org/redisson/RedissonLockEntry.java @@ -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 { private int counter; private final Semaphore latch; - private final Promise promise; + private final RPromise promise; private final ConcurrentLinkedQueue listeners = new ConcurrentLinkedQueue(); - public RedissonLockEntry(Promise promise) { + public RedissonLockEntry(RPromise promise) { super(); this.latch = new Semaphore(0); this.promise = promise; @@ -42,7 +44,7 @@ public class RedissonLockEntry implements PubSubEntry { return --counter; } - public Promise getPromise() { + public RPromise getPromise() { return promise; } diff --git a/redisson/src/main/java/org/redisson/RedissonMapCache.java b/redisson/src/main/java/org/redisson/RedissonMapCache.java index 9148fe3ff..9d644b789 100644 --- a/redisson/src/main/java/org/redisson/RedissonMapCache.java +++ b/redisson/src/main/java/org/redisson/RedissonMapCache.java @@ -534,7 +534,7 @@ public class RedissonMapCache extends RedissonMap implements RMapCac MapScanResult scanIterator(String name, InetSocketAddress client, long startPos) { RedisCommand> EVAL_HSCAN = new RedisCommand>("EVAL", new ListMultiDecoder(new LongMultiDecoder(), new ObjectMapDecoder(new ScanCodec(codec)), new ObjectListDecoder(codec), new MapCacheScanResultReplayDecoder()), ValueType.MAP); - Future> f = commandExecutor.evalReadAsync(client, getName(), codec, EVAL_HSCAN, + RFuture> f = commandExecutor.evalReadAsync(client, getName(), codec, EVAL_HSCAN, "local result = {}; " + "local idleKeys = {}; " + "local res = redis.call('hscan', KEYS[1], ARGV[2]); " diff --git a/redisson/src/main/java/org/redisson/RedissonMultiLock.java b/redisson/src/main/java/org/redisson/RedissonMultiLock.java index fdd6f9f6d..517d155ab 100644 --- a/redisson/src/main/java/org/redisson/RedissonMultiLock.java +++ b/redisson/src/main/java/org/redisson/RedissonMultiLock.java @@ -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 promise = ImmediateEventExecutor.INSTANCE.newPromise(); + RPromise promise = new RedissonPromise(ImmediateEventExecutor.INSTANCE.newPromise()); long currentThreadId = Thread.currentThread().getId(); Queue lockedLocks = new ConcurrentLinkedQueue(); @@ -94,7 +95,7 @@ public class RedissonMultiLock implements Lock { lockInterruptibly(-1, null); } - private void lock(final Promise promise, final long waitTime, final long leaseTime, final TimeUnit unit, + private void lock(final RPromise promise, final long waitTime, final long leaseTime, final TimeUnit unit, final List locks, final long currentThreadId, final Queue lockedLocks) throws InterruptedException { final AtomicInteger tryLockRequestsAmount = new AtomicInteger(); final Map, RLock> tryLockFutures = new HashMap, RLock>(locks.size()); @@ -145,7 +146,7 @@ public class RedissonMultiLock implements Lock { } } - protected void tryLockAgain(final Promise promise, final long waitTime, final long leaseTime, + protected void tryLockAgain(final RPromise promise, final long waitTime, final long leaseTime, final TimeUnit unit, final long currentThreadId, final Map, RLock> tryLockFutures) throws InterruptedException { lockedLocks.clear(); if (failed.get() != null) { @@ -176,9 +177,9 @@ public class RedissonMultiLock implements Lock { tryLockRequestsAmount.incrementAndGet(); Future 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> tryLockFutures = new HashMap>(locks.size()); + Map> tryLockFutures = new HashMap>(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> tryLockFutures) { + protected boolean sync(Map> tryLockFutures) { List lockedLocks = new ArrayList(tryLockFutures.size()); RuntimeException latestException = null; - for (Entry> entry : tryLockFutures.entrySet()) { + for (Entry> 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 locks) { - List> futures = new ArrayList>(locks.size()); + List> futures = new ArrayList>(locks.size()); for (RLock lock : locks) { futures.add(lock.unlockAsync()); } - for (Future unlockFuture : futures) { + for (RFuture 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> tryLockFutures = new HashMap>(locks.size()); + Map> tryLockFutures = new HashMap>(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> futures = new ArrayList>(locks.size()); + List> futures = new ArrayList>(locks.size()); for (RLock lock : locks) { futures.add(lock.unlockAsync()); } - for (Future future : futures) { + for (RFuture future : futures) { future.syncUninterruptibly(); } } diff --git a/redisson/src/main/java/org/redisson/RedissonMultimap.java b/redisson/src/main/java/org/redisson/RedissonMultimap.java index 01ae4be7f..430e1c7dd 100644 --- a/redisson/src/main/java/org/redisson/RedissonMultimap.java +++ b/redisson/src/main/java/org/redisson/RedissonMultimap.java @@ -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 extends RedissonExpirable implement MapScanResult scanIterator(InetSocketAddress client, long startPos) { - Future> f = commandExecutor.readAsync(client, getName(), new ScanCodec(codec, StringCodec.INSTANCE), RedisCommands.HSCAN, getName(), startPos); + RFuture> f = commandExecutor.readAsync(client, getName(), new ScanCodec(codec, StringCodec.INSTANCE), RedisCommands.HSCAN, getName(), startPos); return get(f); } diff --git a/redisson/src/main/java/org/redisson/RedissonNode.java b/redisson/src/main/java/org/redisson/RedissonNode.java index 3c56062f0..7585c5f34 100644 --- a/redisson/src/main/java/org/redisson/RedissonNode.java +++ b/redisson/src/main/java/org/redisson/RedissonNode.java @@ -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 readFuture = entry.connectionReadOp(); + RFuture 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 writeFuture = entry.connectionWriteOp(); + RFuture writeFuture = entry.connectionWriteOp(); if (writeFuture.awaitUninterruptibly((long)connectionManager.getConfig().getConnectTimeout()) && writeFuture.isSuccess()) { RedisConnection connection = writeFuture.getNow(); diff --git a/redisson/src/main/java/org/redisson/RedissonObject.java b/redisson/src/main/java/org/redisson/RedissonObject.java index 22775b396..6f756967d 100644 --- a/redisson/src/main/java/org/redisson/RedissonObject.java +++ b/redisson/src/main/java/org/redisson/RedissonObject.java @@ -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 get(Future future) { + protected V get(RFuture future) { return commandExecutor.get(future); } diff --git a/redisson/src/main/java/org/redisson/RedissonPatternTopic.java b/redisson/src/main/java/org/redisson/RedissonPatternTopic.java index 52bc043c3..b99b8438d 100644 --- a/redisson/src/main/java/org/redisson/RedissonPatternTopic.java +++ b/redisson/src/main/java/org/redisson/RedissonPatternTopic.java @@ -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 implements RPatternTopic { } private int addListener(RedisPubSubListener pubSubListener) { - Future future = commandExecutor.getConnectionManager().psubscribe(name, codec, pubSubListener); + RFuture future = commandExecutor.getConnectionManager().psubscribe(name, codec, pubSubListener); future.syncUninterruptibly(); return System.identityHashCode(pubSubListener); } diff --git a/redisson/src/main/java/org/redisson/RedissonReactive.java b/redisson/src/main/java/org/redisson/RedissonReactive.java index 1f8ec5d69..bc9f39c2e 100644 --- a/redisson/src/main/java/org/redisson/RedissonReactive.java +++ b/redisson/src/main/java/org/redisson/RedissonReactive.java @@ -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 List> findBuckets(String pattern) { - Future> r = commandExecutor.readAllAsync(RedisCommands.KEYS, pattern); + RFuture> r = commandExecutor.readAllAsync(RedisCommands.KEYS, pattern); Collection keys = commandExecutor.get(r); List> buckets = new ArrayList>(keys.size()); diff --git a/redisson/src/main/java/org/redisson/RedissonRedLock.java b/redisson/src/main/java/org/redisson/RedissonRedLock.java index dd5a1a148..25b296d01 100644 --- a/redisson/src/main/java/org/redisson/RedissonRedLock.java +++ b/redisson/src/main/java/org/redisson/RedissonRedLock.java @@ -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> tryLockFutures) { + protected boolean sync(Map> tryLockFutures) { List lockedLocks = new ArrayList(tryLockFutures.size()); RuntimeException latestException = null; - for (Entry> entry : tryLockFutures.entrySet()) { + for (Entry> entry : tryLockFutures.entrySet()) { try { if (entry.getValue().syncUninterruptibly().getNow()) { lockedLocks.add(entry.getKey()); diff --git a/redisson/src/main/java/org/redisson/RedissonRemoteService.java b/redisson/src/main/java/org/redisson/RedissonRemoteService.java index 6607b5646..925958e24 100644 --- a/redisson/src/main/java/org/redisson/RedissonRemoteService.java +++ b/redisson/src/main/java/org/redisson/RedissonRemoteService.java @@ -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 void subscribe(final Class remoteInterface, final RBlockingQueue requestQueue, final ExecutorService executor) { - Future take = requestQueue.takeAsync(); + RFuture take = requestQueue.takeAsync(); take.addListener(new FutureListener() { @Override public void operationComplete(Future 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 ackClientsFuture = commandExecutor.evalWriteAsync(responseName, + RFuture 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 cancelRequestQueue = redisson.getBlockingQueue(getCancelRequestQueueName(remoteInterface, request.getRequestId()), getCodec()); - final Future cancelRequestFuture = cancelRequestQueue.takeAsync(); + final RFuture cancelRequestFuture = cancelRequestQueue.takeAsync(); final AtomicReference responseHolder = new AtomicReference(); @@ -230,7 +231,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS private void invokeMethod(final Class remoteInterface, final RBlockingQueue requestQueue, final RemoteServiceRequest request, RemoteServiceMethod method, String responseName, final ExecutorService executor, - Future cancelRequestFuture, final AtomicReference responseHolder) { + RFuture cancelRequestFuture, final AtomicReference 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> clientsFuture = send(timeout, responseName, + RFuture> clientsFuture = send(timeout, responseName, responseHolder.get()); clientsFuture.addListener(new FutureListener>() { @Override @@ -282,7 +283,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS } } - private Future> send(long timeout, String responseName, T response) { + private RFuture> send(long timeout, String responseName, T response) { RBatch batch = redisson.createBatch(); RBlockingQueueAsync queue = batch.getBlockingQueue(responseName, getCodec()); queue.putAsync(response); diff --git a/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java b/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java index 8ba39aa9d..227d9bb51 100644 --- a/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java +++ b/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java @@ -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 extends RedissonExpirable implements RScoredSortedSet { public RedissonScoredSortedSet(CommandAsyncExecutor commandExecutor, String name) { @@ -253,7 +251,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc } private ListScanResult scanIterator(InetSocketAddress client, long startPos) { - Future> f = commandExecutor.readAsync(client, getName(), codec, RedisCommands.ZSCAN, getName(), startPos); + RFuture> f = commandExecutor.readAsync(client, getName(), codec, RedisCommands.ZSCAN, getName(), startPos); return get(f); } diff --git a/redisson/src/main/java/org/redisson/RedissonSemaphore.java b/redisson/src/main/java/org/redisson/RedissonSemaphore.java index 8ac547166..000eff669 100644 --- a/redisson/src/main/java/org/redisson/RedissonSemaphore.java +++ b/redisson/src/main/java/org/redisson/RedissonSemaphore.java @@ -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 future = subscribe(); + RFuture future = subscribe(); get(future); try { while (true) { @@ -103,7 +102,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore { @Override public RFuture acquireAsync(final int permits) { final RPromise result = newPromise(); - Future tryAcquireFuture = tryAcquireAsync(permits); + RFuture tryAcquireFuture = tryAcquireAsync(permits); tryAcquireFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -117,7 +116,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore { return; } - final Future subscribeFuture = subscribe(); + final RFuture subscribeFuture = subscribe(); subscribeFuture.addListener(new FutureListener() { @Override public void operationComplete(Future 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 subscribeFuture, final Promise result) { - Future tryAcquireFuture = tryAcquireAsync(permits); + private void tryAcquireAsync(final AtomicLong time, final int permits, final RFuture subscribeFuture, final RPromise result) { + RFuture tryAcquireFuture = tryAcquireAsync(permits); tryAcquireFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -206,8 +205,8 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore { } - private void acquireAsync(final int permits, final Future subscribeFuture, final Promise result) { - Future tryAcquireFuture = tryAcquireAsync(permits); + private void acquireAsync(final int permits, final RFuture subscribeFuture, final RPromise result) { + RFuture tryAcquireFuture = tryAcquireAsync(permits); tryAcquireFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -284,7 +283,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore { } long time = unit.toMillis(waitTime); - Future future = subscribe(); + RFuture future = subscribe(); if (!await(future, time, TimeUnit.MILLISECONDS)) { return false; } @@ -317,7 +316,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore { public RFuture tryAcquireAsync(final int permits, long waitTime, TimeUnit unit) { final RPromise result = newPromise(); final AtomicLong time = new AtomicLong(unit.toMillis(waitTime)); - Future tryAcquireFuture = tryAcquireAsync(permits); + RFuture tryAcquireFuture = tryAcquireAsync(permits); tryAcquireFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -333,7 +332,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore { final long current = System.currentTimeMillis(); final AtomicReference futureRef = new AtomicReference(); - final Future subscribeFuture = subscribe(); + final RFuture subscribeFuture = subscribe(); subscribeFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -381,11 +380,11 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore { return semaphorePubSub.getEntry(getName()); } - private Future subscribe() { + private RFuture subscribe() { return semaphorePubSub.subscribe(getName(), getChannelName(), commandExecutor.getConnectionManager()); } - private void unsubscribe(Future future) { + private void unsubscribe(RFuture future) { semaphorePubSub.unsubscribe(future.getNow(), getName(), getChannelName(), commandExecutor.getConnectionManager()); } diff --git a/redisson/src/main/java/org/redisson/RedissonSubList.java b/redisson/src/main/java/org/redisson/RedissonSubList.java index 9b026de17..27ac6b8d2 100644 --- a/redisson/src/main/java/org/redisson/RedissonSubList.java +++ b/redisson/src/main/java/org/redisson/RedissonSubList.java @@ -323,7 +323,7 @@ public class RedissonSubList extends RedissonList implements RList { return get(f); } - private RFuture indexOfAsync(Object o, Convertor convertor) { + public RFuture indexOfAsync(Object o, Convertor convertor) { return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand("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 extends RedissonList implements RList { } @Override - public RFuture trimAsync(int fromIndex, int toIndex) { + public RFuture trimAsync(long fromIndex, long toIndex) { if (fromIndex < this.fromIndex || toIndex >= this.toIndex.get()) { throw new IndexOutOfBoundsException("fromIndex: " + fromIndex + " toIndex: " + toIndex); } diff --git a/redisson/src/main/java/org/redisson/RedissonTopic.java b/redisson/src/main/java/org/redisson/RedissonTopic.java index 5e290bce4..5bd324cf4 100644 --- a/redisson/src/main/java/org/redisson/RedissonTopic.java +++ b/redisson/src/main/java/org/redisson/RedissonTopic.java @@ -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 implements RTopic { } private int addListener(RedisPubSubListener pubSubListener) { - Future future = commandExecutor.getConnectionManager().subscribe(codec, name, pubSubListener); + RFuture future = commandExecutor.getConnectionManager().subscribe(codec, name, pubSubListener); future.syncUninterruptibly(); return System.identityHashCode(pubSubListener); } diff --git a/redisson/src/main/java/org/redisson/api/RFuture.java b/redisson/src/main/java/org/redisson/api/RFuture.java index d433def85..bbe9c6005 100644 --- a/redisson/src/main/java/org/redisson/api/RFuture.java +++ b/redisson/src/main/java/org/redisson/api/RFuture.java @@ -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 */ -public interface RFuture extends Future { +public interface RFuture extends java.util.concurrent.Future { + + /** + * 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 addListener(FutureListener listener); + + RFuture addListeners(FutureListener... listeners); + + RFuture removeListener(FutureListener listener); + + RFuture removeListeners(FutureListener... listeners); + + boolean isCancellable(); + + RFuture sync() throws InterruptedException; + + RFuture syncUninterruptibly(); + + RFuture await() throws InterruptedException; + + RFuture awaitUninterruptibly(); + + boolean awaitUninterruptibly(long timeout, TimeUnit unit); + + boolean awaitUninterruptibly(long timeoutMillis); + } diff --git a/redisson/src/main/java/org/redisson/api/RListAsync.java b/redisson/src/main/java/org/redisson/api/RListAsync.java index a93101ac4..df8de1f03 100644 --- a/redisson/src/main/java/org/redisson/api/RListAsync.java +++ b/redisson/src/main/java/org/redisson/api/RListAsync.java @@ -81,8 +81,10 @@ public interface RListAsync extends RCollectionAsync, RandomAccess { * @param toIndex * @return */ - RFuture trimAsync(int fromIndex, int toIndex); + RFuture trimAsync(long fromIndex, long toIndex); - RFuture fastRemoveAsync(int index); + RFuture fastRemoveAsync(long index); + + RFuture removeAsync(long index); } diff --git a/redisson/src/main/java/org/redisson/client/ReconnectListener.java b/redisson/src/main/java/org/redisson/client/ReconnectListener.java index 9248dfe08..3d4e6aebf 100644 --- a/redisson/src/main/java/org/redisson/client/ReconnectListener.java +++ b/redisson/src/main/java/org/redisson/client/ReconnectListener.java @@ -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 connectionFuture) throws RedisException; + void onReconnect(RedisConnection redisConnection, RPromise connectionFuture) throws RedisException; } diff --git a/redisson/src/main/java/org/redisson/client/RedisClient.java b/redisson/src/main/java/org/redisson/client/RedisClient.java index 7dd23ae9f..cfd7f7524 100644 --- a/redisson/src/main/java/org/redisson/client/RedisClient.java +++ b/redisson/src/main/java/org/redisson/client/RedisClient.java @@ -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 connectAsync() { - final Promise f = ImmediateEventExecutor.INSTANCE.newPromise(); + public RFuture connectAsync() { + final RPromise f = new RedissonPromise(ImmediateEventExecutor.INSTANCE.newPromise()); ChannelFuture channelFuture = bootstrap.connect(); channelFuture.addListener(new ChannelFutureListener() { @Override @@ -155,8 +157,8 @@ public class RedisClient { } } - public Future connectPubSubAsync() { - final Promise f = ImmediateEventExecutor.INSTANCE.newPromise(); + public RFuture connectPubSubAsync() { + final RPromise f = new RedissonPromise(ImmediateEventExecutor.INSTANCE.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> serverInfoAsync() { + public RFuture> serverInfoAsync() { final RedisConnection connection = connect(); - Promise> async = (Promise) connection.async(RedisCommands.SERVER_INFO); - async.addListener(new GenericFutureListener>>() { + RFuture> async = connection.async(RedisCommands.SERVER_INFO); + async.addListener(new FutureListener>() { @Override - public void operationComplete(Promise> future) throws Exception { + public void operationComplete(Future> future) throws Exception { connection.closeAsync(); } }); diff --git a/redisson/src/main/java/org/redisson/client/RedisConnection.java b/redisson/src/main/java/org/redisson/client/RedisConnection.java index 07cc2fab8..a4845c4c7 100644 --- a/redisson/src/main/java/org/redisson/client/RedisConnection.java +++ b/redisson/src/main/java/org/redisson/client/RedisConnection.java @@ -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 await(Future future) { + public R await(RFuture future) { final CountDownLatch l = new CountDownLatch(1); future.addListener(new FutureListener() { @Override @@ -151,25 +155,25 @@ public class RedisConnection implements RedisCommands { } public R sync(Codec encoder, RedisCommand command, Object ... params) { - Promise promise = ImmediateEventExecutor.INSTANCE.newPromise(); + RPromise promise = new RedissonPromise(ImmediateEventExecutor.INSTANCE.newPromise()); send(new CommandData(promise, encoder, command, params)); return await(promise); } - public Future async(RedisCommand command, Object ... params) { + public RFuture async(RedisCommand command, Object ... params) { return async(null, command, params); } - public Future async(long timeout, RedisCommand command, Object ... params) { + public RFuture async(long timeout, RedisCommand command, Object ... params) { return async(null, command, params); } - public Future async(Codec encoder, RedisCommand command, Object ... params) { + public RFuture async(Codec encoder, RedisCommand command, Object ... params) { return async(-1, encoder, command, params); } - public Future async(long timeout, Codec encoder, RedisCommand command, Object ... params) { - final Promise promise = ImmediateEventExecutor.INSTANCE.newPromise(); + public RFuture async(long timeout, Codec encoder, RedisCommand command, Object ... params) { + final RPromise promise = new RedissonPromise(ImmediateEventExecutor.INSTANCE.newPromise()); if (timeout == -1) { timeout = redisClient.getCommandTimeout(); } @@ -193,7 +197,7 @@ public class RedisConnection implements RedisCommands { } public CommandData create(Codec encoder, RedisCommand command, Object ... params) { - Promise promise = ImmediateEventExecutor.INSTANCE.newPromise(); + RPromise promise = new RedissonPromise(ImmediateEventExecutor.INSTANCE.newPromise()); return new CommandData(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; } diff --git a/redisson/src/main/java/org/redisson/client/handler/CommandDecoder.java b/redisson/src/main/java/org/redisson/client/handler/CommandDecoder.java index 6058b912d..30ac25c3f 100644 --- a/redisson/src/main/java/org/redisson/client/handler/CommandDecoder.java +++ b/redisson/src/main/java/org/redisson/client/handler/CommandDecoder.java @@ -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 { } if (i == commandBatch.getCommands().size()) { - Promise promise = commandBatch.getPromise(); + RPromise 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); diff --git a/redisson/src/main/java/org/redisson/client/handler/ConnectionWatchdog.java b/redisson/src/main/java/org/redisson/client/handler/ConnectionWatchdog.java index af90d62fa..c15bce8aa 100644 --- a/redisson/src/main/java/org/redisson/client/handler/ConnectionWatchdog.java +++ b/redisson/src/main/java/org/redisson/client/handler/ConnectionWatchdog.java @@ -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 connectionFuture = ImmediateEventExecutor.INSTANCE.newPromise(); + RPromise connectionFuture = new RedissonPromise(ImmediateEventExecutor.INSTANCE.newPromise()); connection.getReconnectListener().onReconnect(rc, connectionFuture); connectionFuture.addListener(new FutureListener() { @Override diff --git a/redisson/src/main/java/org/redisson/client/protocol/BatchCommandData.java b/redisson/src/main/java/org/redisson/client/protocol/BatchCommandData.java index e6b3e058a..3173169f9 100644 --- a/redisson/src/main/java/org/redisson/client/protocol/BatchCommandData.java +++ b/redisson/src/main/java/org/redisson/client/protocol/BatchCommandData.java @@ -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 extends CommandData implements Comparable> { private final int index; private final AtomicReference redirectError = new AtomicReference(); - public BatchCommandData(Promise promise, Codec codec, RedisCommand command, Object[] params, int index) { + public BatchCommandData(RPromise promise, Codec codec, RedisCommand command, Object[] params, int index) { super(promise, codec, command, params); this.index = index; } diff --git a/redisson/src/main/java/org/redisson/client/protocol/CommandData.java b/redisson/src/main/java/org/redisson/client/protocol/CommandData.java index 92bd1763b..9f470c549 100644 --- a/redisson/src/main/java/org/redisson/client/protocol/CommandData.java +++ b/redisson/src/main/java/org/redisson/client/protocol/CommandData.java @@ -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 implements QueueCommand { - final Promise promise; + final RPromise promise; final RedisCommand command; final Object[] params; final Codec codec; final MultiDecoder messageDecoder; - public CommandData(Promise promise, Codec codec, RedisCommand command, Object[] params) { + public CommandData(RPromise promise, Codec codec, RedisCommand command, Object[] params) { this(promise, null, codec, command, params); } - public CommandData(Promise promise, MultiDecoder messageDecoder, Codec codec, RedisCommand command, Object[] params) { + public CommandData(RPromise promise, MultiDecoder messageDecoder, Codec codec, RedisCommand command, Object[] params) { this.promise = promise; this.command = command; this.params = params; @@ -56,7 +55,7 @@ public class CommandData implements QueueCommand { return messageDecoder; } - public Promise getPromise() { + public RPromise getPromise() { return promise; } diff --git a/redisson/src/main/java/org/redisson/client/protocol/CommandsData.java b/redisson/src/main/java/org/redisson/client/protocol/CommandsData.java index 85c07b116..b30556f09 100644 --- a/redisson/src/main/java/org/redisson/client/protocol/CommandsData.java +++ b/redisson/src/main/java/org/redisson/client/protocol/CommandsData.java @@ -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> commands; - private final Promise promise; + private final RPromise promise; - public CommandsData(Promise promise, List> commands) { + public CommandsData(RPromise promise, List> commands) { super(); this.promise = promise; this.commands = commands; } - public Promise getPromise() { + public RPromise getPromise() { return promise; } diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java index c19bfb80d..e0d6249a5 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java @@ -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 connectionFuture = connect(cfg, addr); + RFuture connectionFuture = connect(cfg, addr); try { RedisConnection connection = connectionFuture.syncUninterruptibly().getNow(); List nodes = connection.sync(RedisCommands.CLUSTER_NODES); @@ -93,21 +94,21 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { lastClusterNode = addr; Collection partitions = parsePartitions(nodes); - List>>> futures = new ArrayList>>>(); + List>>> futures = new ArrayList>>>(); for (ClusterPartition partition : partitions) { if (partition.isMasterFail()) { continue; } - Future>> masterFuture = addMasterEntry(partition, cfg); + RFuture>> masterFuture = addMasterEntry(partition, cfg); futures.add(masterFuture); } - for (Future>> masterFuture : futures) { + for (RFuture>> masterFuture : futures) { masterFuture.awaitUninterruptibly(); if (!masterFuture.isSuccess()) { continue; } - for (Future future : masterFuture.getNow()) { + for (RFuture future : masterFuture.getNow()) { future.awaitUninterruptibly(); if (!future.isSuccess()) { continue; @@ -140,15 +141,15 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { } } - private Future connect(ClusterServersConfig cfg, final URI addr) { + private RFuture 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 result = newPromise(); - Future future = client.connectAsync(); + final RPromise result = newPromise(); + RFuture future = client.connectAsync(); future.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -158,7 +159,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { } RedisConnection connection = future.getNow(); - Promise promise = newPromise(); + RPromise promise = newPromise(); connectListener.onConnect(promise, connection, null, config); promise.addListener(new FutureListener() { @Override @@ -188,7 +189,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { protected void initEntry(MasterSlaveServersConfig config) { } - private Future>> addMasterEntry(final ClusterPartition partition, final ClusterServersConfig cfg) { + private RFuture>> 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>> result = newPromise(); - Future connectionFuture = connect(cfg, partition.getMasterAddress()); + final RPromise>> result = newPromise(); + RFuture connectionFuture = connect(cfg, partition.getMasterAddress()); connectionFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -213,7 +214,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { } final RedisConnection connection = future.getNow(); - Future> clusterFuture = connection.async(RedisCommands.CLUSTER_INFO); + RFuture> clusterFuture = connection.async(RedisCommands.CLUSTER_INFO); clusterFuture.addListener(new FutureListener>() { @Override @@ -238,7 +239,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { config.setMasterAddress(partition.getMasterAddress()); final MasterSlaveEntry e; - List> futures = new ArrayList>(); + List> futures = new ArrayList>(); 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> fs = e.initSlaveBalancer(partition.getFailedSlaveAddresses()); + List> 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 f = e.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort()); - final Promise initFuture = newPromise(); + RFuture f = e.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort()); + final RPromise initFuture = newPromise(); futures.add(initFuture); f.addListener(new FutureListener() { @Override @@ -327,7 +328,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { return; } final URI uri = iterator.next(); - Future connectionFuture = connect(cfg, uri); + RFuture connectionFuture = connect(cfg, uri); connectionFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -344,7 +345,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { } private void updateClusterState(final ClusterServersConfig cfg, final RedisConnection connection, final Iterator iterator, final URI uri) { - Future> future = connection.async(RedisCommands.CLUSTER_NODES); + RFuture> future = connection.async(RedisCommands.CLUSTER_NODES); future.addListener(new FutureListener>() { @Override public void operationComplete(Future> future) throws Exception { @@ -367,7 +368,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { } final Collection newPartitions = parsePartitions(nodes); - Future masterFuture = checkMasterNodesChange(cfg, newPartitions); + RFuture masterFuture = checkMasterNodesChange(cfg, newPartitions); checkSlaveNodesChange(newPartitions); masterFuture.addListener(new FutureListener() { @Override @@ -434,7 +435,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { Set addedSlaves = new HashSet(newPart.getSlaveAddresses()); addedSlaves.removeAll(currentPart.getSlaveAddresses()); for (final URI uri : addedSlaves) { - Future future = entry.addSlave(uri.getHost(), uri.getPort()); + RFuture future = entry.addSlave(uri.getHost(), uri.getPort()); future.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -470,7 +471,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { return null; } - private Future checkMasterNodesChange(ClusterServersConfig cfg, Collection newPartitions) { + private RFuture checkMasterNodesChange(ClusterServersConfig cfg, Collection newPartitions) { List newMasters = new ArrayList(); for (final ClusterPartition newPart : newPartitions) { boolean masterFound = false; @@ -509,21 +510,21 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { return newSucceededFuture(null); } - final Promise result = newPromise(); + final RPromise result = newPromise(); final AtomicInteger masters = new AtomicInteger(newMasters.size()); - final Queue> futures = new ConcurrentLinkedQueue>(); + final Queue> futures = new ConcurrentLinkedQueue>(); for (ClusterPartition newPart : newMasters) { - Future>> future = addMasterEntry(newPart, cfg); - future.addListener(new FutureListener>>() { + RFuture>> future = addMasterEntry(newPart, cfg); + future.addListener(new FutureListener>>() { @Override - public void operationComplete(Future>> future) throws Exception { + public void operationComplete(Future>> future) throws Exception { if (future.isSuccess()) { futures.addAll(future.getNow()); } if (masters.decrementAndGet() == 0) { final AtomicInteger nodes = new AtomicInteger(futures.size()); - for (Future nodeFuture : futures) { + for (RFuture nodeFuture : futures) { nodeFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { diff --git a/redisson/src/main/java/org/redisson/command/AsyncDetails.java b/redisson/src/main/java/org/redisson/command/AsyncDetails.java index 0ea4c2fcd..f1aaf3f17 100644 --- a/redisson/src/main/java/org/redisson/command/AsyncDetails.java +++ b/redisson/src/main/java/org/redisson/command/AsyncDetails.java @@ -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 { static final ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue(); - Future connectionFuture; + RFuture connectionFuture; ConnectionManager connectionManager; - Promise attemptPromise; + RPromise attemptPromise; boolean readOnlyMode; NodeSource source; Codec codec; RedisCommand command; Object[] params; - Promise mainPromise; + RPromise mainPromise; int attempt; @@ -69,10 +69,10 @@ public class AsyncDetails { // queue.add(details); } - public void init(Future connectionFuture, - Promise attemptPromise, boolean readOnlyMode, NodeSource source, + public void init(RFuture connectionFuture, + RPromise attemptPromise, boolean readOnlyMode, NodeSource source, Codec codec, RedisCommand command, Object[] params, - Promise mainPromise, int attempt) { + RPromise mainPromise, int attempt) { this.connectionFuture = connectionFuture; this.attemptPromise = attemptPromise; this.readOnlyMode = readOnlyMode; @@ -108,11 +108,11 @@ public class AsyncDetails { this.timeout = timeout; } - public Future getConnectionFuture() { + public RFuture getConnectionFuture() { return connectionFuture; } - public Promise getAttemptPromise() { + public RPromise getAttemptPromise() { return attemptPromise; } @@ -136,7 +136,7 @@ public class AsyncDetails { return params; } - public Promise getMainPromise() { + public RPromise getMainPromise() { return mainPromise; } diff --git a/redisson/src/main/java/org/redisson/command/CommandAsyncExecutor.java b/redisson/src/main/java/org/redisson/command/CommandAsyncExecutor.java index 1aeaf7271..59bf5e9c1 100644 --- a/redisson/src/main/java/org/redisson/command/CommandAsyncExecutor.java +++ b/redisson/src/main/java/org/redisson/command/CommandAsyncExecutor.java @@ -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(); - RedisException convertException(Future RFuture); + RedisException convertException(RFuture RFuture); - boolean await(Future RFuture, long timeout, TimeUnit timeoutUnit) throws InterruptedException; + boolean await(RFuture RFuture, long timeout, TimeUnit timeoutUnit) throws InterruptedException; - V get(Future RFuture); + V get(RFuture RFuture); RFuture writeAsync(MasterSlaveEntry entry, Codec codec, RedisCommand command, Object ... params); diff --git a/redisson/src/main/java/org/redisson/command/CommandAsyncService.java b/redisson/src/main/java/org/redisson/command/CommandAsyncService.java index e0da953c3..01dc900ab 100644 --- a/redisson/src/main/java/org/redisson/command/CommandAsyncService.java +++ b/redisson/src/main/java/org/redisson/command/CommandAsyncService.java @@ -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 get(Future future) { + public V get(RFuture future) { final CountDownLatch l = new CountDownLatch(1); future.addListener(new FutureListener() { @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() { @Override @@ -173,7 +172,7 @@ public class CommandAsyncService implements CommandAsyncExecutor { }; for (MasterSlaveEntry entry : nodes) { - Promise promise = connectionManager.newPromise(); + RPromise 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 void retryReadRandomAsync(final RedisCommand command, final Promise mainPromise, + private void retryReadRandomAsync(final RedisCommand command, final RPromise mainPromise, final List nodes, final Object... params) { final RPromise attemptPromise = connectionManager.newPromise(); attemptPromise.addListener(new FutureListener() { @@ -257,14 +256,14 @@ public class CommandAsyncService implements CommandAsyncExecutor { }; for (MasterSlaveEntry entry : nodes) { - Promise promise = connectionManager.newPromise(); + RPromise promise = connectionManager.newPromise(); promise.addListener(listener); async(readOnlyMode, new NodeSource(entry), connectionManager.getCodec(), command, params, promise, 0); } return mainPromise; } - public RedisException convertException(Future future) { + public RedisException convertException(RFuture 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 promise = connectionManager.newPromise(); + RPromise 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 void async(final boolean readOnlyMode, final NodeSource source, final Codec codec, - final RedisCommand command, final Object[] params, final Promise mainPromise, final int attempt) { + final RedisCommand command, final Object[] params, final RPromise mainPromise, final int attempt) { if (mainPromise.isCancelled()) { return; } @@ -427,9 +426,9 @@ public class CommandAsyncService implements CommandAsyncExecutor { return; } - final Promise attemptPromise = connectionManager.newPromise(); + final RPromise attemptPromise = connectionManager.newPromise(); - final Future connectionFuture; + final RFuture 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> list = new ArrayList>(2); - Promise promise = connectionManager.newPromise(); + RPromise promise = connectionManager.newPromise(); list.add(new CommandData(promise, details.getCodec(), RedisCommands.ASKING, new Object[] {})); list.add(new CommandData(details.getAttemptPromise(), details.getCodec(), details.getCommand(), details.getParams())); - Promise main = connectionManager.newPromise(); + RPromise 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 void releaseConnection(final NodeSource source, final Future connectionFuture, - final boolean isReadOnly, Promise attemptPromise, final AsyncDetails details) { + protected void releaseConnection(final NodeSource source, final RFuture connectionFuture, + final boolean isReadOnly, RPromise attemptPromise, final AsyncDetails details) { attemptPromise.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { diff --git a/redisson/src/main/java/org/redisson/command/CommandBatchService.java b/redisson/src/main/java/org/redisson/command/CommandBatchService.java index 38cbb646a..d693f3670 100644 --- a/redisson/src/main/java/org/redisson/command/CommandBatchService.java +++ b/redisson/src/main/java/org/redisson/command/CommandBatchService.java @@ -93,7 +93,7 @@ public class CommandBatchService extends CommandReactiveService { @Override protected void async(boolean readOnlyMode, NodeSource nodeSource, - Codec codec, RedisCommand command, Object[] params, Promise mainPromise, int attempt) { + Codec codec, RedisCommand command, Object[] params, RPromise 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 voidPromise = connectionManager.newPromise(); + RPromise voidPromise = connectionManager.newPromise(); final RPromise> promise = connectionManager.newPromise(); voidPromise.addListener(new FutureListener() { @Override @@ -185,7 +185,7 @@ public class CommandBatchService extends CommandReactiveService { return promise; } - public void execute(final Entry entry, final NodeSource source, final Promise mainPromise, final AtomicInteger slots, final int attempt) { + public void execute(final Entry entry, final NodeSource source, final RPromise mainPromise, final AtomicInteger slots, final int attempt) { if (mainPromise.isCancelled()) { return; } @@ -195,11 +195,11 @@ public class CommandBatchService extends CommandReactiveService { return; } - final Promise attemptPromise = connectionManager.newPromise(); + final RPromise attemptPromise = connectionManager.newPromise(); final AsyncDetails details = new AsyncDetails(); - final Future connectionFuture; + final RFuture connectionFuture; if (entry.isReadOnlyMode()) { connectionFuture = connectionManager.connectionReadOp(source, null); } else { @@ -254,7 +254,7 @@ public class CommandBatchService extends CommandReactiveService { connectionFuture.addListener(new FutureListener() { @Override public void operationComplete(Future 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 attemptPromise, AsyncDetails details, + private void checkWriteFuture(final RPromise 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 mainPromise, final Promise attemptPromise, final AsyncDetails details, - Future connFuture) { + final RPromise mainPromise, final RPromise attemptPromise, final AsyncDetails details, + RFuture connFuture) { if (attemptPromise.isDone() || mainPromise.isCancelled() || connFuture.isCancelled()) { return; } @@ -335,7 +335,7 @@ public class CommandBatchService extends CommandReactiveService { List> list = new ArrayList>(entry.getCommands().size() + 1); if (source.getRedirect() == Redirect.ASK) { - Promise promise = connectionManager.newPromise(); + RPromise promise = connectionManager.newPromise(); list.add(new CommandData(promise, StringCodec.INSTANCE, RedisCommands.ASKING, new Object[] {})); } for (BatchCommandData c : entry.getCommands()) { diff --git a/redisson/src/main/java/org/redisson/command/CommandReactiveExecutor.java b/redisson/src/main/java/org/redisson/command/CommandReactiveExecutor.java index 05e205a4e..32df60fca 100644 --- a/redisson/src/main/java/org/redisson/command/CommandReactiveExecutor.java +++ b/redisson/src/main/java/org/redisson/command/CommandReactiveExecutor.java @@ -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 { - Publisher reactive(Future future); + Publisher reactive(RFuture future); ConnectionManager getConnectionManager(); diff --git a/redisson/src/main/java/org/redisson/command/CommandReactiveService.java b/redisson/src/main/java/org/redisson/command/CommandReactiveService.java index 236a4da64..fc33c3f5f 100644 --- a/redisson/src/main/java/org/redisson/command/CommandReactiveService.java +++ b/redisson/src/main/java/org/redisson/command/CommandReactiveService.java @@ -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 Publisher evalWriteAllReactive(RedisCommand command, SlotCallback callback, String script, List keys, Object ... params) { - Future f = evalWriteAllAsync(command, callback, script, keys, params); + RFuture f = evalWriteAllAsync(command, callback, script, keys, params); return new NettyFuturePublisher(f); } - public Publisher reactive(Future future) { + public Publisher reactive(RFuture future) { return new NettyFuturePublisher(future); } @Override public Publisher> readAllReactive(RedisCommand command, Object ... params) { - Future> f = readAllAsync(command, params); + RFuture> f = readAllAsync(command, params); return new NettyFuturePublisher>(f); } @Override public Publisher readRandomReactive(RedisCommand command, Object ... params) { - Future f = readRandomAsync(command, params); + RFuture f = readRandomAsync(command, params); return new NettyFuturePublisher(f); } @Override public Publisher readReactive(InetSocketAddress client, String key, Codec codec, RedisCommand command, Object ... params) { - Future f = readAsync(client, key, codec, command, params); + RFuture f = readAsync(client, key, codec, command, params); return new NettyFuturePublisher(f); } @@ -75,13 +74,13 @@ public class CommandReactiveService extends CommandAsyncService implements Comma @Override public Publisher writeReactive(String key, Codec codec, RedisCommand command, Object ... params) { - Future f = writeAsync(key, codec, command, params); + RFuture f = writeAsync(key, codec, command, params); return new NettyFuturePublisher(f); } @Override public Publisher writeReactive(MasterSlaveEntry entry, Codec codec, RedisCommand command, Object ... params) { - Future f = writeAsync(entry, codec, command, params); + RFuture f = writeAsync(entry, codec, command, params); return new NettyFuturePublisher(f); } @@ -92,21 +91,21 @@ public class CommandReactiveService extends CommandAsyncService implements Comma @Override public Publisher readReactive(String key, Codec codec, RedisCommand command, Object ... params) { - Future f = readAsync(key, codec, command, params); + RFuture f = readAsync(key, codec, command, params); return new NettyFuturePublisher(f); } @Override public Publisher evalReadReactive(String key, Codec codec, RedisCommand evalCommandType, String script, List keys, Object... params) { - Future f = evalReadAsync(key, codec, evalCommandType, script, keys, params); + RFuture f = evalReadAsync(key, codec, evalCommandType, script, keys, params); return new NettyFuturePublisher(f); } @Override public Publisher evalReadReactive(InetSocketAddress client, String key, Codec codec, RedisCommand evalCommandType, String script, List keys, Object ... params) { - Future f = evalReadAsync(client, key, codec, evalCommandType, script, keys, params); + RFuture f = evalReadAsync(client, key, codec, evalCommandType, script, keys, params); return new NettyFuturePublisher(f); } @@ -114,19 +113,19 @@ public class CommandReactiveService extends CommandAsyncService implements Comma @Override public Publisher evalWriteReactive(String key, Codec codec, RedisCommand evalCommandType, String script, List keys, Object... params) { - Future f = evalWriteAsync(key, codec, evalCommandType, script, keys, params); + RFuture f = evalWriteAsync(key, codec, evalCommandType, script, keys, params); return new NettyFuturePublisher(f); } @Override public Publisher writeAllReactive(RedisCommand command, Object ... params) { - Future f = writeAllAsync(command, params); + RFuture f = writeAllAsync(command, params); return new NettyFuturePublisher(f); } @Override public Publisher writeAllReactive(RedisCommand command, SlotCallback callback, Object ... params) { - Future f = writeAllAsync(command, callback, params); + RFuture f = writeAllAsync(command, callback, params); return new NettyFuturePublisher(f); } diff --git a/redisson/src/main/java/org/redisson/command/CommandSyncExecutor.java b/redisson/src/main/java/org/redisson/command/CommandSyncExecutor.java index ac6c70ca9..104171b52 100644 --- a/redisson/src/main/java/org/redisson/command/CommandSyncExecutor.java +++ b/redisson/src/main/java/org/redisson/command/CommandSyncExecutor.java @@ -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 get(Future future); + V get(RFuture future); R write(Integer slot, Codec codec, RedisCommand command, Object ... params); diff --git a/redisson/src/main/java/org/redisson/command/CommandSyncService.java b/redisson/src/main/java/org/redisson/command/CommandSyncService.java index f99372496..8a05f4821 100644 --- a/redisson/src/main/java/org/redisson/command/CommandSyncService.java +++ b/redisson/src/main/java/org/redisson/command/CommandSyncService.java @@ -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 R read(String key, Codec codec, RedisCommand command, Object ... params) { - Future res = readAsync(key, codec, command, params); + RFuture res = readAsync(key, codec, command, params); return get(res); } @Override public R read(InetSocketAddress client, String key, RedisCommand command, Object ... params) { - Future res = readAsync(client, key, connectionManager.getCodec(), command, params); + RFuture res = readAsync(client, key, connectionManager.getCodec(), command, params); return get(res); } @Override public R read(InetSocketAddress client, String key, Codec codec, RedisCommand command, Object ... params) { - Future res = readAsync(client, key, codec, command, params); + RFuture res = readAsync(client, key, codec, command, params); return get(res); } @@ -69,7 +68,7 @@ public class CommandSyncService extends CommandAsyncService implements CommandEx @Override public R evalRead(String key, Codec codec, RedisCommand evalCommandType, String script, List keys, Object ... params) { - Future res = evalReadAsync(key, codec, evalCommandType, script, keys, params); + RFuture res = evalReadAsync(key, codec, evalCommandType, script, keys, params); return get(res); } @@ -80,25 +79,25 @@ public class CommandSyncService extends CommandAsyncService implements CommandEx @Override public R evalWrite(String key, Codec codec, RedisCommand evalCommandType, String script, List keys, Object ... params) { - Future res = evalWriteAsync(key, codec, evalCommandType, script, keys, params); + RFuture res = evalWriteAsync(key, codec, evalCommandType, script, keys, params); return get(res); } @Override public R write(Integer slot, Codec codec, RedisCommand command, Object ... params) { - Future res = writeAsync(slot, codec, command, params); + RFuture res = writeAsync(slot, codec, command, params); return get(res); } @Override public R write(String key, Codec codec, RedisCommand command, Object ... params) { - Future res = writeAsync(key, codec, command, params); + RFuture res = writeAsync(key, codec, command, params); return get(res); } @Override public R write(String key, RedisCommand command, Object ... params) { - Future res = writeAsync(key, command, params); + RFuture res = writeAsync(key, command, params); return get(res); } diff --git a/redisson/src/main/java/org/redisson/connection/ClientConnectionsEntry.java b/redisson/src/main/java/org/redisson/connection/ClientConnectionsEntry.java index a4c2613cd..e0d869a23 100644 --- a/redisson/src/main/java/org/redisson/connection/ClientConnectionsEntry.java +++ b/redisson/src/main/java/org/redisson/connection/ClientConnectionsEntry.java @@ -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 connect() { - final Promise connectionFuture = connectionManager.newPromise(); - Future future = client.connectAsync(); + public RFuture connect() { + final RPromise connectionFuture = connectionManager.newPromise(); + RFuture future = client.connectAsync(); future.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -158,18 +159,18 @@ public class ClientConnectionsEntry { return connectionFuture; } - private void addReconnectListener(Promise connectionFuture, T conn) { + private void addReconnectListener(RPromise connectionFuture, T conn) { addFireEventListener(conn, connectionFuture); conn.setReconnectListener(new ReconnectListener() { @Override - public void onReconnect(RedisConnection conn, Promise connectionFuture) { + public void onReconnect(RedisConnection conn, RPromise connectionFuture) { addFireEventListener(conn, connectionFuture); } }); } - private void addFireEventListener(T conn, Promise connectionFuture) { + private void addFireEventListener(T conn, RPromise connectionFuture) { connectionManager.getConnectListener().onConnect(connectionFuture, conn, nodeType, connectionManager.getConfig()); if (connectionFuture.isSuccess()) { @@ -191,9 +192,9 @@ public class ClientConnectionsEntry { return connectionManager.getConfig(); } - public Future connectPubSub() { - final Promise connectionFuture = connectionManager.newPromise(); - Future future = client.connectPubSubAsync(); + public RFuture connectPubSub() { + final RPromise connectionFuture = connectionManager.newPromise(); + RFuture future = client.connectPubSubAsync(); future.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { diff --git a/redisson/src/main/java/org/redisson/connection/ConnectionInitializer.java b/redisson/src/main/java/org/redisson/connection/ConnectionInitializer.java index 124ace6b5..f9b98c35b 100644 --- a/redisson/src/main/java/org/redisson/connection/ConnectionInitializer.java +++ b/redisson/src/main/java/org/redisson/connection/ConnectionInitializer.java @@ -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 { - void onConnect(Promise connectionFuture, T conn, NodeType nodeType, MasterSlaveServersConfig config); + void onConnect(RPromise connectionFuture, T conn, NodeType nodeType, MasterSlaveServersConfig config); } diff --git a/redisson/src/main/java/org/redisson/connection/ConnectionManager.java b/redisson/src/main/java/org/redisson/connection/ConnectionManager.java index 4c9f69063..4f3022fd8 100644 --- a/redisson/src/main/java/org/redisson/connection/ConnectionManager.java +++ b/redisson/src/main/java/org/redisson/connection/ConnectionManager.java @@ -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 subscribe(Codec codec, String channelName, RedisPubSubListener listener); + RFuture subscribe(Codec codec, String channelName, RedisPubSubListener listener); - Future subscribe(Codec codec, String channelName, RedisPubSubListener listener, AsyncSemaphore semaphore); + RFuture 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 connectionReadOp(NodeSource source, RedisCommand command); + RFuture connectionReadOp(NodeSource source, RedisCommand command); - Future connectionWriteOp(NodeSource source, RedisCommand command); + RFuture 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 psubscribe(String pattern, Codec codec, RedisPubSubListener listener); + RFuture psubscribe(String pattern, Codec codec, RedisPubSubListener listener); - Future psubscribe(String pattern, Codec codec, RedisPubSubListener listener, AsyncSemaphore semaphore); + RFuture 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 getShutdownPromise(); + RFuture getShutdownPromise(); } diff --git a/redisson/src/main/java/org/redisson/connection/DefaultConnectionListener.java b/redisson/src/main/java/org/redisson/connection/DefaultConnectionListener.java index 534723474..8dc8f3a3c 100644 --- a/redisson/src/main/java/org/redisson/connection/DefaultConnectionListener.java +++ b/redisson/src/main/java/org/redisson/connection/DefaultConnectionListener.java @@ -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 void onConnect(Promise connectionFuture, T conn, NodeType nodeType, MasterSlaveServersConfig config) { + public final void onConnect(RPromise connectionFuture, T conn, NodeType nodeType, MasterSlaveServersConfig config) { FutureConnectionListener listener = new FutureConnectionListener(connectionFuture, conn); doConnect(config, nodeType, listener); listener.executeCommands(); diff --git a/redisson/src/main/java/org/redisson/connection/ElasticacheConnectionManager.java b/redisson/src/main/java/org/redisson/connection/ElasticacheConnectionManager.java index 539134d7f..615b6ffee 100644 --- a/redisson/src/main/java/org/redisson/connection/ElasticacheConnectionManager.java +++ b/redisson/src/main/java/org/redisson/connection/ElasticacheConnectionManager.java @@ -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 future = newPromise(); + RPromise future = newPromise(); connectListener.onConnect(future, connection, null, config); future.syncUninterruptibly(); nodeConnections.put(addr, connection); diff --git a/redisson/src/main/java/org/redisson/connection/FutureConnectionListener.java b/redisson/src/main/java/org/redisson/connection/FutureConnectionListener.java index 23af19ebb..2d907b441 100644 --- a/redisson/src/main/java/org/redisson/connection/FutureConnectionListener.java +++ b/redisson/src/main/java/org/redisson/connection/FutureConnectionListener.java @@ -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 implements FutureListener { private final AtomicInteger commandsCounter = new AtomicInteger(); - private final Promise connectionPromise; + private final RPromise connectionPromise; private final T connection; private final List commands = new ArrayList(4); - public FutureConnectionListener(Promise connectionFuture, T connection) { + public FutureConnectionListener(RPromise connectionFuture, T connection) { super(); this.connectionPromise = connectionFuture; this.connection = connection; @@ -45,7 +46,7 @@ public class FutureConnectionListener implements Futu commands.add(new Runnable() { @Override public void run() { - Future future = connection.async(command, params); + RFuture future = connection.async(command, params); future.addListener(FutureConnectionListener.this); } }); diff --git a/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java b/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java index 0570b0c76..eb496253e 100644 --- a/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java +++ b/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java @@ -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 entries = PlatformDependent.newConcurrentHashMap(); - private final Promise shutdownPromise; + private final RPromise 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 f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort()); + RFuture 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 slots) { MasterSlaveEntry entry = new MasterSlaveEntry(slots, this, config); - List> fs = entry.initSlaveBalancer(java.util.Collections.emptySet()); - for (Future future : fs) { + List> fs = entry.initSlaveBalancer(java.util.Collections.emptySet()); + for (RFuture future : fs) { future.syncUninterruptibly(); } - Future f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort()); + RFuture 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 psubscribe(final String channelName, final Codec codec, final RedisPubSubListener listener) { + public RFuture psubscribe(final String channelName, final Codec codec, final RedisPubSubListener listener) { final AsyncSemaphore lock = getSemaphore(channelName); - final Promise result = newPromise(); + final RPromise result = newPromise(); lock.acquire(new Runnable() { @Override public void run() { - Future future = psubscribe(channelName, codec, listener, lock); + RFuture future = psubscribe(channelName, codec, listener, lock); future.addListener(new TransferListener(result)); } }); return result; } - public Future psubscribe(String channelName, Codec codec, RedisPubSubListener listener, AsyncSemaphore semaphore) { - Promise promise = newPromise(); + public RFuture psubscribe(String channelName, Codec codec, RedisPubSubListener listener, AsyncSemaphore semaphore) { + RPromise promise = newPromise(); subscribe(codec, channelName, listener, promise, PubSubType.PSUBSCRIBE, semaphore); return promise; } - public Future subscribe(final Codec codec, final String channelName, final RedisPubSubListener listener) { + public RFuture subscribe(final Codec codec, final String channelName, final RedisPubSubListener listener) { final AsyncSemaphore lock = getSemaphore(channelName); - final Promise result = newPromise(); + final RPromise result = newPromise(); lock.acquire(new Runnable() { @Override public void run() { - Future future = subscribe(codec, channelName, listener, lock); + RFuture future = subscribe(codec, channelName, listener, lock); future.addListener(new TransferListener(result)); } }); return result; } - public Future subscribe(Codec codec, String channelName, RedisPubSubListener listener, AsyncSemaphore semaphore) { - Promise promise = newPromise(); + public RFuture subscribe(Codec codec, String channelName, RedisPubSubListener listener, AsyncSemaphore semaphore) { + RPromise 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 promise, final PubSubType type, final AsyncSemaphore lock) { + final RPromise 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 promise, final PubSubType type, final AsyncSemaphore lock) { + final RPromise promise, final PubSubType type, final AsyncSemaphore lock) { final int slot = calcSlot(channelName); - Future connFuture = nextPubSubConnection(slot); + RFuture connFuture = nextPubSubConnection(slot); connFuture.addListener(new FutureListener() { @Override @@ -614,7 +613,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager { } @Override - public Future connectionWriteOp(NodeSource source, RedisCommand command) { + public RFuture 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 connectionReadOp(NodeSource source, RedisCommand command) { + public RFuture 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 nextPubSubConnection(int slot) { + RFuture nextPubSubConnection(int slot) { return getEntry(slot).nextPubSubConnection(); } @@ -746,7 +745,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager { } @Override - public Future getShutdownPromise() { + public RFuture getShutdownPromise() { return shutdownPromise; } diff --git a/redisson/src/main/java/org/redisson/connection/MasterSlaveEntry.java b/redisson/src/main/java/org/redisson/connection/MasterSlaveEntry.java index 61cc713dc..d28a0979d 100644 --- a/redisson/src/main/java/org/redisson/connection/MasterSlaveEntry.java +++ b/redisson/src/main/java/org/redisson/connection/MasterSlaveEntry.java @@ -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> initSlaveBalancer(Collection disconnectedNodes) { + public List> initSlaveBalancer(Collection disconnectedNodes) { boolean freezeMasterAsSlave = !config.getSlaveAddresses().isEmpty() && config.getReadMode() == ReadMode.SLAVE && disconnectedNodes.size() < config.getSlaveAddresses().size(); - List> result = new LinkedList>(); - Future f = addSlave(config.getMasterAddress().getHost(), config.getMasterAddress().getPort(), freezeMasterAsSlave, NodeType.MASTER); + List> result = new LinkedList>(); + RFuture 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 setupMasterEntry(String host, int port) { + public RFuture 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 subscribeFuture = connectionManager.subscribe(subscribeCodec, channelName, null); + RFuture subscribeFuture = connectionManager.subscribe(subscribeCodec, channelName, null); subscribeFuture.addListener(new FutureListener() { @Override @@ -203,7 +204,7 @@ public class MasterSlaveEntry { final Collection> listeners) { Codec subscribeCodec = connectionManager.punsubscribe(channelName); if (!listeners.isEmpty()) { - Future future = connectionManager.psubscribe(channelName, subscribeCodec, null); + RFuture future = connectionManager.psubscribe(channelName, subscribeCodec, null); future.addListener(new FutureListener() { @Override public void operationComplete(Future future) @@ -231,7 +232,7 @@ public class MasterSlaveEntry { return; } - Future newConnection = connectionReadOp(); + RFuture newConnection = connectionReadOp(); newConnection.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -268,11 +269,11 @@ public class MasterSlaveEntry { }); } - public Future addSlave(String host, int port) { + public RFuture addSlave(String host, int port) { return addSlave(host, port, true, NodeType.SLAVE); } - private Future addSlave(String host, int port, boolean freezed, NodeType mode) { + private RFuture 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 connectionWriteOp() { + public RFuture connectionWriteOp() { return writeConnectionHolder.get(); } - public Future connectionReadOp() { + public RFuture connectionReadOp() { return slaveBalancer.nextConnection(); } - public Future connectionReadOp(InetSocketAddress addr) { + public RFuture connectionReadOp(InetSocketAddress addr) { return slaveBalancer.getConnection(addr); } - - Future nextPubSubConnection() { + RFuture nextPubSubConnection() { return slaveBalancer.nextPubSubConnection(); } diff --git a/redisson/src/main/java/org/redisson/connection/RedisClientEntry.java b/redisson/src/main/java/org/redisson/connection/RedisClientEntry.java index eed80a2f8..f0c3dc2b5 100644 --- a/redisson/src/main/java/org/redisson/connection/RedisClientEntry.java +++ b/redisson/src/main/java/org/redisson/connection/RedisClientEntry.java @@ -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 future = manager.newPromise(); + RPromise future = manager.newPromise(); manager.getConnectListener().onConnect(future, c, null, manager.getConfig()); future.syncUninterruptibly(); return future.getNow(); diff --git a/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java b/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java index 8a7d0bda1..227ab8a82 100755 --- a/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java +++ b/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java @@ -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> connectionFutures = new ArrayList>(cfg.getSentinelAddresses().size()); + List> connectionFutures = new ArrayList>(cfg.getSentinelAddresses().size()); for (URI addr : cfg.getSentinelAddresses()) { - Future future = registerSentinel(cfg, addr, c); + RFuture future = registerSentinel(cfg, addr, c); connectionFutures.add(future); } - for (Future future : connectionFutures) { + for (RFuture future : connectionFutures) { future.awaitUninterruptibly(); } } @@ -130,23 +131,23 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { protected MasterSlaveEntry createMasterSlaveEntry(MasterSlaveServersConfig config, HashSet slots) { MasterSlaveEntry entry = new MasterSlaveEntry(slots, this, config); - List> fs = entry.initSlaveBalancer(disconnectedSlaves); - for (Future future : fs) { + List> fs = entry.initSlaveBalancer(disconnectedSlaves); + for (RFuture future : fs) { future.syncUninterruptibly(); } - Future f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort()); + RFuture f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort()); f.syncUninterruptibly(); return entry; } - private Future registerSentinel(final SentinelServersConfig cfg, final URI addr, final MasterSlaveServersConfig c) { + private RFuture 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 pubsubFuture = client.connectPubSubAsync(); + RFuture pubsubFuture = client.connectPubSubAsync(); pubsubFuture.addListener(new FutureListener() { @Override public void operationComplete(Future 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 future = getEntry(singleSlotRange.getStartSlot()).addSlave(ip, Integer.valueOf(port)); + RFuture future = getEntry(singleSlotRange.getStartSlot()).addSlave(ip, Integer.valueOf(port)); future.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { diff --git a/redisson/src/main/java/org/redisson/connection/SingleEntry.java b/redisson/src/main/java/org/redisson/connection/SingleEntry.java index 85ca21e7a..a474a125b 100644 --- a/redisson/src/main/java/org/redisson/connection/SingleEntry.java +++ b/redisson/src/main/java/org/redisson/connection/SingleEntry.java @@ -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 setupMasterEntry(String host, int port) { + public RFuture 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 res = connectionManager.newPromise(); - Future f = writeConnectionHolder.add(masterEntry); - Future s = pubSubConnectionHolder.add(masterEntry); + final RPromise res = connectionManager.newPromise(); + RFuture f = writeConnectionHolder.add(masterEntry); + RFuture s = pubSubConnectionHolder.add(masterEntry); FutureListener listener = new FutureListener() { AtomicInteger counter = new AtomicInteger(2); @Override @@ -71,7 +72,7 @@ public class SingleEntry extends MasterSlaveEntry { } @Override - Future nextPubSubConnection() { + RFuture nextPubSubConnection() { return pubSubConnectionHolder.get(); } @@ -81,12 +82,12 @@ public class SingleEntry extends MasterSlaveEntry { } @Override - public Future connectionReadOp(InetSocketAddress addr) { + public RFuture connectionReadOp(InetSocketAddress addr) { return super.connectionWriteOp(); } @Override - public Future connectionReadOp() { + public RFuture connectionReadOp() { return super.connectionWriteOp(); } diff --git a/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManager.java b/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManager.java index a3342ab90..e80ed8cad 100644 --- a/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManager.java +++ b/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManager.java @@ -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 getConnection(InetSocketAddress addr); + RFuture getConnection(InetSocketAddress addr); int getAvailableClients(); @@ -40,11 +39,11 @@ public interface LoadBalancerManager { ClientConnectionsEntry freeze(String host, int port, FreezeReason freezeReason); - Future add(ClientConnectionsEntry entry); + RFuture add(ClientConnectionsEntry entry); - Future nextConnection(); + RFuture nextConnection(); - Future nextPubSubConnection(); + RFuture nextPubSubConnection(); void returnConnection(RedisConnection connection); diff --git a/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManagerImpl.java b/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManagerImpl.java index 921c8b0dd..e39020e54 100644 --- a/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManagerImpl.java +++ b/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManagerImpl.java @@ -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 add(final ClientConnectionsEntry entry) { - final Promise result = connectionManager.newPromise(); + public RFuture add(final ClientConnectionsEntry entry) { + final RPromise result = connectionManager.newPromise(); FutureListener listener = new FutureListener() { AtomicInteger counter = new AtomicInteger(2); @Override @@ -69,9 +70,9 @@ public class LoadBalancerManagerImpl implements LoadBalancerManager { } }; - Future slaveFuture = slaveConnectionPool.add(entry); + RFuture slaveFuture = slaveConnectionPool.add(entry); slaveFuture.addListener(listener); - Future pubSubFuture = pubSubConnectionPool.add(entry); + RFuture pubSubFuture = pubSubConnectionPool.add(entry); pubSubFuture.addListener(listener); return result; } @@ -136,11 +137,11 @@ public class LoadBalancerManagerImpl implements LoadBalancerManager { return connectionEntry; } - public Future nextPubSubConnection() { + public RFuture nextPubSubConnection() { return pubSubConnectionPool.get(); } - public Future getConnection(InetSocketAddress addr) { + public RFuture 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 nextConnection() { + public RFuture nextConnection() { return slaveConnectionPool.get(); } diff --git a/redisson/src/main/java/org/redisson/connection/pool/ConnectionPool.java b/redisson/src/main/java/org/redisson/connection/pool/ConnectionPool.java index cf1ad64d0..f0bb65715 100644 --- a/redisson/src/main/java/org/redisson/connection/pool/ConnectionPool.java +++ b/redisson/src/main/java/org/redisson/connection/pool/ConnectionPool.java @@ -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 { @@ -58,8 +59,8 @@ abstract class ConnectionPool { this.connectionManager = connectionManager; } - public Future add(final ClientConnectionsEntry entry) { - final Promise promise = connectionManager.newPromise(); + public RFuture add(final ClientConnectionsEntry entry) { + final RPromise promise = connectionManager.newPromise(); promise.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -70,7 +71,7 @@ abstract class ConnectionPool { return promise; } - private void initConnections(final ClientConnectionsEntry entry, final Promise initPromise, boolean checkFreezed) { + private void initConnections(final ClientConnectionsEntry entry, final RPromise initPromise, boolean checkFreezed) { final int minimumIdleSize = getMinimumIdleSize(entry); if (minimumIdleSize == 0 || (checkFreezed && entry.isFreezed())) { @@ -86,7 +87,7 @@ abstract class ConnectionPool { } } - private void createConnection(final boolean checkFreezed, final AtomicInteger requests, final ClientConnectionsEntry entry, final Promise initPromise, + private void createConnection(final boolean checkFreezed, final AtomicInteger requests, final ClientConnectionsEntry entry, final RPromise initPromise, final int minimumIdleSize, final AtomicInteger initializedConnections) { if ((checkFreezed && entry.isFreezed()) || !tryAcquireConnection(entry)) { @@ -97,7 +98,7 @@ abstract class ConnectionPool { return; } - Future promise = createConnection(entry); + RFuture promise = createConnection(entry); promise.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -135,7 +136,7 @@ abstract class ConnectionPool { return config.getLoadBalancer().getEntry(entries); } - public Future get() { + public RFuture 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 { return connectionManager.newFailedFuture(exception); } - public Future get(ClientConnectionsEntry entry) { + public RFuture 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 { return (T) entry.pollConnection(); } - protected Future connect(ClientConnectionsEntry entry) { - return (Future) entry.connect(); + protected RFuture connect(ClientConnectionsEntry entry) { + return (RFuture) entry.connect(); } - private Future connectTo(ClientConnectionsEntry entry) { + private RFuture connectTo(ClientConnectionsEntry entry) { T conn = poll(entry); if (conn != null) { if (!conn.isActive()) { @@ -201,9 +202,9 @@ abstract class ConnectionPool { return createConnection(entry); } - private Future createConnection(final ClientConnectionsEntry entry) { - final Promise promise = connectionManager.newPromise(); - Future connFuture = connect(entry); + private RFuture createConnection(final ClientConnectionsEntry entry) { + final RPromise promise = connectionManager.newPromise(); + RFuture connFuture = connect(entry); connFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -226,7 +227,7 @@ abstract class ConnectionPool { return promise; } - private void promiseSuccessful(ClientConnectionsEntry entry, Promise promise, T conn) { + private void promiseSuccessful(ClientConnectionsEntry entry, RPromise promise, T conn) { entry.resetFailedAttempts(); if (!promise.trySuccess(conn)) { releaseConnection(entry, conn); @@ -234,12 +235,12 @@ abstract class ConnectionPool { } } - private Future promiseSuccessful(ClientConnectionsEntry entry, T conn) { + private RFuture promiseSuccessful(ClientConnectionsEntry entry, T conn) { entry.resetFailedAttempts(); - return (Future) conn.getAcquireFuture(); + return (RFuture) conn.getAcquireFuture(); } - private void promiseFailure(ClientConnectionsEntry entry, Promise promise, Throwable cause) { + private void promiseFailure(ClientConnectionsEntry entry, RPromise promise, Throwable cause) { if (entry.incFailedAttempts() == config.getFailedAttempts()) { checkForReconnect(entry); } @@ -247,7 +248,7 @@ abstract class ConnectionPool { promise.tryFailure(cause); } - private void promiseFailure(ClientConnectionsEntry entry, Promise promise, T conn) { + private void promiseFailure(ClientConnectionsEntry entry, RPromise promise, T conn) { int attempts = entry.incFailedAttempts(); if (attempts == config.getFailedAttempts()) { checkForReconnect(entry); @@ -261,7 +262,7 @@ abstract class ConnectionPool { promise.tryFailure(cause); } - private Future promiseFailure(ClientConnectionsEntry entry, T conn) { + private RFuture promiseFailure(ClientConnectionsEntry entry, T conn) { int attempts = entry.incFailedAttempts(); if (attempts == config.getFailedAttempts()) { checkForReconnect(entry); @@ -301,7 +302,7 @@ abstract class ConnectionPool { return; } - Future connectionFuture = entry.getClient().connectAsync(); + RFuture connectionFuture = entry.getClient().connectAsync(); connectionFuture.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -332,7 +333,7 @@ abstract class ConnectionPool { if (future.isSuccess() && "PONG".equals(future.getNow())) { entry.resetFailedAttempts(); - Promise promise = connectionManager.newPromise(); + RPromise promise = connectionManager.newPromise(); promise.addListener(new FutureListener() { @Override public void operationComplete(Future future) @@ -362,7 +363,7 @@ abstract class ConnectionPool { }; if (entry.getConfig().getPassword() != null) { - Future temp = c.async(RedisCommands.AUTH, config.getPassword()); + RFuture temp = c.async(RedisCommands.AUTH, config.getPassword()); FutureListener listener = new FutureListener () { @Override public void operationComplete (Future < Void > future)throws Exception { @@ -381,7 +382,7 @@ abstract class ConnectionPool { } private void ping(RedisConnection c, final FutureListener pingListener) { - Future f = c.async(RedisCommands.PING); + RFuture f = c.async(RedisCommands.PING); f.addListener(pingListener); } diff --git a/redisson/src/main/java/org/redisson/connection/pool/PubSubConnectionPool.java b/redisson/src/main/java/org/redisson/connection/pool/PubSubConnectionPool.java index 7efd5d0f0..b0d7de32d 100644 --- a/redisson/src/main/java/org/redisson/connection/pool/PubSubConnectionPool.java +++ b/redisson/src/main/java/org/redisson/connection/pool/PubSubConnectionPool.java @@ -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 { @@ -40,7 +39,7 @@ public class PubSubConnectionPool extends ConnectionPool } @Override - protected Future connect(ClientConnectionsEntry entry) { + protected RFuture connect(ClientConnectionsEntry entry) { return entry.connectPubSub(); } diff --git a/redisson/src/main/java/org/redisson/executor/ExecutorRemoteService.java b/redisson/src/main/java/org/redisson/executor/ExecutorRemoteService.java index 249badd38..e61ec5467 100644 --- a/redisson/src/main/java/org/redisson/executor/ExecutorRemoteService.java +++ b/redisson/src/main/java/org/redisson/executor/ExecutorRemoteService.java @@ -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 addAsync(RBlockingQueue requestQueue, + protected final RFuture addAsync(RBlockingQueue requestQueue, RemoteServiceRequest request, RemotePromise result) { - final Promise promise = commandExecutor.getConnectionManager().newPromise(); - Future future = addAsync(requestQueue, request); + final RPromise promise = commandExecutor.getConnectionManager().newPromise(); + RFuture future = addAsync(requestQueue, request); result.setAddFuture(future); future.addListener(new FutureListener() { diff --git a/redisson/src/main/java/org/redisson/executor/RedissonScheduledFuture.java b/redisson/src/main/java/org/redisson/executor/RedissonScheduledFuture.java index 38f3004bb..4dbf1a7f9 100644 --- a/redisson/src/main/java/org/redisson/executor/RedissonScheduledFuture.java +++ b/redisson/src/main/java/org/redisson/executor/RedissonScheduledFuture.java @@ -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 */ -public class RedissonScheduledFuture extends RedissonFuture implements RScheduledFuture { +public class RedissonScheduledFuture extends PromiseDelegator implements RScheduledFuture { private final long scheduledExecutionTime; private final String taskId; diff --git a/redisson/src/main/java/org/redisson/executor/RemotePromise.java b/redisson/src/main/java/org/redisson/executor/RemotePromise.java index 4dc5f7fba..62781401e 100644 --- a/redisson/src/main/java/org/redisson/executor/RemotePromise.java +++ b/redisson/src/main/java/org/redisson/executor/RemotePromise.java @@ -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 extends PromiseDelegator { private String requestId; - private Future addFuture; + private RFuture addFuture; - public RemotePromise(Promise promise) { + public RemotePromise(RPromise promise) { super(promise); } @@ -41,10 +40,10 @@ public class RemotePromise extends PromiseDelegator { return requestId; } - public void setAddFuture(Future addFuture) { + public void setAddFuture(RFuture addFuture) { this.addFuture = addFuture; } - public Future getAddFuture() { + public RFuture getAddFuture() { return addFuture; } diff --git a/redisson/src/main/java/org/redisson/misc/PromiseDelegator.java b/redisson/src/main/java/org/redisson/misc/PromiseDelegator.java index ee8e88534..9182b5a09 100644 --- a/redisson/src/main/java/org/redisson/misc/PromiseDelegator.java +++ b/redisson/src/main/java/org/redisson/misc/PromiseDelegator.java @@ -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 implements RPromise { - private final Promise promise; + private final RPromise promise; - public PromiseDelegator(Promise promise) { + public PromiseDelegator(RPromise promise) { super(); this.promise = promise; } - public Promise getInnerPromise() { + public RPromise getInnerPromise() { return promise; } - public Promise setSuccess(T result) { + public RPromise setSuccess(T result) { return promise.setSuccess(result); } @@ -68,35 +67,35 @@ public class PromiseDelegator implements RPromise { return promise.setUncancellable(); } - public Promise addListener(GenericFutureListener> listener) { + public RPromise addListener(FutureListener listener) { return promise.addListener(listener); } - public Promise addListeners(GenericFutureListener>... listeners) { + public RPromise addListeners(FutureListener... listeners) { return promise.addListeners(listeners); } - public Promise removeListener(GenericFutureListener> listener) { + public RPromise removeListener(FutureListener listener) { return promise.removeListener(listener); } - public Promise removeListeners(GenericFutureListener>... listeners) { + public RPromise removeListeners(FutureListener... listeners) { return promise.removeListeners(listeners); } - public Promise await() throws InterruptedException { + public RPromise await() throws InterruptedException { return promise.await(); } - public Promise awaitUninterruptibly() { + public RPromise awaitUninterruptibly() { return promise.awaitUninterruptibly(); } - public Promise sync() throws InterruptedException { + public RPromise sync() throws InterruptedException { return promise.sync(); } - public Promise syncUninterruptibly() { + public RPromise syncUninterruptibly() { return promise.syncUninterruptibly(); } diff --git a/redisson/src/main/java/org/redisson/misc/RPromise.java b/redisson/src/main/java/org/redisson/misc/RPromise.java index 5050f7cfc..100907e78 100644 --- a/redisson/src/main/java/org/redisson/misc/RPromise.java +++ b/redisson/src/main/java/org/redisson/misc/RPromise.java @@ -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 */ -public interface RPromise extends Promise, RFuture { +public interface RPromise extends RFuture { + + /** + * Marks this future as a success and notifies all + * listeners. + * + * If it is success or failed already it will throw an {@link IllegalStateException}. + */ + RPromise 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 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 addListener(FutureListener listener); + + @Override + RPromise addListeners(FutureListener... listeners); + + @Override + RPromise removeListener(FutureListener listener); + + @Override + RPromise removeListeners(FutureListener... listeners); + + @Override + RPromise await() throws InterruptedException; + + @Override + RPromise awaitUninterruptibly(); + + @Override + RPromise sync() throws InterruptedException; + + @Override + RPromise syncUninterruptibly(); } diff --git a/redisson/src/main/java/org/redisson/misc/RedissonFuture.java b/redisson/src/main/java/org/redisson/misc/RedissonFuture.java index cff4d2d78..e41bce293 100644 --- a/redisson/src/main/java/org/redisson/misc/RedissonFuture.java +++ b/redisson/src/main/java/org/redisson/misc/RedissonFuture.java @@ -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 implements RFuture { return future.cause(); } - public Future addListener(GenericFutureListener> listener) { - return future.addListener(listener); + public RFuture addListener(FutureListener listener) { + future.addListener(listener); + return this; } - public Future addListeners(GenericFutureListener>... listeners) { - return future.addListeners(listeners); + public RFuture addListeners(FutureListener... listeners) { + future.addListeners(listeners); + return this; } - public Future removeListener(GenericFutureListener> listener) { - return future.removeListener(listener); + public RFuture removeListener(FutureListener listener) { + future.removeListener(listener); + return this; } - public Future removeListeners(GenericFutureListener>... listeners) { - return future.removeListeners(listeners); + public RFuture removeListeners(FutureListener... listeners) { + future.removeListeners(listeners); + return this; } - public Future sync() throws InterruptedException { - return future.sync(); + public RFuture sync() throws InterruptedException { + future.sync(); + return this; } - public Future syncUninterruptibly() { - return future.syncUninterruptibly(); + public RFuture syncUninterruptibly() { + future.syncUninterruptibly(); + return this; } - public Future await() throws InterruptedException { - return future.await(); + public RFuture await() throws InterruptedException { + future.await(); + return this; } - public Future awaitUninterruptibly() { - return future.awaitUninterruptibly(); + public RFuture awaitUninterruptibly() { + future.awaitUninterruptibly(); + return this; } public boolean await(long timeout, TimeUnit unit) throws InterruptedException { diff --git a/redisson/src/main/java/org/redisson/misc/RedissonPromise.java b/redisson/src/main/java/org/redisson/misc/RedissonPromise.java index 814395e47..d0c2c2902 100644 --- a/redisson/src/main/java/org/redisson/misc/RedissonPromise.java +++ b/redisson/src/main/java/org/redisson/misc/RedissonPromise.java @@ -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 */ -public class RedissonPromise extends PromiseDelegator implements RPromise { +public class RedissonPromise implements RPromise { + private final Promise promise; + public RedissonPromise(Promise promise) { - super(promise); + this.promise = promise; + } + + public Promise getInnerPromise() { + return promise; + } + + @Override + public RPromise 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 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 addListener(FutureListener listener) { + promise.addListener(listener); + return this; + } + + @Override + public RPromise addListeners(FutureListener... listeners) { + promise.addListeners(listeners); + return this; + } + + @Override + public RPromise removeListener(FutureListener listener) { + promise.removeListener(listener); + return this; + } + + @Override + public RPromise removeListeners(FutureListener... listeners) { + promise.removeListeners(listeners); + return this; + } + + @Override + public RPromise await() throws InterruptedException { + promise.await(); + return this; + } + + @Override + public RPromise awaitUninterruptibly() { + promise.awaitUninterruptibly(); + return this; + } + + @Override + public RPromise sync() throws InterruptedException { + promise.sync(); + return this; + } + + @Override + public RPromise 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); } } diff --git a/redisson/src/main/java/org/redisson/pubsub/CountDownLatchPubSub.java b/redisson/src/main/java/org/redisson/pubsub/CountDownLatchPubSub.java index 998bfd6d4..11ab3dd9a 100644 --- a/redisson/src/main/java/org/redisson/pubsub/CountDownLatchPubSub.java +++ b/redisson/src/main/java/org/redisson/pubsub/CountDownLatchPubSub.java @@ -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 { @Override - protected RedissonCountDownLatchEntry createEntry(Promise newPromise) { + protected RedissonCountDownLatchEntry createEntry(RPromise newPromise) { return new RedissonCountDownLatchEntry(newPromise); } diff --git a/redisson/src/main/java/org/redisson/pubsub/LockPubSub.java b/redisson/src/main/java/org/redisson/pubsub/LockPubSub.java index 04ed5b47c..cbc572741 100644 --- a/redisson/src/main/java/org/redisson/pubsub/LockPubSub.java +++ b/redisson/src/main/java/org/redisson/pubsub/LockPubSub.java @@ -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 { public static final Long unlockMessage = 0L; @Override - protected RedissonLockEntry createEntry(Promise newPromise) { + protected RedissonLockEntry createEntry(RPromise newPromise) { return new RedissonLockEntry(newPromise); } diff --git a/redisson/src/main/java/org/redisson/pubsub/PublishSubscribe.java b/redisson/src/main/java/org/redisson/pubsub/PublishSubscribe.java index eeb60fd75..801902d46 100644 --- a/redisson/src/main/java/org/redisson/pubsub/PublishSubscribe.java +++ b/redisson/src/main/java/org/redisson/pubsub/PublishSubscribe.java @@ -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> { @@ -58,10 +58,10 @@ abstract class PublishSubscribe> { return entries.get(entryName); } - public Future subscribe(final String entryName, final String channelName, final ConnectionManager connectionManager) { + public RFuture subscribe(final String entryName, final String channelName, final ConnectionManager connectionManager) { final AtomicReference listenerHolder = new AtomicReference(); final AsyncSemaphore semaphore = connectionManager.getSemaphore(channelName); - final Promise newPromise = new PromiseDelegator(connectionManager.newPromise()) { + final RPromise newPromise = new PromiseDelegator(connectionManager.newPromise()) { @Override public boolean cancel(boolean mayInterruptIfRunning) { return semaphore.remove(listenerHolder.get()); @@ -101,7 +101,7 @@ abstract class PublishSubscribe> { return newPromise; } - protected abstract E createEntry(Promise newPromise); + protected abstract E createEntry(RPromise newPromise); protected abstract void onMessage(E value, Long message); diff --git a/redisson/src/main/java/org/redisson/pubsub/SemaphorePubSub.java b/redisson/src/main/java/org/redisson/pubsub/SemaphorePubSub.java index 84ca12807..6fb3bde77 100644 --- a/redisson/src/main/java/org/redisson/pubsub/SemaphorePubSub.java +++ b/redisson/src/main/java/org/redisson/pubsub/SemaphorePubSub.java @@ -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 { @Override - protected RedissonLockEntry createEntry(Promise newPromise) { + protected RedissonLockEntry createEntry(RPromise newPromise) { return new RedissonLockEntry(newPromise); } diff --git a/redisson/src/main/java/org/redisson/pubsub/TransferListener.java b/redisson/src/main/java/org/redisson/pubsub/TransferListener.java index d1cfb0031..52728ee12 100644 --- a/redisson/src/main/java/org/redisson/pubsub/TransferListener.java +++ b/redisson/src/main/java/org/redisson/pubsub/TransferListener.java @@ -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 implements FutureListener { - private Promise promise; + private RPromise promise; - public TransferListener(Promise promise) { + public TransferListener(RPromise promise) { super(); this.promise = promise; } diff --git a/redisson/src/main/java/org/redisson/reactive/NettyFuturePublisher.java b/redisson/src/main/java/org/redisson/reactive/NettyFuturePublisher.java index 971a277e4..1bdda4f80 100644 --- a/redisson/src/main/java/org/redisson/reactive/NettyFuturePublisher.java +++ b/redisson/src/main/java/org/redisson/reactive/NettyFuturePublisher.java @@ -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 extends Stream { - private final Future that; + private final RFuture that; - public NettyFuturePublisher(Future that) { + public NettyFuturePublisher(RFuture that) { this.that = that; } diff --git a/redisson/src/main/java/org/redisson/reactive/RedissonListReactive.java b/redisson/src/main/java/org/redisson/reactive/RedissonListReactive.java index df4fc68b0..b9dd297b1 100644 --- a/redisson/src/main/java/org/redisson/reactive/RedissonListReactive.java +++ b/redisson/src/main/java/org/redisson/reactive/RedissonListReactive.java @@ -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 extends RedissonExpirableReactive implement @Override public Publisher 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.singletonList(getName()), index); + return reactive(instance.removeAsync(index)); } @Override @@ -277,38 +264,14 @@ public class RedissonListReactive extends RedissonExpirableReactive implement return reactive(instance.containsAsync(o)); } - private Publisher indexOf(Object o, Convertor convertor) { - return commandExecutor.evalReadReactive(getName(), codec, new RedisCommand("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.singletonList(getName()), o); - } - @Override public Publisher indexOf(Object o) { - return indexOf(o, new LongReplayConvertor()); + return reactive(instance.indexOfAsync(o, new LongReplayConvertor())); } @Override public Publisher lastIndexOf(Object o) { - return commandExecutor.evalReadReactive(getName(), codec, new RedisCommand("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.singletonList(getName()), o); + return reactive(instance.lastIndexOfAsync(o, new LongReplayConvertor())); } @Override diff --git a/redisson/src/main/java/org/redisson/reactive/RedissonObjectReactive.java b/redisson/src/main/java/org/redisson/reactive/RedissonObjectReactive.java index 7931af3de..6c4d70970 100644 --- a/redisson/src/main/java/org/redisson/reactive/RedissonObjectReactive.java +++ b/redisson/src/main/java/org/redisson/reactive/RedissonObjectReactive.java @@ -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 Publisher reactive(Future future) { + public Publisher reactive(RFuture future) { return commandExecutor.reactive(future); } diff --git a/redisson/src/main/java/org/redisson/reactive/RedissonPatternTopicReactive.java b/redisson/src/main/java/org/redisson/reactive/RedissonPatternTopicReactive.java index 744de3995..00a8140a3 100644 --- a/redisson/src/main/java/org/redisson/reactive/RedissonPatternTopicReactive.java +++ b/redisson/src/main/java/org/redisson/reactive/RedissonPatternTopicReactive.java @@ -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 implements RPatternTopicReactive @Override public Publisher addListener(PatternStatusListener listener) { - Promise promise = commandExecutor.getConnectionManager().newPromise(); + RPromise promise = commandExecutor.getConnectionManager().newPromise(); addListener(new PubSubPatternStatusListener(listener, name), promise); return new NettyFuturePublisher(promise); }; @Override public Publisher addListener(PatternMessageListener listener) { - Promise promise = commandExecutor.getConnectionManager().newPromise(); + RPromise promise = commandExecutor.getConnectionManager().newPromise(); PubSubPatternMessageListener pubSubListener = new PubSubPatternMessageListener(listener, name); addListener(pubSubListener, promise); return new NettyFuturePublisher(promise); } - private void addListener(final RedisPubSubListener pubSubListener, final Promise promise) { - Future future = commandExecutor.getConnectionManager().psubscribe(name, codec, pubSubListener); + private void addListener(final RedisPubSubListener pubSubListener, final RPromise promise) { + RFuture future = commandExecutor.getConnectionManager().psubscribe(name, codec, pubSubListener); future.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { diff --git a/redisson/src/main/java/org/redisson/reactive/RedissonTopicReactive.java b/redisson/src/main/java/org/redisson/reactive/RedissonTopicReactive.java index 326e38956..71ce5f70a 100644 --- a/redisson/src/main/java/org/redisson/reactive/RedissonTopicReactive.java +++ b/redisson/src/main/java/org/redisson/reactive/RedissonTopicReactive.java @@ -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 implements RTopicReactive { } private Publisher addListener(final RedisPubSubListener pubSubListener) { - final Promise promise = commandExecutor.getConnectionManager().newPromise(); - Future future = commandExecutor.getConnectionManager().subscribe(codec, name, pubSubListener); + final RPromise promise = commandExecutor.getConnectionManager().newPromise(); + RFuture future = commandExecutor.getConnectionManager().subscribe(codec, name, pubSubListener); future.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { diff --git a/redisson/src/test/java/org/redisson/BaseTest.java b/redisson/src/test/java/org/redisson/BaseTest.java index 4430f711a..e22c1df61 100644 --- a/redisson/src/test/java/org/redisson/BaseTest.java +++ b/redisson/src/test/java/org/redisson/BaseTest.java @@ -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(); } } diff --git a/redisson/src/test/java/org/redisson/RedisClientTest.java b/redisson/src/test/java/org/redisson/RedisClientTest.java index 5e68d80d3..9419e07ee 100644 --- a/redisson/src/test/java/org/redisson/RedisClientTest.java +++ b/redisson/src/test/java/org/redisson/RedisClientTest.java @@ -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 f = c.connectAsync(); + RFuture f = c.connectAsync(); final CountDownLatch l = new CountDownLatch(1); f.addListener((FutureListener) future -> { RedisConnection conn = future.get(); @@ -143,7 +145,7 @@ public class RedisClientTest { CommandData cmd4 = conn.create(null, RedisCommands.PING); commands.add(cmd4); - Promise p = c.getBootstrap().group().next().newPromise(); + RPromise p = new RedissonPromise(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 p = c.getBootstrap().group().next().newPromise(); + RPromise p = new RedissonPromise(ImmediateEventExecutor.INSTANCE.newPromise()); conn.send(new CommandsData(p, commands)); for (CommandData commandData : commands) { diff --git a/redisson/src/test/java/org/redisson/RedissonBatchTest.java b/redisson/src/test/java/org/redisson/RedissonBatchTest.java index 1576f5ee7..32ebce925 100644 --- a/redisson/src/test/java/org/redisson/RedissonBatchTest.java +++ b/redisson/src/test/java/org/redisson/RedissonBatchTest.java @@ -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 val1 = b.getMap("test1").getAsync("1"); - Future val2 = b.getMap("test2", StringCodec.INSTANCE).getAsync("21"); + RFuture val1 = b.getMap("test1").getAsync("1"); + RFuture 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> futures = new CopyOnWriteArrayList<>(); + final List> 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 f1 = batch.getAtomicLong("test" + ind).addAndGetAsync(j); + RFuture 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 a = futures.get(i); + RFuture a = futures.get(i); Assert.assertEquals(a.getNow(), element); i++; } diff --git a/redisson/src/test/java/org/redisson/RedissonBlockingQueueTest.java b/redisson/src/test/java/org/redisson/RedissonBlockingQueueTest.java index 394fac947..32f29757a 100644 --- a/redisson/src/test/java/org/redisson/RedissonBlockingQueueTest.java +++ b/redisson/src/test/java/org/redisson/RedissonBlockingQueueTest.java @@ -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 queue1 = redisson.getBlockingQueue("queue:pollTimeout"); - Future f = queue1.pollAsync(5, TimeUnit.SECONDS); + RFuture 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 queue1 = redisson.getBlockingQueue("queue:pollany"); - Future f = queue1.pollAsync(10, TimeUnit.SECONDS); + RFuture 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 queue1 = redisson.getBlockingQueue("testTakeReattach"); - Future f = queue1.takeAsync(); + RFuture 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 queue1 = redisson.getBlockingQueue("testTakeAsyncCancel"); for (int i = 0; i < 10; i++) { - Future f = queue1.takeAsync(); + RFuture 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 queue1 = redisson.getBlockingQueue("queue:pollany"); for (int i = 0; i < 10; i++) { - Future f = queue1.pollAsync(1, TimeUnit.SECONDS); + RFuture f = queue1.pollAsync(1, TimeUnit.SECONDS); f.cancel(true); } assertThat(queue1.add(1)).isTrue(); diff --git a/redisson/src/test/java/org/redisson/RedissonBoundedBlockingQueueTest.java b/redisson/src/test/java/org/redisson/RedissonBoundedBlockingQueueTest.java index 0cf850dad..628362b11 100644 --- a/redisson/src/test/java/org/redisson/RedissonBoundedBlockingQueueTest.java +++ b/redisson/src/test/java/org/redisson/RedissonBoundedBlockingQueueTest.java @@ -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 queue1 = redisson.getBoundedBlockingQueue("bounded-queue:pollTimeout"); assertThat(queue1.trySetCapacity(5)).isTrue(); - Future f = queue1.pollAsync(5, TimeUnit.SECONDS); + RFuture 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 queue1 = redisson.getBoundedBlockingQueue("queue:pollany"); - Future f = queue1.pollAsync(10, TimeUnit.SECONDS); + RFuture f = queue1.pollAsync(10, TimeUnit.SECONDS); f.await(1, TimeUnit.SECONDS); runner.stop(); @@ -346,7 +347,7 @@ public class RedissonBoundedBlockingQueueTest extends BaseTest { RBoundedBlockingQueue queue1 = redisson.getBoundedBlockingQueue("testTakeReattach"); assertThat(queue1.trySetCapacity(15)).isTrue(); - Future f = queue1.takeAsync(); + RFuture f = queue1.takeAsync(); f.await(1, TimeUnit.SECONDS); runner.stop(); @@ -380,7 +381,7 @@ public class RedissonBoundedBlockingQueueTest extends BaseTest { RBoundedBlockingQueue queue1 = redisson.getBoundedBlockingQueue("testTakeAsyncCancel"); assertThat(queue1.trySetCapacity(15)).isTrue(); for (int i = 0; i < 10; i++) { - Future f = queue1.takeAsync(); + RFuture f = queue1.takeAsync(); f.cancel(true); } assertThat(queue1.add(1)).isTrue(); @@ -401,7 +402,7 @@ public class RedissonBoundedBlockingQueueTest extends BaseTest { RBoundedBlockingQueue queue1 = redisson.getBoundedBlockingQueue("queue:pollany"); assertThat(queue1.trySetCapacity(15)).isTrue(); for (int i = 0; i < 10; i++) { - Future f = queue1.pollAsync(1, TimeUnit.SECONDS); + RFuture f = queue1.pollAsync(1, TimeUnit.SECONDS); f.cancel(true); } assertThat(queue1.add(1)).isTrue(); diff --git a/redisson/src/test/java/org/redisson/RedissonMapCacheTest.java b/redisson/src/test/java/org/redisson/RedissonMapCacheTest.java index fce98ee55..1e64420ca 100644 --- a/redisson/src/test/java/org/redisson/RedissonMapCacheTest.java +++ b/redisson/src/test/java/org/redisson/RedissonMapCacheTest.java @@ -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 map = redisson.getMapCache("simple"); - Future future = map.putAsync(2, 3); + RFuture future = map.putAsync(2, 3); Assert.assertNull(future.get()); Assert.assertEquals((Integer) 3, map.get(2)); - Future future1 = map.putAsync(2, 4); + RFuture future1 = map.putAsync(2, 4); Assert.assertEquals((Integer) 3, future1.get()); Assert.assertEquals((Integer) 4, map.get(2)); diff --git a/redisson/src/test/java/org/redisson/RedissonMapTest.java b/redisson/src/test/java/org/redisson/RedissonMapTest.java index 9b2775650..c57434c73 100644 --- a/redisson/src/test/java/org/redisson/RedissonMapTest.java +++ b/redisson/src/test/java/org/redisson/RedissonMapTest.java @@ -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 map = redisson.getMap("simple"); - Future future = map.putAsync(2, 3); + RFuture future = map.putAsync(2, 3); Assert.assertNull(future.get()); Assert.assertEquals((Integer) 3, map.get(2)); - Future future1 = map.putAsync(2, 4); + RFuture future1 = map.putAsync(2, 4); Assert.assertEquals((Integer) 3, future1.get()); Assert.assertEquals((Integer) 4, map.get(2)); diff --git a/redisson/src/test/java/org/redisson/RedissonRemoteServiceTest.java b/redisson/src/test/java/org/redisson/RedissonRemoteServiceTest.java index 6d0fae8cb..efc06f454 100644 --- a/redisson/src/test/java/org/redisson/RedissonRemoteServiceTest.java +++ b/redisson/src/test/java/org/redisson/RedissonRemoteServiceTest.java @@ -198,7 +198,7 @@ public class RedissonRemoteServiceTest extends BaseTest { RedissonClient r2 = createInstance(); RemoteInterfaceAsync ri = r2.getRemoteSerivce().get(RemoteInterfaceAsync.class); - Future f = ri.cancelMethod(); + RFuture 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 f = ri.voidMethod("someName", 100L); + RFuture f = ri.voidMethod("someName", 100L); f.sync(); - Future resFuture = ri.resultMethod(100L); + RFuture 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 f = ri.voidMethod("someName", 100L); + RFuture f = ri.voidMethod("someName", 100L); f.sync(); - Future resFuture = ri.resultMethod(100L); + RFuture resFuture = ri.resultMethod(100L); resFuture.sync(); assertThat(resFuture.getNow()).isEqualTo(200); diff --git a/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java b/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java index ca0a9aa61..de17bdf09 100644 --- a/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java +++ b/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java @@ -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 set = redisson.getScoredSortedSet("simple"); - Future future = set.addAsync(0.323, 2); + RFuture future = set.addAsync(0.323, 2); Assert.assertTrue(future.get()); - Future future2 = set.addAsync(0.323, 2); + RFuture future2 = set.addAsync(0.323, 2); Assert.assertFalse(future2.get()); Assert.assertTrue(set.contains(2)); diff --git a/redisson/src/test/java/org/redisson/RedissonScriptTest.java b/redisson/src/test/java/org/redisson/RedissonScriptTest.java index 776273fab..e67e676de 100644 --- a/redisson/src/test/java/org/redisson/RedissonScriptTest.java +++ b/redisson/src/test/java/org/redisson/RedissonScriptTest.java @@ -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> res = script.evalAsync(RScript.Mode.READ_ONLY, "return {1,2,3.3333,'\"foo\"',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList()); + RFuture> 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 r = redisson.getScript().scriptLoadAsync("return redis.call('get', 'foo')"); + RFuture 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 r1 = redisson.getScript().evalShaAsync(Mode.READ_ONLY, "282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList()); + RFuture r1 = redisson.getScript().evalShaAsync(Mode.READ_ONLY, "282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList()); Assert.assertEquals("bar", r1.awaitUninterruptibly().getNow()); } diff --git a/redisson/src/test/java/org/redisson/RedissonSetTest.java b/redisson/src/test/java/org/redisson/RedissonSetTest.java index eb620ed5d..5a26005cd 100644 --- a/redisson/src/test/java/org/redisson/RedissonSetTest.java +++ b/redisson/src/test/java/org/redisson/RedissonSetTest.java @@ -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 set = redisson.getSet("simple"); - Future future = set.addAsync(2); + RFuture future = set.addAsync(2); Assert.assertTrue(future.get()); Assert.assertTrue(set.contains(2)); diff --git a/redisson/src/test/java/org/redisson/RedissonSortedSetTest.java b/redisson/src/test/java/org/redisson/RedissonSortedSetTest.java index 381852d08..a4078b993 100644 --- a/redisson/src/test/java/org/redisson/RedissonSortedSetTest.java +++ b/redisson/src/test/java/org/redisson/RedissonSortedSetTest.java @@ -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 set = redisson.getSortedSet("simple"); - Future future = set.addAsync(2); + RFuture future = set.addAsync(2); Assert.assertTrue(future.get()); Assert.assertTrue(set.contains(2)); diff --git a/redisson/src/test/java/org/redisson/TimeoutTest.java b/redisson/src/test/java/org/redisson/TimeoutTest.java index b5faa2025..d6311e127 100644 --- a/redisson/src/test/java/org/redisson/TimeoutTest.java +++ b/redisson/src/test/java/org/redisson/TimeoutTest.java @@ -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 map = redisson.getMap("simple"); - List> futures = new ArrayList>(); + List> futures = new ArrayList<>(); for (int i = 0; i < 1000; i++) { - Future future = map.putAsync(i, i*1000); + RFuture future = map.putAsync(i, i*1000); Thread.sleep(1000); futures.add(future); System.out.println(i); } - for (Future future : futures) { + for (RFuture future : futures) { future.get(); } @@ -80,19 +80,19 @@ public class TimeoutTest extends BaseTest { // @Test public void testGetAsyncTimeout() throws InterruptedException, ExecutionException { RMap map = redisson.getMap("simple"); - List> futures = new ArrayList>(); + List> futures = new ArrayList<>(); for (int i = 0; i < 10; i++) { map.put(i, i*1000); } for (int i = 0; i < 10; i++) { - Future future = map.getAsync(i); + RFuture future = map.getAsync(i); Thread.sleep(1000); System.out.println(i); futures.add(future); } - for (Future future : futures) { + for (RFuture future : futures) { Integer res = future.get(); System.out.println(res); }