This is the first of two sets of patches relating to sessions. The following
set will be my proposed session persistence package, while these are more
general and should be considered independently.

ManagerBase.java
----------------------------------------
- Fixed a bug where recycled sessions don't seem to have their Managers set.
  The session.recycle() clears the manager, so the createSession() method should
  set the manager if it uses a recycled session. It's possible this is done elsewhere,
  but I don't see it, caused some NullPointerExceptions while testing my persistence 
  code.
- Fixed a bug where findSession() apparently doesn't call access() on the returned
  session. The result is sessions will expire based on when they were first created,
  not when they were last accessed. Again, this might be set somewhere else, but
  it wasn't getting set in my persistence testing.

StandardSession.java
----------------------------------------
- Changed expire() to recycle the session if the Manager is a subclass of ManagerBase.
- Added activate() and passivate() methods which notify HttpSessionActivationListeners
  when the session is activated or passivated, as per the Servlet 2.3 specification 
PFD.

Kief
--- ManagerBase.java.orig       Fri Jan 12 22:03:13 2001
+++ ManagerBase.java    Fri Jan 12 21:22:44 2001
@@ -506,7 +506,9 @@
                recycled.remove(size - 1);
            }
        }
-       if (session == null)
+       if (session != null)
+           session.setManager(this);
+       else
            session = new StandardSession(this);
 
        // Initialize the properties of the new session and return it
@@ -544,7 +546,10 @@
        if (id == null)
            return (null);
        synchronized (sessions) {
-           return ((Session) sessions.get(id));
+           Session session = (Session) sessions.get(id);
+           if (session != null)
+               session.access();
+           return (session);
        }
 
     }
--- StandardSession.java.orig   Thu Jan 11 23:01:02 2001
+++ StandardSession.java        Fri Jan 12 22:17:50 2001
@@ -77,6 +77,7 @@
 import java.util.Iterator;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionActivationListener;
 import javax.servlet.http.HttpSessionAttributesListener;
 import javax.servlet.http.HttpSessionBindingEvent;
 import javax.servlet.http.HttpSessionBindingListener;
@@ -538,10 +539,58 @@
 
         // We have completed expire of this session
        expiring = false;
+       if ((manager != null) && (manager instanceof ManagerBase)) {
+           recycle();
+           ((ManagerBase) manager).recycle(this);
+       }
 
     }
 
 
+    /**
+     * Perform the internal processing required to passivate
+     * this session.
+     */
+    public void passivate() {
+    
+       // Notify ActivationListeners
+       HttpSessionEvent event = null;
+       String keys[] = keys();
+       for (int i = 0; i < keys.length; i++) {
+           Object attribute = getAttribute(keys[i]);
+           if (attribute instanceof HttpSessionActivationListener) {
+               if (event == null)
+                   event = new HttpSessionEvent(this);
+               // FIXME: Should we catch throwables?
+               ((HttpSessionActivationListener)attribute).sessionWillPassivate(event);
+           }
+       }
+
+    }
+
+    
+    /**
+     * Perform internal processing required to activate this
+     * session.
+     */
+    public void activate() {
+    
+       // Notify ActivationListeners
+       HttpSessionEvent event = null;
+       String keys[] = keys();
+       for (int i = 0; i < keys.length; i++) {
+           Object attribute = getAttribute(keys[i]);
+           if (attribute instanceof HttpSessionActivationListener) {
+               if (event == null)
+                   event = new HttpSessionEvent(this);
+               // FIXME: Should we catch throwables?
+               ((HttpSessionActivationListener)attribute).sessionDidActivate(event);
+           }
+       }
+
+    }
+    
+    
     /**
      * Return the <code>isValid</code> flag for this session.
      */

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to