You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/02/06 09:52:00 UTC
[5/38] git commit: WICKET-4444 Add a callback to the Session which is
called when the HttpSession is invalidated
WICKET-4444 Add a callback to the Session which is called when the HttpSession is invalidated
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/afa176ee
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/afa176ee
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/afa176ee
Branch: refs/heads/reference-guide
Commit: afa176eea058cc596fe9f4dbfdf1cf0c40866c47
Parents: 953eceb
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Jan 28 10:15:57 2013 +0100
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Jan 28 10:15:57 2013 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/wicket/Session.java | 14 ++++++++++++++
.../apache/wicket/session/HttpSessionStore.java | 12 ++++++++++--
2 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/afa176ee/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 3f2ba31..fa2b655 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Session.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Session.java
@@ -868,6 +868,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/afa176ee/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 ff7010c..976603b 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
@@ -117,7 +117,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));
+ new SessionBindingListener(applicationKey, newSession));
// register the session object itself
setAttribute(request, Session.SESSION_ATTRIBUTE_NAME, newSession);
@@ -417,14 +417,20 @@ public class HttpSessionStore implements ISessionStore
private final String applicationKey;
/**
+ * 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
*/
- public SessionBindingListener(final String applicationKey)
+ public SessionBindingListener(final String applicationKey, final Session wicketSession)
{
this.applicationKey = applicationKey;
+ this.wicketSession = wicketSession;
}
/**
@@ -445,6 +451,8 @@ public class HttpSessionStore implements ISessionStore
log.debug("Session unbound: {}", sessionId);
+ wicketSession.onInvalidate();
+
Application application = Application.get(applicationKey);
if (application == null)
{