Updated Branches:
  refs/heads/wicket-1.5.x d235f666e -> d3e8d96e0

WICKET-4444 Add a callback to the Session which is called when the HttpSession 
is invalidated

Conflicts:
        
wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/d3e8d96e
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/d3e8d96e
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/d3e8d96e

Branch: refs/heads/wicket-1.5.x
Commit: d3e8d96e0723e5ab8575a213e5917f05e4152a8c
Parents: d235f66
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Mon Jan 28 10:15:57 2013 +0100
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Mon Jan 28 10:20:40 2013 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/wicket/Session.java   |   14 ++++++++++
 .../apache/wicket/session/HttpSessionStore.java    |   20 +++++++++-----
 2 files changed, 27 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/d3e8d96e/wicket-core/src/main/java/org/apache/wicket/Session.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/Session.java 
b/wicket-core/src/main/java/org/apache/wicket/Session.java
index 9574591..37624e4 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Session.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Session.java
@@ -843,6 +843,20 @@ public abstract class Session implements IClusterable, 
IEventSink
        {
        }
 
+       /**
+        * A callback method that is executed when the user session is 
invalidated
+        * either by explicit call to {@link 
org.apache.wicket.Session#invalidate()}
+        * or due to HttpSession expiration.
+        *
+        * <p>In case of session expiration this method is called in a 
non-worker thread, i.e.
+        * there are no thread locals exported for the Application, 
RequestCycle and Session.
+        * The Session is the current instance. The Application can be found by 
using
+        * {@link Application#get(String)}. There is no way to get a reference 
to a RequestCycle</p>
+        */
+       public void onInvalidate()
+       {
+       }
+
        private static final class PageAccessSynchronizerProvider extends
                LazyInitializer<PageAccessSynchronizer>
        {

http://git-wip-us.apache.org/repos/asf/wicket/blob/d3e8d96e/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java 
b/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java
index 8dd19e0..30c49ba 100644
--- a/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java
+++ b/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java
@@ -116,7 +116,7 @@ public class HttpSessionStore implements ISessionStore
                                // register an unbinding listener for cleaning 
up
                                String applicationKey = 
Application.get().getName();
                                
httpSession.setAttribute("Wicket:SessionUnbindingListener-" + applicationKey,
-                                       new 
SessionBindingListener(applicationKey, httpSession.getId()));
+                                       new 
SessionBindingListener(applicationKey, newSession));
 
                                // register the session object itself
                                setAttribute(request, 
Session.SESSION_ATTRIBUTE_NAME, newSession);
@@ -400,21 +400,23 @@ public class HttpSessionStore implements ISessionStore
                /** The unique key of the application within this web 
application. */
                private final String applicationKey;
 
-               /** Session id. */
-               private final String sessionId;
+               /**
+                * The Wicket Session associated with the expiring HttpSession
+                */
+               private final Session wicketSession;
 
                /**
                 * Construct.
                 * 
                 * @param applicationKey
                 *            The unique key of the application within this web 
application
-                * @param sessionId
-                *            The session's id
+                * @param wicketSession
+                *            The Wicket Session associated with the expiring 
http session
                 */
-               public SessionBindingListener(final String applicationKey, 
final String sessionId)
+               public SessionBindingListener(final String applicationKey, 
final Session wicketSession)
                {
                        this.applicationKey = applicationKey;
-                       this.sessionId = sessionId;
+                       this.wicketSession = wicketSession;
                }
 
                /**
@@ -429,11 +431,15 @@ public class HttpSessionStore implements ISessionStore
                 */
                public void valueUnbound(final HttpSessionBindingEvent evt)
                {
+                       String sessionId = evt.getSession().getId();
+
                        if (log.isDebugEnabled())
                        {
                                log.debug("Session unbound: " + sessionId);
                        }
 
+                       wicketSession.onInvalidate();
+
                        Application application = 
Application.get(applicationKey);
                        if (application == null)
                        {

Reply via email to