Merge branch 'master' into 3.0.0

pull/1933/head
Nikita Koksharov 6 years ago
commit 31b38027d9

@ -18,6 +18,8 @@ package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -76,13 +78,52 @@ public class RedissonSession extends StandardSession {
@Override
public Object getAttribute(String name) {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException(sm.getString("standardSession.getAttribute.ise"));
}
if (name == null) {
return null;
}
return map.get(name);
}
return super.getAttribute(name);
}
@Override
public Enumeration<String> getAttributeNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
return Collections.enumeration(map.readAllKeySet());
}
return super.getAttributeNames();
}
@Override
public String[] getValueNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
Set<String> keys = map.readAllKeySet();
return keys.toArray(new String[keys.size()]);
}
return super.getValueNames();
}
public void delete() {
if (map == null) {
map = redissonManager.getMap(id);
}
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));

@ -18,6 +18,8 @@ package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -76,13 +78,52 @@ public class RedissonSession extends StandardSession {
@Override
public Object getAttribute(String name) {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException(sm.getString("standardSession.getAttribute.ise"));
}
if (name == null) {
return null;
}
return map.get(name);
}
return super.getAttribute(name);
}
@Override
public Enumeration<String> getAttributeNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
return Collections.enumeration(map.readAllKeySet());
}
return super.getAttributeNames();
}
@Override
public String[] getValueNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
Set<String> keys = map.readAllKeySet();
return keys.toArray(new String[keys.size()]);
}
return super.getValueNames();
}
public void delete() {
if (map == null) {
map = redissonManager.getMap(id);
}
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));

@ -18,6 +18,8 @@ package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -76,13 +78,52 @@ public class RedissonSession extends StandardSession {
@Override
public Object getAttribute(String name) {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException(sm.getString("standardSession.getAttribute.ise"));
}
if (name == null) {
return null;
}
return map.get(name);
}
return super.getAttribute(name);
}
@Override
public Enumeration<String> getAttributeNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
return Collections.enumeration(map.readAllKeySet());
}
return super.getAttributeNames();
}
@Override
public String[] getValueNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
Set<String> keys = map.readAllKeySet();
return keys.toArray(new String[keys.size()]);
}
return super.getValueNames();
}
public void delete() {
if (map == null) {
map = redissonManager.getMap(id);
}
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));

@ -18,6 +18,8 @@ package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -76,13 +78,52 @@ public class RedissonSession extends StandardSession {
@Override
public Object getAttribute(String name) {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException(sm.getString("standardSession.getAttribute.ise"));
}
if (name == null) {
return null;
}
return map.get(name);
}
return super.getAttribute(name);
}
@Override
public Enumeration<String> getAttributeNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
return Collections.enumeration(map.readAllKeySet());
}
return super.getAttributeNames();
}
@Override
public String[] getValueNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
Set<String> keys = map.readAllKeySet();
return keys.toArray(new String[keys.size()]);
}
return super.getValueNames();
}
public void delete() {
if (map == null) {
map = redissonManager.getMap(id);
}
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));

@ -78,6 +78,10 @@ public class RedissonMultiLock implements Lock {
}
public RFuture<Void> lockAsync(long leaseTime, TimeUnit unit) {
return lockAsync(leaseTime, unit, Thread.currentThread().getId());
}
public RFuture<Void> lockAsync(long leaseTime, TimeUnit unit, long threadId) {
long baseWaitTime = locks.size() * 1500;
long waitTime = -1;
if (leaseTime == -1) {
@ -93,14 +97,14 @@ public class RedissonMultiLock implements Lock {
waitTime = ThreadLocalRandom.current().nextLong(baseWaitTime, waitTime);
}
}
RPromise<Void> result = new RedissonPromise<Void>();
tryLockAsync(leaseTime, TimeUnit.MILLISECONDS, waitTime, result);
tryLockAsync(threadId, leaseTime, TimeUnit.MILLISECONDS, waitTime, result);
return result;
}
protected void tryLockAsync(final long leaseTime, final TimeUnit unit, final long waitTime, final RPromise<Void> result) {
tryLockAsync(waitTime, leaseTime, unit).addListener(new FutureListener<Boolean>() {
protected void tryLockAsync(final long threadId, final long leaseTime, final TimeUnit unit, final long waitTime, final RPromise<Void> result) {
tryLockAsync(waitTime, leaseTime, unit, threadId).addListener(new FutureListener<Boolean>() {
@Override
public void operationComplete(Future<Boolean> future) throws Exception {
if (!future.isSuccess()) {
@ -111,7 +115,7 @@ public class RedissonMultiLock implements Lock {
if (future.getNow()) {
result.trySuccess(null);
} else {
tryLockAsync(leaseTime, unit, waitTime, result);
tryLockAsync(threadId, leaseTime, unit, waitTime, result);
}
}
});
@ -417,7 +421,7 @@ public class RedissonMultiLock implements Lock {
leaseTime, newLeaseTime, remainTime, time, failedLocksLimit, unit, threadId);
}
public RFuture<Boolean> tryLockAsync(long waitTime, long leaseTime, TimeUnit unit) {
public RFuture<Boolean> tryLockAsync(long waitTime, long leaseTime, TimeUnit unit, long threadId) {
RPromise<Boolean> result = new RedissonPromise<Boolean>();
long newLeaseTime = -1;
if (leaseTime != -1) {
@ -433,13 +437,16 @@ public class RedissonMultiLock implements Lock {
AtomicInteger failedLocksLimit = new AtomicInteger(failedLocksLimit());
List<RLock> acquiredLocks = new ArrayList<RLock>(locks.size());
long threadId = Thread.currentThread().getId();
tryAcquireLockAsync(locks.listIterator(), acquiredLocks, result,
lockWaitTime, waitTime, leaseTime, newLeaseTime,
remainTime, time, failedLocksLimit, unit, threadId);
return result;
}
public RFuture<Boolean> tryLockAsync(long waitTime, long leaseTime, TimeUnit unit) {
return tryLockAsync(waitTime, leaseTime, unit, Thread.currentThread().getId());
}
protected long calcLockWaitTime(long remainTime) {

@ -938,7 +938,8 @@ public class CommandAsyncService implements CommandAsyncExecutor {
TimerTask timeoutTask = new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (details.getAttempt() < connectionManager.getConfig().getRetryAttempts()) {
if (!details.getAttemptPromise().isDone()
&& details.getAttempt() < connectionManager.getConfig().getRetryAttempts()) {
if (!details.getAttemptPromise().cancel(false)) {
return;
}

@ -437,7 +437,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
}
private String createAddress(String host, Object port) {
if (host.contains(":")) {
if (host.contains(":") && !host.startsWith("[")) {
host = "[" + host + "]";
}
return "redis://" + host + ":" + port;

Loading…
Cancel
Save