diff --git a/redisson-tomcat/redisson-tomcat-6/src/main/java/org/redisson/tomcat/RedissonSessionManager.java b/redisson-tomcat/redisson-tomcat-6/src/main/java/org/redisson/tomcat/RedissonSessionManager.java
index 65dd81ac2..ccf7b9411 100644
--- a/redisson-tomcat/redisson-tomcat-6/src/main/java/org/redisson/tomcat/RedissonSessionManager.java
+++ b/redisson-tomcat/redisson-tomcat-6/src/main/java/org/redisson/tomcat/RedissonSessionManager.java
@@ -162,6 +162,12 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
@Override
public void start() throws LifecycleException {
+ redisson = buildClient();
+
+ lifecycle.fireLifecycleEvent(START_EVENT, null);
+ }
+
+ protected RedissonClient buildClient() throws LifecycleException {
Config config = null;
try {
config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
@@ -176,12 +182,10 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
}
try {
- redisson = Redisson.create(config);
+ return Redisson.create(config);
} catch (Exception e) {
throw new LifecycleException(e);
}
-
- lifecycle.fireLifecycleEvent(START_EVENT, null);
}
@Override
diff --git a/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSessionManager.java b/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSessionManager.java
index 45f87b10d..1af366e72 100644
--- a/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSessionManager.java
+++ b/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSessionManager.java
@@ -143,6 +143,13 @@ public class RedissonSessionManager extends ManagerBase {
@Override
protected void startInternal() throws LifecycleException {
super.startInternal();
+
+ redisson = buildClient();
+
+ setState(LifecycleState.STARTING);
+ }
+
+ protected RedissonClient buildClient() throws LifecycleException {
Config config = null;
try {
config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
@@ -166,12 +173,10 @@ public class RedissonSessionManager extends ManagerBase {
throw new IllegalStateException("Unable to initialize codec with ClassLoader parameter", e);
}
- redisson = Redisson.create(config);
+ return Redisson.create(config);
} catch (Exception e) {
throw new LifecycleException(e);
}
-
- setState(LifecycleState.STARTING);
}
@Override
diff --git a/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSessionManager.java b/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSessionManager.java
index 21f71bfea..c170335f7 100644
--- a/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSessionManager.java
+++ b/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSessionManager.java
@@ -144,6 +144,12 @@ public class RedissonSessionManager extends ManagerBase {
@Override
protected void startInternal() throws LifecycleException {
super.startInternal();
+ redisson = buildClient();
+
+ setState(LifecycleState.STARTING);
+ }
+
+ protected RedissonClient buildClient() throws LifecycleException {
Config config = null;
try {
config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
@@ -163,12 +169,10 @@ public class RedissonSessionManager extends ManagerBase {
.newInstance(Thread.currentThread().getContextClassLoader());
config.setCodec(codec);
- redisson = Redisson.create(config);
+ return Redisson.create(config);
} catch (Exception e) {
throw new LifecycleException(e);
}
-
- setState(LifecycleState.STARTING);
}
@Override
diff --git a/redisson/pom.xml b/redisson/pom.xml
index d345336a3..bc8c9ddcf 100644
--- a/redisson/pom.xml
+++ b/redisson/pom.xml
@@ -81,9 +81,9 @@
test
- com.jayway.awaitility
+ org.awaitility
awaitility
- 1.7.0
+ 3.0.0
test
diff --git a/redisson/src/main/java/org/redisson/RedissonBlockingDeque.java b/redisson/src/main/java/org/redisson/RedissonBlockingDeque.java
index b82bb0761..b24d83856 100644
--- a/redisson/src/main/java/org/redisson/RedissonBlockingDeque.java
+++ b/redisson/src/main/java/org/redisson/RedissonBlockingDeque.java
@@ -126,8 +126,7 @@ public class RedissonBlockingDeque extends RedissonDeque implements RBlock
@Override
public V takeLastAndOfferFirstTo(String queueName) throws InterruptedException {
- RFuture res = takeLastAndOfferFirstToAsync(queueName);
- return res.await().getNow();
+ return get(takeLastAndOfferFirstToAsync(queueName));
}
@Override
@@ -194,8 +193,7 @@ public class RedissonBlockingDeque extends RedissonDeque implements RBlock
@Override
public V takeFirst() throws InterruptedException {
- RFuture res = takeFirstAsync();
- return res.await().getNow();
+ return get(takeFirstAsync());
}
@Override
@@ -210,8 +208,7 @@ public class RedissonBlockingDeque extends RedissonDeque implements RBlock
@Override
public V takeLast() throws InterruptedException {
- RFuture res = takeLastAsync();
- return res.await().getNow();
+ return get(takeLastAsync());
}
@Override
@@ -221,8 +218,7 @@ public class RedissonBlockingDeque extends RedissonDeque implements RBlock
@Override
public V pollFirstFromAny(long timeout, TimeUnit unit, String ... queueNames) throws InterruptedException {
- RFuture res = pollFirstFromAnyAsync(timeout, unit, queueNames);
- return res.await().getNow();
+ return get(pollFirstFromAnyAsync(timeout, unit, queueNames));
}
@Override
@@ -232,8 +228,7 @@ public class RedissonBlockingDeque extends RedissonDeque implements RBlock
@Override
public V pollLastFromAny(long timeout, TimeUnit unit, String ... queueNames) throws InterruptedException {
- RFuture res = pollLastFromAnyAsync(timeout, unit, queueNames);
- return res.await().getNow();
+ return get(pollLastFromAnyAsync(timeout, unit, queueNames));
}
@Override
@@ -249,8 +244,7 @@ public class RedissonBlockingDeque extends RedissonDeque implements RBlock
@Override
public V pollFirst(long timeout, TimeUnit unit) throws InterruptedException {
- RFuture res = pollFirstAsync(timeout, unit);
- return res.await().getNow();
+ return get(pollFirstAsync(timeout, unit));
}
@Override
@@ -260,8 +254,7 @@ public class RedissonBlockingDeque extends RedissonDeque implements RBlock
@Override
public V pollLast(long timeout, TimeUnit unit) throws InterruptedException {
- RFuture res = pollLastAsync(timeout, unit);
- return res.await().getNow();
+ return get(pollLastAsync(timeout, unit));
}
}
\ No newline at end of file
diff --git a/redisson/src/main/java/org/redisson/RedissonBlockingQueue.java b/redisson/src/main/java/org/redisson/RedissonBlockingQueue.java
index 4f518e681..3809ade4d 100644
--- a/redisson/src/main/java/org/redisson/RedissonBlockingQueue.java
+++ b/redisson/src/main/java/org/redisson/RedissonBlockingQueue.java
@@ -79,8 +79,7 @@ public class RedissonBlockingQueue extends RedissonQueue implements RBlock
*/
@Override
public V take() throws InterruptedException {
- RFuture res = takeAsync();
- return res.await().getNow();
+ return get(takeAsync());
}
@Override
@@ -94,8 +93,7 @@ public class RedissonBlockingQueue extends RedissonQueue implements RBlock
*/
@Override
public V poll(long timeout, TimeUnit unit) throws InterruptedException {
- RFuture res = pollAsync(timeout, unit);
- return res.await().getNow();
+ return get(pollAsync(timeout, unit));
}
/*
@@ -104,8 +102,7 @@ public class RedissonBlockingQueue extends RedissonQueue implements RBlock
*/
@Override
public V pollFromAny(long timeout, TimeUnit unit, String ... queueNames) throws InterruptedException {
- RFuture res = pollFromAnyAsync(timeout, unit, queueNames);
- return res.await().getNow();
+ return get(pollFromAnyAsync(timeout, unit, queueNames));
}
/*
@@ -130,14 +127,12 @@ public class RedissonBlockingQueue extends RedissonQueue implements RBlock
@Override
public V pollLastAndOfferFirstTo(String queueName, long timeout, TimeUnit unit) throws InterruptedException {
- RFuture res = pollLastAndOfferFirstToAsync(queueName, timeout, unit);
- return res.await().getNow();
+ return get(pollLastAndOfferFirstToAsync(queueName, timeout, unit));
}
@Override
public V takeLastAndOfferFirstTo(String queueName) throws InterruptedException {
- RFuture res = takeLastAndOfferFirstToAsync(queueName);
- return res.await().getNow();
+ return get(takeLastAndOfferFirstToAsync(queueName));
}
@Override
diff --git a/redisson/src/main/java/org/redisson/RedissonBoundedBlockingQueue.java b/redisson/src/main/java/org/redisson/RedissonBoundedBlockingQueue.java
index f754571a3..b4231f0d6 100644
--- a/redisson/src/main/java/org/redisson/RedissonBoundedBlockingQueue.java
+++ b/redisson/src/main/java/org/redisson/RedissonBoundedBlockingQueue.java
@@ -31,7 +31,6 @@ import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandExecutor;
import org.redisson.connection.decoder.ListDrainToDecoder;
-import org.redisson.misc.PromiseDelegator;
import org.redisson.misc.RPromise;
import org.redisson.misc.RedissonPromise;
import org.redisson.pubsub.SemaphorePubSub;
@@ -256,8 +255,7 @@ public class RedissonBoundedBlockingQueue extends RedissonQueue implements
@Override
public V takeLastAndOfferFirstTo(String queueName) throws InterruptedException {
- RFuture res = takeLastAndOfferFirstToAsync(queueName);
- return res.await().getNow();
+ return get(takeLastAndOfferFirstToAsync(queueName));
}
@Override
diff --git a/redisson/src/main/java/org/redisson/RedissonReadLock.java b/redisson/src/main/java/org/redisson/RedissonReadLock.java
index 4bf5f770b..096a335ac 100644
--- a/redisson/src/main/java/org/redisson/RedissonReadLock.java
+++ b/redisson/src/main/java/org/redisson/RedissonReadLock.java
@@ -53,6 +53,10 @@ public class RedissonReadLock extends RedissonLock implements RLock {
return super.getLockName(threadId) + ":write";
}
+ String getReadWriteTimeoutNamePrefix(long threadId) {
+ return suffixName(getName(), getLockName(threadId)) + ":rwlock_timeout";
+ }
+
@Override
RFuture tryLockInnerAsync(long leaseTime, TimeUnit unit, long threadId, RedisStrictCommand command) {
internalLockLeaseTime = unit.toMillis(leaseTime);
@@ -62,25 +66,27 @@ public class RedissonReadLock extends RedissonLock implements RLock {
"if (mode == false) then " +
"redis.call('hset', KEYS[1], 'mode', 'read'); " +
"redis.call('hset', KEYS[1], ARGV[2], 1); " +
- "redis.call('set', KEYS[1] .. ':' .. ARGV[2] .. ':rwlock_timeout:1', 1); " +
- "redis.call('pexpire', KEYS[1] .. ':' .. ARGV[2] .. ':rwlock_timeout:1', ARGV[1]); " +
+ "redis.call('set', KEYS[2] .. ':1', 1); " +
+ "redis.call('pexpire', KEYS[2] .. ':1', ARGV[1]); " +
"redis.call('pexpire', KEYS[1], ARGV[1]); " +
"return nil; " +
"end; " +
"if (mode == 'read') or (mode == 'write' and redis.call('hexists', KEYS[1], ARGV[3]) == 1) then " +
"local ind = redis.call('hincrby', KEYS[1], ARGV[2], 1); " +
- "local key = KEYS[1] .. ':' .. ARGV[2] .. ':rwlock_timeout:' .. ind;" +
+ "local key = KEYS[2] .. ':' .. ind;" +
"redis.call('set', key, 1); " +
"redis.call('pexpire', key, ARGV[1]); " +
"redis.call('pexpire', KEYS[1], ARGV[1]); " +
"return nil; " +
"end;" +
"return redis.call('pttl', KEYS[1]);",
- Arrays.