Merge branch 'master' into 3.0.0

# Conflicts:
#	pom.xml
#	redisson-all/pom.xml
#	redisson-tomcat/pom.xml
#	redisson-tomcat/redisson-tomcat-6/pom.xml
#	redisson-tomcat/redisson-tomcat-7/pom.xml
#	redisson-tomcat/redisson-tomcat-8/pom.xml
#	redisson/pom.xml
pull/985/head^2
Nikita 8 years ago
commit 1852c1c993

@ -2,7 +2,25 @@ Redisson Releases History
================================ ================================
### Please Note: trunk is current development branch. ### Please Note: trunk is current development branch.
__[Redisson PRO](https://redisson.pro)__ now costs only __$975__ per year and supports unlimited Redisson instances Try __[Redisson PRO](https://redisson.pro)__ version.
### 28-Jul-2017 - versions 2.10.0 and 3.5.0 released
Feature - __Local Cache support for Hibernate Cache__ Please read [documentation](https://github.com/redisson/redisson/wiki/14.-Integration-with-frameworks/#1431-hibernate-cache-local-cache) for more details
Feature - __Local Cache support for Spring Cache__ Please read [documentation](https://github.com/redisson/redisson/wiki/14.-Integration-with-frameworks/#1421-spring-cache-local-cache) for more details
Feature - __`RedissonLocalCachedMapCache` object added__ Please read [documentation](https://github.com/redisson/redisson/wiki/7.-distributed-collections/#713-map-local-cache-for-expiring-entries) for more details
Feature - __`BlockingFairDeque` object added__ Please read [documentation](https://github.com/redisson/redisson/wiki/7.-distributed-collections#714-blocking-fair-deque) for more details
Feature - __`RLockReactive` object added__
Feature - __`RReadWriteLockReactive` object added__
Feature - __`RSemaphoreReactive` object added__
Feature - `unlink`, `flushdbParallel`, `flushallParallel` methods added
Fixed - ContextClassLoader should be used by Redisson Codec for Tomcat session's object serialization
Fixed - Spring Cache `NullValue` does not implement Serializable
Fixed - `RLocalCachedMap` doesn't work with non-json and non-binary codecs
Fixed - Tomcat RedissonSessionManager doesn't remove session on invalidation/expiration
Fixed - `RedissonBatch` shouldn't require `reactor.fn.Supplier` dependency
Fixed - Spring Session 1.3.x compatibility (thanks to Vcgoyo)
Fixed - priority queues should acquire lock before polling the element
### 12-Jul-2017 - versions 2.9.4 and 3.4.4 released ### 12-Jul-2017 - versions 2.9.4 and 3.4.4 released

@ -6,8 +6,8 @@ Based on high-performance async and lock-free Java Redis client and [Netty](http
| Stable Release Version | JDK Version compatibility | Release Date | | Stable Release Version | JDK Version compatibility | Release Date |
| ------------- | ------------- | ------------| | ------------- | ------------- | ------------|
| 3.4.4 | 1.8+ | 12.07.2017 | | 3.5.0 | 1.8+ | 28.07.2017 |
| 2.9.4 | 1.6, 1.7, 1.8 and Android | 12.07.2017 | | 2.10.0 | 1.6, 1.7, 1.8 and Android | 28.07.2017 |
__NOTE__: Both version lines have same features except `CompletionStage` interface added in 3.x.x __NOTE__: Both version lines have same features except `CompletionStage` interface added in 3.x.x
@ -82,23 +82,23 @@ Quick start
<dependency> <dependency>
<groupId>org.redisson</groupId> <groupId>org.redisson</groupId>
<artifactId>redisson</artifactId> <artifactId>redisson</artifactId>
<version>3.4.4</version> <version>3.5.0</version>
</dependency> </dependency>
<!-- JDK 1.6+ compatible --> <!-- JDK 1.6+ compatible -->
<dependency> <dependency>
<groupId>org.redisson</groupId> <groupId>org.redisson</groupId>
<artifactId>redisson</artifactId> <artifactId>redisson</artifactId>
<version>2.9.4</version> <version>2.10.0</version>
</dependency> </dependency>
#### Gradle #### Gradle
// JDK 1.8+ compatible // JDK 1.8+ compatible
compile 'org.redisson:redisson:3.4.4' compile 'org.redisson:redisson:3.5.0'
// JDK 1.6+ compatible // JDK 1.6+ compatible
compile 'org.redisson:redisson:2.9.4' compile 'org.redisson:redisson:2.10.0'
#### Java #### Java
@ -123,11 +123,11 @@ RExecutorService executor = redisson.getExecutorService("myExecutorService");
Downloads Downloads
=============================== ===============================
[Redisson 3.4.4](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson&v=3.4.4&e=jar), [Redisson 3.5.0](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson&v=3.5.0&e=jar),
[Redisson node 3.4.4](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-all&v=3.4.4&e=jar) [Redisson node 3.5.0](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-all&v=3.5.0&e=jar)
[Redisson 2.9.4](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson&v=2.9.4&e=jar), [Redisson 2.10.0](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson&v=2.10.0&e=jar),
[Redisson node 2.9.4](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-all&v=2.9.4&e=jar) [Redisson node 2.10.0](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-all&v=2.10.0&e=jar)
### Supported by ### Supported by

@ -26,22 +26,22 @@ Usage
**2** Copy two jars into `TOMCAT_BASE/lib` directory: **2** Copy two jars into `TOMCAT_BASE/lib` directory:
1. __For JDK 1.8+__ 1. __For JDK 1.8+__
[redisson-all-3.4.4.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-all&v=3.4.4&e=jar) [redisson-all-3.5.0.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-all&v=3.5.0&e=jar)
for Tomcat 6.x for Tomcat 6.x
[redisson-tomcat-6-3.4.4.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-6&v=3.4.4&e=jar) [redisson-tomcat-6-3.5.0.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-6&v=3.5.0&e=jar)
for Tomcat 7.x for Tomcat 7.x
[redisson-tomcat-7-3.4.4.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-7&v=3.4.4&e=jar) [redisson-tomcat-7-3.5.0.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-7&v=3.5.0&e=jar)
for Tomcat 8.x for Tomcat 8.x
[redisson-tomcat-8-3.4.4.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-8&v=3.4.4&e=jar) [redisson-tomcat-8-3.5.0.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-8&v=3.5.0&e=jar)
2. __For JDK 1.6+__ 2. __For JDK 1.6+__
[redisson-all-2.9.4.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-all&v=2.9.4&e=jar) [redisson-all-2.10.0.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-all&v=2.10.0&e=jar)
for Tomcat 6.x for Tomcat 6.x
[redisson-tomcat-6-2.9.4.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-6&v=2.9.4&e=jar) [redisson-tomcat-6-2.10.0.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-6&v=2.10.0&e=jar)
for Tomcat 7.x for Tomcat 7.x
[redisson-tomcat-7-2.9.4.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-7&v=2.9.4&e=jar) [redisson-tomcat-7-2.10.0.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-7&v=2.10.0&e=jar)
for Tomcat 8.x for Tomcat 8.x
[redisson-tomcat-8-2.9.4.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-8&v=2.9.4&e=jar) [redisson-tomcat-8-2.10.0.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-8&v=2.10.0&e=jar)

@ -19,11 +19,11 @@ import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.catalina.session.StandardSession; import org.apache.catalina.session.StandardSession;
import org.redisson.api.RMap; import org.redisson.api.RMap;
import org.redisson.tomcat.RedissonSessionManager.ReadMode;
/** /**
* Redisson Session object for Apache Tomcat * Redisson Session object for Apache Tomcat
@ -36,10 +36,12 @@ public class RedissonSession extends StandardSession {
private final RedissonSessionManager redissonManager; private final RedissonSessionManager redissonManager;
private final Map<String, Object> attrs; private final Map<String, Object> attrs;
private RMap<String, Object> map; private RMap<String, Object> map;
private final RedissonSessionManager.ReadMode readMode;
public RedissonSession(RedissonSessionManager manager) { public RedissonSession(RedissonSessionManager manager, RedissonSessionManager.ReadMode readMode) {
super(manager); super(manager);
this.redissonManager = manager; this.redissonManager = manager;
this.readMode = readMode;
try { try {
Field attr = StandardSession.class.getDeclaredField("attributes"); Field attr = StandardSession.class.getDeclaredField("attributes");
@ -51,6 +53,15 @@ public class RedissonSession extends StandardSession {
private static final long serialVersionUID = -2518607181636076487L; private static final long serialVersionUID = -2518607181636076487L;
@Override
public Object getAttribute(String name) {
if (readMode == ReadMode.REDIS) {
return map.get(name);
}
return super.getAttribute(name);
}
@Override @Override
public void setId(String id, boolean notify) { public void setId(String id, boolean notify) {
super.setId(id, notify); super.setId(id, notify);
@ -163,24 +174,30 @@ public class RedissonSession extends StandardSession {
} }
} }
public void load() { public void load(Map<String, Object> attrs) {
Set<Entry<String, Object>> entrySet = map.readAllEntrySet(); Long creationTime = (Long) attrs.remove("session:creationTime");
for (Entry<String, Object> entry : entrySet) { if (creationTime != null) {
if ("session:creationTime".equals(entry.getKey())) { this.creationTime = creationTime;
creationTime = (Long) entry.getValue(); }
} else if ("session:lastAccessedTime".equals(entry.getKey())) { Long lastAccessedTime = (Long) attrs.remove("session:lastAccessedTime");
lastAccessedTime = (Long) entry.getValue(); if (lastAccessedTime != null) {
} else if ("session:thisAccessedTime".equals(entry.getKey())) { this.lastAccessedTime = lastAccessedTime;
thisAccessedTime = (Long) entry.getValue(); }
} else if ("session:maxInactiveInterval".equals(entry.getKey())) { Long thisAccessedTime = (Long) attrs.remove("session:thisAccessedTime");
maxInactiveInterval = (Integer) entry.getValue(); if (thisAccessedTime != null) {
} else if ("session:isValid".equals(entry.getKey())) { this.thisAccessedTime = thisAccessedTime;
isValid = (Boolean) entry.getValue(); }
} else if ("session:isNew".equals(entry.getKey())) { Boolean isValid = (Boolean) attrs.remove("session:isValid");
isNew = (Boolean) entry.getValue(); if (isValid != null) {
} else { this.isValid = isValid;
setAttribute(entry.getKey(), entry.getValue(), false); }
} Boolean isNew = (Boolean) attrs.remove("session:isNew");
if (isNew != null) {
this.isNew = isNew;
}
for (Entry<String, Object> entry : attrs.entrySet()) {
setAttribute(entry.getKey(), entry.getValue(), false);
} }
} }

@ -17,6 +17,7 @@ package org.redisson.tomcat;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import org.apache.juli.logging.Log; import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory; import org.apache.juli.logging.LogFactory;
@ -40,13 +41,24 @@ import org.redisson.config.Config;
*/ */
public class RedissonSessionManager extends ManagerBase implements Lifecycle { public class RedissonSessionManager extends ManagerBase implements Lifecycle {
public enum ReadMode {REDIS, MEMORY}
private final Log log = LogFactory.getLog(RedissonSessionManager.class); private final Log log = LogFactory.getLog(RedissonSessionManager.class);
protected LifecycleSupport lifecycle = new LifecycleSupport(this); protected LifecycleSupport lifecycle = new LifecycleSupport(this);
private RedissonClient redisson; private RedissonClient redisson;
private String configPath; private String configPath;
private ReadMode readMode = ReadMode.MEMORY;
public String getReadMode() {
return readMode.toString();
}
public void setReadMode(String readMode) {
this.readMode = ReadMode.valueOf(readMode);
}
public void setConfigPath(String configPath) { public void setConfigPath(String configPath) {
this.configPath = configPath; this.configPath = configPath;
} }
@ -114,9 +126,18 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
public Session findSession(String id) throws IOException { public Session findSession(String id) throws IOException {
Session result = super.findSession(id); Session result = super.findSession(id);
if (result == null && id != null) { if (result == null && id != null) {
Map<String, Object> attrs = getMap(id).readAllMap();
if (attrs.isEmpty()) {
log.info("Session " + id + " can't be found");
return null;
}
RedissonSession session = (RedissonSession) createEmptySession(); RedissonSession session = (RedissonSession) createEmptySession();
session.setId(id); session.setId(id);
session.load(); session.load(attrs);
session.access();
session.endAccess();
return session; return session;
} }
@ -125,7 +146,7 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
@Override @Override
public Session createEmptySession() { public Session createEmptySession() {
return new RedissonSession(this); return new RedissonSession(this, readMode);
} }
@Override @Override

@ -19,11 +19,11 @@ import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.catalina.session.StandardSession; import org.apache.catalina.session.StandardSession;
import org.redisson.api.RMap; import org.redisson.api.RMap;
import org.redisson.tomcat.RedissonSessionManager.ReadMode;
/** /**
* Redisson Session object for Apache Tomcat * Redisson Session object for Apache Tomcat
@ -36,10 +36,12 @@ public class RedissonSession extends StandardSession {
private final RedissonSessionManager redissonManager; private final RedissonSessionManager redissonManager;
private final Map<String, Object> attrs; private final Map<String, Object> attrs;
private RMap<String, Object> map; private RMap<String, Object> map;
private final RedissonSessionManager.ReadMode readMode;
public RedissonSession(RedissonSessionManager manager) { public RedissonSession(RedissonSessionManager manager, RedissonSessionManager.ReadMode readMode) {
super(manager); super(manager);
this.redissonManager = manager; this.redissonManager = manager;
this.readMode = readMode;
try { try {
Field attr = StandardSession.class.getDeclaredField("attributes"); Field attr = StandardSession.class.getDeclaredField("attributes");
attrs = (Map<String, Object>) attr.get(this); attrs = (Map<String, Object>) attr.get(this);
@ -50,6 +52,15 @@ public class RedissonSession extends StandardSession {
private static final long serialVersionUID = -2518607181636076487L; private static final long serialVersionUID = -2518607181636076487L;
@Override
public Object getAttribute(String name) {
if (readMode == ReadMode.REDIS) {
return map.get(name);
}
return super.getAttribute(name);
}
@Override @Override
public void setId(String id, boolean notify) { public void setId(String id, boolean notify) {
super.setId(id, notify); super.setId(id, notify);
@ -167,24 +178,30 @@ public class RedissonSession extends StandardSession {
} }
} }
public void load() { public void load(Map<String, Object> attrs) {
Set<Entry<String, Object>> entrySet = map.readAllEntrySet(); Long creationTime = (Long) attrs.remove("session:creationTime");
for (Entry<String, Object> entry : entrySet) { if (creationTime != null) {
if ("session:creationTime".equals(entry.getKey())) { this.creationTime = creationTime;
creationTime = (Long) entry.getValue(); }
} else if ("session:lastAccessedTime".equals(entry.getKey())) { Long lastAccessedTime = (Long) attrs.remove("session:lastAccessedTime");
lastAccessedTime = (Long) entry.getValue(); if (lastAccessedTime != null) {
} else if ("session:thisAccessedTime".equals(entry.getKey())) { this.lastAccessedTime = lastAccessedTime;
thisAccessedTime = (Long) entry.getValue(); }
} else if ("session:maxInactiveInterval".equals(entry.getKey())) { Long thisAccessedTime = (Long) attrs.remove("session:thisAccessedTime");
maxInactiveInterval = (Integer) entry.getValue(); if (thisAccessedTime != null) {
} else if ("session:isValid".equals(entry.getKey())) { this.thisAccessedTime = thisAccessedTime;
isValid = (Boolean) entry.getValue(); }
} else if ("session:isNew".equals(entry.getKey())) { Boolean isValid = (Boolean) attrs.remove("session:isValid");
isNew = (Boolean) entry.getValue(); if (isValid != null) {
} else { this.isValid = isValid;
setAttribute(entry.getKey(), entry.getValue(), false); }
} Boolean isNew = (Boolean) attrs.remove("session:isNew");
if (isNew != null) {
this.isNew = isNew;
}
for (Entry<String, Object> entry : attrs.entrySet()) {
setAttribute(entry.getKey(), entry.getValue(), false);
} }
} }

@ -17,6 +17,7 @@ package org.redisson.tomcat;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import org.apache.catalina.Context; import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleException;
@ -39,11 +40,22 @@ import org.redisson.config.Config;
*/ */
public class RedissonSessionManager extends ManagerBase { public class RedissonSessionManager extends ManagerBase {
public enum ReadMode {REDIS, MEMORY}
private final Log log = LogFactory.getLog(RedissonSessionManager.class); private final Log log = LogFactory.getLog(RedissonSessionManager.class);
private RedissonClient redisson; private RedissonClient redisson;
private String configPath; private String configPath;
private ReadMode readMode = ReadMode.MEMORY;
public String getReadMode() {
return readMode.toString();
}
public void setReadMode(String readMode) {
this.readMode = ReadMode.valueOf(readMode);
}
public void setConfigPath(String configPath) { public void setConfigPath(String configPath) {
this.configPath = configPath; this.configPath = configPath;
} }
@ -92,9 +104,18 @@ public class RedissonSessionManager extends ManagerBase {
public Session findSession(String id) throws IOException { public Session findSession(String id) throws IOException {
Session result = super.findSession(id); Session result = super.findSession(id);
if (result == null && id != null) { if (result == null && id != null) {
Map<String, Object> attrs = getMap(id).readAllMap();
if (attrs.isEmpty()) {
log.info("Session " + id + " can't be found");
return null;
}
RedissonSession session = (RedissonSession) createEmptySession(); RedissonSession session = (RedissonSession) createEmptySession();
session.setId(id); session.setId(id);
session.load(); session.load(attrs);
session.access();
session.endAccess();
return session; return session;
} }
@ -103,7 +124,7 @@ public class RedissonSessionManager extends ManagerBase {
@Override @Override
public Session createEmptySession() { public Session createEmptySession() {
return new RedissonSession(this); return new RedissonSession(this, readMode);
} }
@Override @Override

@ -19,11 +19,11 @@ import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.catalina.session.StandardSession; import org.apache.catalina.session.StandardSession;
import org.redisson.api.RMap; import org.redisson.api.RMap;
import org.redisson.tomcat.RedissonSessionManager.ReadMode;
/** /**
* Redisson Session object for Apache Tomcat * Redisson Session object for Apache Tomcat
@ -36,10 +36,13 @@ public class RedissonSession extends StandardSession {
private final RedissonSessionManager redissonManager; private final RedissonSessionManager redissonManager;
private final Map<String, Object> attrs; private final Map<String, Object> attrs;
private RMap<String, Object> map; private RMap<String, Object> map;
private final RedissonSessionManager.ReadMode readMode;
public RedissonSession(RedissonSessionManager manager) { public RedissonSession(RedissonSessionManager manager, RedissonSessionManager.ReadMode readMode) {
super(manager); super(manager);
this.redissonManager = manager; this.redissonManager = manager;
this.readMode = readMode;
try { try {
Field attr = StandardSession.class.getDeclaredField("attributes"); Field attr = StandardSession.class.getDeclaredField("attributes");
attrs = (Map<String, Object>) attr.get(this); attrs = (Map<String, Object>) attr.get(this);
@ -50,6 +53,15 @@ public class RedissonSession extends StandardSession {
private static final long serialVersionUID = -2518607181636076487L; private static final long serialVersionUID = -2518607181636076487L;
@Override
public Object getAttribute(String name) {
if (readMode == ReadMode.REDIS) {
return map.get(name);
}
return super.getAttribute(name);
}
@Override @Override
public void setId(String id, boolean notify) { public void setId(String id, boolean notify) {
super.setId(id, notify); super.setId(id, notify);
@ -167,24 +179,30 @@ public class RedissonSession extends StandardSession {
} }
} }
public void load() { public void load(Map<String, Object> attrs) {
Set<Entry<String, Object>> entrySet = map.readAllEntrySet(); Long creationTime = (Long) attrs.remove("session:creationTime");
for (Entry<String, Object> entry : entrySet) { if (creationTime != null) {
if ("session:creationTime".equals(entry.getKey())) { this.creationTime = creationTime;
creationTime = (Long) entry.getValue(); }
} else if ("session:lastAccessedTime".equals(entry.getKey())) { Long lastAccessedTime = (Long) attrs.remove("session:lastAccessedTime");
lastAccessedTime = (Long) entry.getValue(); if (lastAccessedTime != null) {
} else if ("session:thisAccessedTime".equals(entry.getKey())) { this.lastAccessedTime = lastAccessedTime;
thisAccessedTime = (Long) entry.getValue(); }
} else if ("session:maxInactiveInterval".equals(entry.getKey())) { Long thisAccessedTime = (Long) attrs.remove("session:thisAccessedTime");
maxInactiveInterval = (Integer) entry.getValue(); if (thisAccessedTime != null) {
} else if ("session:isValid".equals(entry.getKey())) { this.thisAccessedTime = thisAccessedTime;
isValid = (Boolean) entry.getValue(); }
} else if ("session:isNew".equals(entry.getKey())) { Boolean isValid = (Boolean) attrs.remove("session:isValid");
isNew = (Boolean) entry.getValue(); if (isValid != null) {
} else { this.isValid = isValid;
setAttribute(entry.getKey(), entry.getValue(), false); }
} Boolean isNew = (Boolean) attrs.remove("session:isNew");
if (isNew != null) {
this.isNew = isNew;
}
for (Entry<String, Object> entry : attrs.entrySet()) {
setAttribute(entry.getKey(), entry.getValue(), false);
} }
} }

@ -17,6 +17,7 @@ package org.redisson.tomcat;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleState; import org.apache.catalina.LifecycleState;
@ -38,11 +39,23 @@ import org.redisson.config.Config;
*/ */
public class RedissonSessionManager extends ManagerBase { public class RedissonSessionManager extends ManagerBase {
public enum ReadMode {REDIS, MEMORY}
private final Log log = LogFactory.getLog(RedissonSessionManager.class); private final Log log = LogFactory.getLog(RedissonSessionManager.class);
private RedissonClient redisson; private RedissonClient redisson;
private String configPath; private String configPath;
private ReadMode readMode = ReadMode.MEMORY;
public String getReadMode() {
return readMode.toString();
}
public void setReadMode(String readMode) {
this.readMode = ReadMode.valueOf(readMode);
}
public void setConfigPath(String configPath) { public void setConfigPath(String configPath) {
this.configPath = configPath; this.configPath = configPath;
} }
@ -91,9 +104,18 @@ public class RedissonSessionManager extends ManagerBase {
public Session findSession(String id) throws IOException { public Session findSession(String id) throws IOException {
Session result = super.findSession(id); Session result = super.findSession(id);
if (result == null && id != null) { if (result == null && id != null) {
Map<String, Object> attrs = getMap(id).readAllMap();
if (attrs.isEmpty()) {
log.info("Session " + id + " can't be found");
return null;
}
RedissonSession session = (RedissonSession) createEmptySession(); RedissonSession session = (RedissonSession) createEmptySession();
session.setId(id); session.setId(id);
session.load(); session.load(attrs);
session.access();
session.endAccess();
return session; return session;
} }
@ -102,7 +124,7 @@ public class RedissonSessionManager extends ManagerBase {
@Override @Override
public Session createEmptySession() { public Session createEmptySession() {
return new RedissonSession(this); return new RedissonSession(this, readMode);
} }
@Override @Override

@ -1291,7 +1291,11 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
} }
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_VOID, return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_VOID,
"for i, value in ipairs(ARGV) do " "for i=1, #ARGV, 5000 do "
+ "redis.call('hmset', KEYS[1], unpack(ARGV, i, math.min(i+4999, table.getn(ARGV)))) "
+ "end; "
+ "for i, value in ipairs(ARGV) do "
+ "if i % 2 == 0 then " + "if i % 2 == 0 then "
+ "local val = struct.pack('dLc0', 0, string.len(value), value); " + "local val = struct.pack('dLc0', 0, string.len(value), value); "
+ "ARGV[i] = val; " + "ARGV[i] = val; "
@ -1300,8 +1304,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
+ "local msg = struct.pack('Lc0Lc0', string.len(key), key, string.len(value), value); " + "local msg = struct.pack('Lc0Lc0', string.len(key), key, string.len(value), value); "
+ "redis.call('publish', KEYS[2], msg); " + "redis.call('publish', KEYS[2], msg); "
+ "end;" + "end;"
+ "end;" + "end;",
+ "return redis.call('hmset', KEYS[1], unpack(ARGV)); ",
Arrays.<Object>asList(getName(), getCreatedChannelName()), params.toArray()); Arrays.<Object>asList(getName(), getCreatedChannelName()), params.toArray());
} }

@ -20,16 +20,13 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Queue;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import org.redisson.api.RFuture; import org.redisson.api.RFuture;
import org.redisson.api.RLock; import org.redisson.api.RLock;
import io.netty.util.concurrent.Future;
import io.netty.util.internal.ThreadLocalRandom; import io.netty.util.internal.ThreadLocalRandom;
/** /**
@ -226,12 +223,4 @@ public class RedissonMultiLock implements Lock {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
protected boolean isLockFailed(Future<Boolean> future) {
return !future.isSuccess();
}
protected boolean isAllLocksAcquired(AtomicReference<RLock> lockedLockHolder, AtomicReference<Throwable> failed, Queue<RLock> lockedLocks) {
return lockedLockHolder.get() == null && failed.get() == null;
}
} }

@ -16,13 +16,9 @@
package org.redisson; package org.redisson;
import java.util.List; import java.util.List;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicReference;
import org.redisson.api.RLock; import org.redisson.api.RLock;
import io.netty.util.concurrent.Future;
/** /**
* RedLock locking algorithm implementation for multiple locks. * RedLock locking algorithm implementation for multiple locks.
* It manages all locks as one. * It manages all locks as one.
@ -58,14 +54,4 @@ public class RedissonRedLock extends RedissonMultiLock {
unlockInner(locks); unlockInner(locks);
} }
@Override
protected boolean isLockFailed(Future<Boolean> future) {
return false;
}
@Override
protected boolean isAllLocksAcquired(AtomicReference<RLock> lockedLockHolder, AtomicReference<Throwable> failed, Queue<RLock> lockedLocks) {
return (lockedLockHolder.get() == null && failed.get() == null) || lockedLocks.size() >= minLocksAmount(locks);
}
} }

@ -432,6 +432,19 @@ public class RedissonMapCacheTest extends BaseMapTest {
Assert.assertEquals(1, map.size()); Assert.assertEquals(1, map.size());
} }
@Test
public void testPutAllBig() {
Map<Integer, String> joinMap = new HashMap<Integer, String>();
for (int i = 0; i < 100000; i++) {
joinMap.put(i, "" + i);
}
Map<Integer, String> map = redisson.getMapCache("simple");
map.putAll(joinMap);
assertThat(map.size()).isEqualTo(joinMap.size());
}
@Test @Test
public void testPutAll() { public void testPutAll() {
Map<Integer, String> map = redisson.getMapCache("simple"); Map<Integer, String> map = redisson.getMapCache("simple");

Loading…
Cancel
Save