shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r1335828 - in /shiro/branches/SHIRO-317: core/src/main/java/org/apache/shiro/session/mgt/ core/src/main/java/org/apache/shiro/subject/support/ samples/web/ samples/web/src/test/java/org/apache/shiro/test/
Date Tue, 08 May 2012 23:28:46 GMT
Author: lhazlewood
Date: Tue May  8 23:28:45 2012
New Revision: 1335828

URL: http://svn.apache.org/viewvc?rev=1335828&view=rev
Log:
SHIRO-317: updated SessionManager first-level cache concept to use a private ThreadLocal instead
of the ThreadContext.  The ThreadContext is cleared during subject.execute() which is undesirable
when caching has been enabled during subject construction (Subject.Builder invocation).

Modified:
    shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/session/mgt/AbstractNativeSessionManager.java
    shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/session/mgt/DefaultSessionManager.java
    shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/subject/support/DelegatingSubject.java
    shiro/branches/SHIRO-317/samples/web/pom.xml
    shiro/branches/SHIRO-317/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java

Modified: shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/session/mgt/AbstractNativeSessionManager.java
URL: http://svn.apache.org/viewvc/shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/session/mgt/AbstractNativeSessionManager.java?rev=1335828&r1=1335827&r2=1335828&view=diff
==============================================================================
--- shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/session/mgt/AbstractNativeSessionManager.java
(original)
+++ shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/session/mgt/AbstractNativeSessionManager.java
Tue May  8 23:28:45 2012
@@ -122,22 +122,14 @@ public abstract class AbstractNativeSess
     //since 1.3
     protected SessionKey createSessionKey(Session session, SessionContext context) {
         SessionKey key = doCreateSessionKey(session, context);
-        if (key instanceof UpdateDeferrable && context instanceof UpdateDeferrable)
{
-            UpdateDeferrable udKey = (UpdateDeferrable)key;
-            UpdateDeferrable udContext = (UpdateDeferrable)context;
-            udKey.setUpdateDeferred(udContext.isUpdateDeferred());
-        }
+        applyUpdateDeferred(key, context);
         return key;
     }
 
     //since 1.3
     protected SessionKey createSessionKey(Session session, SessionKey oldKey) {
         SessionKey newKey = doCreateSessionKey(session, oldKey);
-        if (newKey instanceof UpdateDeferrable && oldKey instanceof UpdateDeferrable)
{
-            UpdateDeferrable newKeyUdDeferrable = (UpdateDeferrable)newKey;
-            UpdateDeferrable oldKeyUdDeferrable = (UpdateDeferrable)oldKey;
-            newKeyUdDeferrable.setUpdateDeferred(oldKeyUdDeferrable.isUpdateDeferred());
-        }
+        applyUpdateDeferred(newKey, oldKey);
         return newKey;
     }
 
@@ -260,6 +252,13 @@ public abstract class AbstractNativeSess
     }
 
     //since 1.3
+    protected final void applyUpdateDeferred(Object target, Object source) {
+        if (target instanceof UpdateDeferrable) {
+            ((UpdateDeferrable)target).setUpdateDeferred(isUpdateDeferred(source));
+        }
+    }
+
+    //since 1.3
     protected final boolean isUpdateImmediate(Object object) {
         return !isUpdateDeferred(object);
     }

Modified: shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/session/mgt/DefaultSessionManager.java
URL: http://svn.apache.org/viewvc/shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/session/mgt/DefaultSessionManager.java?rev=1335828&r1=1335827&r2=1335828&view=diff
==============================================================================
--- shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/session/mgt/DefaultSessionManager.java
(original)
+++ shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/session/mgt/DefaultSessionManager.java
Tue May  8 23:28:45 2012
@@ -25,7 +25,6 @@ import org.apache.shiro.session.Session;
 import org.apache.shiro.session.UnknownSessionException;
 import org.apache.shiro.session.mgt.eis.MemorySessionDAO;
 import org.apache.shiro.session.mgt.eis.SessionDAO;
-import org.apache.shiro.util.ThreadContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,8 +45,7 @@ public class DefaultSessionManager exten
 
     private static final Logger log = LoggerFactory.getLogger(DefaultSessionManager.class);
 
-    //since 1.3
-    private static final String SESSION_THREAD_CACHE_KEY = DefaultSessionManager.class.getName()
+ ".SESSION_THREAD_CACHE_KEY";
+    private static final ThreadLocal<Session> firstLevelSessionCache = new ThreadLocal<Session>();
 
     private SessionFactory sessionFactory;
 
@@ -233,10 +231,7 @@ public class DefaultSessionManager exten
 
         Session s = null;
 
-        boolean updateDeferred = false;
-        if (sessionKey instanceof UpdateDeferrable && ((UpdateDeferrable)sessionKey).isUpdateDeferred())
{
-            updateDeferred = true;
-        }
+        boolean updateDeferred = isUpdateDeferred(sessionKey);
         if (updateDeferred) {
             s = retrieveSessionFromFirstLevelCache(sessionId);
         }
@@ -260,28 +255,32 @@ public class DefaultSessionManager exten
 
     //since 1.3
     protected final void addToFirstLevelCache(Session session) {
-        ThreadContext.put(SESSION_THREAD_CACHE_KEY, session);
+        firstLevelSessionCache.set(session);
+        log.trace("Added session {} to first level cache", session);
     }
 
     //since 1.3
     protected final Session retrieveSessionFromFirstLevelCache(Serializable sessionId) {
-        Session session = (Session) ThreadContext.get(SESSION_THREAD_CACHE_KEY);
+        Session session = firstLevelSessionCache.get();
         if (session != null && sessionId.equals(session.getId())) {
+            log.trace("Retrieved session {} from first level cache.", session);
             return session;
         }
         return null;
     }
 
     protected final void removeSessionFromFirstLevelCache() {
-        ThreadContext.remove(SESSION_THREAD_CACHE_KEY);
+        firstLevelSessionCache.remove();
+        log.trace("Removed session from first level cache.");
     }
 
     public void flush(SessionKey key) throws InvalidSessionException {
         Serializable sessionId = getSessionId(key);
         Session session = retrieveSessionFromFirstLevelCache(sessionId);
         if (session != null) {
-            log.trace("Flushing session to data store.  Session id: {}", session.getId());
+            log.debug("Flushing session to data store.  Session id: {}", session.getId());
             sessionDAO.update(session);
+            removeSessionFromFirstLevelCache();
         }
     }
 

Modified: shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/subject/support/DelegatingSubject.java
URL: http://svn.apache.org/viewvc/shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/subject/support/DelegatingSubject.java?rev=1335828&r1=1335827&r2=1335828&view=diff
==============================================================================
--- shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/subject/support/DelegatingSubject.java
(original)
+++ shiro/branches/SHIRO-317/core/src/main/java/org/apache/shiro/subject/support/DelegatingSubject.java
Tue May  8 23:28:45 2012
@@ -361,8 +361,9 @@ public class DelegatingSubject implement
             sessionContext.setHost(host);
         }
         //added for 1.3 (see SHIRO-317):
-        if (isSessionUpdateDeferred()) {
-            sessionContext.setUpdateDeferred(isSessionUpdateDeferred());
+        boolean updateDeferred = isSessionUpdateDeferred();
+        if (updateDeferred) {
+            sessionContext.setUpdateDeferred(updateDeferred);
         }
         return sessionContext;
     }

Modified: shiro/branches/SHIRO-317/samples/web/pom.xml
URL: http://svn.apache.org/viewvc/shiro/branches/SHIRO-317/samples/web/pom.xml?rev=1335828&r1=1335827&r2=1335828&view=diff
==============================================================================
--- shiro/branches/SHIRO-317/samples/web/pom.xml (original)
+++ shiro/branches/SHIRO-317/samples/web/pom.xml Tue May  8 23:28:45 2012
@@ -113,6 +113,7 @@
         <dependency>
             <groupId>taglibs</groupId>
             <artifactId>standard</artifactId>
+            <scope>runtime</scope>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>

Modified: shiro/branches/SHIRO-317/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java
URL: http://svn.apache.org/viewvc/shiro/branches/SHIRO-317/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java?rev=1335828&r1=1335827&r2=1335828&view=diff
==============================================================================
--- shiro/branches/SHIRO-317/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java
(original)
+++ shiro/branches/SHIRO-317/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java
Tue May  8 23:28:45 2012
@@ -26,11 +26,13 @@ import com.gargoylesoftware.htmlunit.htm
 import com.gargoylesoftware.htmlunit.html.HtmlInput;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import java.io.IOException;
 import java.net.MalformedURLException;
 
+@Ignore
 public class ContainerIntegrationTest extends AbstractContainerTest {
 
     @Before



Mime
View raw message