You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/04/13 19:16:41 UTC

svn commit: r528558 - in /incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket: RequestCycle.java Session.java protocol/http/WebSession.java

Author: ehillenius
Date: Fri Apr 13 10:16:39 2007
New Revision: 528558

URL: http://svn.apache.org/viewvc?view=rev&rev=528558
Log:
More cleaning up. Session#update is not used anymore, and the detach logic is put into one method now. Also brought deferred invalidation of the session from WebSession to Session as there really wasn't a good reason not to have it there and it simplifies our code.

Modified:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Session.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java?view=diff&rev=528558&r1=528557&r2=528558
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java Fri Apr 13 10:16:39 2007
@@ -895,19 +895,7 @@
 			}
 		}
 
-		// At the end of our response, let the session do some book keeping
-		if (sessionExists())
-		{
-			try
-			{
-				getSession().update();
-			}
-			catch (RuntimeException re)
-			{
-				log.error("there was an error updating the session " + session + ".", re);
-			}
-		}
-
+		// if we have a request logger, update that now
 		try
 		{
 			IRequestLogger requestLogger = getApplication().getRequestLogger();
@@ -921,7 +909,7 @@
 			log.error("there was an error in the RequestLogger ending.", re);
 		}
 
-		// clear the used pagemap for this thread,
+		// let the session cleanup after a request, flushing changes etc.
 		if (sessionExists())
 		{
 			try
@@ -946,7 +934,6 @@
 				log.error("there was an error filtering the response.", re);
 			}
 		}
-
 
 		try
 		{

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Session.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Session.java?view=diff&rev=528558&r1=528557&r2=528558
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Session.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Session.java Fri Apr 13 10:16:39 2007
@@ -123,6 +123,44 @@
  */
 public abstract class Session implements IClusterable, IConverterLocator
 {
+	/** True, if session has been invalidated */
+	private transient boolean sessionInvalidated = false;
+
+	/**
+	 * Invalidates this session at the end of the current request. If you need
+	 * to invalidate the session immediately, you can do this by calling
+	 * invalidateNow(), however this will remove all Wicket components from this
+	 * session, which means that you will no longer be able to work with them.
+	 */
+	public void invalidate()
+	{
+		sessionInvalidated = true;
+	}
+
+	/**
+	 * Invalidates this session immediately. Calling this method will remove all
+	 * Wicket components from this session, which means that you will no longer
+	 * be able to work with them.
+	 */
+	public void invalidateNow()
+	{
+		sessionInvalidated = true; // set this for isSessionInvalidated
+		getSessionStore().invalidate(RequestCycle.get().getRequest());
+	}
+
+	/**
+	 * Whether the session is invalid now, or will be invalidated by the end of
+	 * the request. Clients should rarely need to use this method if ever.
+	 * 
+	 * @return Whether the session is invalid when the current request is done
+	 * 
+	 * @see #invalidate()
+	 * @see #invalidateNow()
+	 */
+	public final boolean isSessionInvalidated()
+	{
+		return sessionInvalidated;
+	}
 
 	/**
 	 * Visitor interface for visiting page maps
@@ -788,14 +826,6 @@
 	}
 
 	/**
-	 * Invalidates this session.
-	 */
-	public void invalidate()
-	{
-		getSessionStore().invalidate(RequestCycle.get().getRequest());
-	}
-
-	/**
 	 * Whether this session is temporary. A Wicket application can operate in a
 	 * session-less mode as long as stateless pages are used. If this session
 	 * object is temporary, it will not be available on a next request.
@@ -1038,6 +1068,10 @@
 	 */
 	protected void detach()
 	{
+		if (sessionInvalidated)
+		{
+			invalidateNow();
+		}
 	}
 
 	/**
@@ -1191,10 +1225,56 @@
 	}
 
 	/**
-	 * Updates the session at the end of a request, e.g. for replication
-	 * purposes.
+	 * @param page
+	 *            The page to add to dirty objects list
+	 */
+	void dirtyPage(final Page page)
+	{
+		List dirtyObjects = getDirtyObjectsList();
+		if (!dirtyObjects.contains(page))
+		{
+			dirtyObjects.add(page);
+		}
+	}
+
+
+	/**
+	 * @param map
+	 *            The page map to add to dirty objects list
+	 */
+	void dirtyPageMap(final IPageMap map)
+	{
+		if (!map.isDefault())
+		{
+			usedPageMaps.remove(map);
+			usedPageMaps.addLast(map);
+		}
+		List dirtyObjects = getDirtyObjectsList();
+		if (!dirtyObjects.contains(map))
+		{
+			dirtyObjects.add(map);
+		}
+	}
+
+	/**
+	 * @return The current thread dirty objects list
+	 */
+	List getDirtyObjectsList()
+	{
+		List list = (List)dirtyObjects.get();
+		if (list == null)
+		{
+			list = new ArrayList(4);
+			dirtyObjects.set(list);
+		}
+		return list;
+	}
+
+	/**
+	 * INTERNAL API. The request cycle when detached will call this.
+	 * 
 	 */
-	protected void update()
+	final void requestDetached()
 	{
 		List touchedPages = (List)Session.touchedPages.get();
 		Session.touchedPages.set(null);
@@ -1265,77 +1345,6 @@
 				setAttribute(attribute, object);
 			}
 		}
-	}
-
-	/**
-	 * @param page
-	 *            The page to add to dirty objects list
-	 */
-	void dirtyPage(final Page page)
-	{
-		List dirtyObjects = getDirtyObjectsList();
-		if (!dirtyObjects.contains(page))
-		{
-			dirtyObjects.add(page);
-		}
-	}
-
-
-	/**
-	 * @param map
-	 *            The page map to add to dirty objects list
-	 */
-	void dirtyPageMap(final IPageMap map)
-	{
-		if (!map.isDefault())
-		{
-			usedPageMaps.remove(map);
-			usedPageMaps.addLast(map);
-		}
-		List dirtyObjects = getDirtyObjectsList();
-		if (!dirtyObjects.contains(map))
-		{
-			dirtyObjects.add(map);
-		}
-	}
-
-	/**
-	 * @return The current thread dirty objects list
-	 */
-	List getDirtyObjectsList()
-	{
-		List list = (List)dirtyObjects.get();
-		if (list == null)
-		{
-			list = new ArrayList(4);
-			dirtyObjects.set(list);
-		}
-		return list;
-	}
-
-	/**
-	 * INTERNAL API. The request cycle when detached will call this.
-	 * 
-	 */
-	final void requestDetached()
-	{
-		List touchedPages = (List)Session.touchedPages.get();
-		Session.touchedPages.set(null);
-		if (touchedPages != null && touchedPages.size() > 0)
-		{
-			log
-					.warn("There were still touched pages in the request detach phase, session update wasn't called: "
-							+ touchedPages);
-		}
-
-		List dirtyObjects = (List)Session.dirtyObjects.get();
-		Session.dirtyObjects.set(null);
-		if (dirtyObjects != null && dirtyObjects.size() > 0)
-		{
-			log
-					.warn("There were still dirty objects in the request detach phase, session update wasn't called: "
-							+ dirtyObjects);
-		}
 
 		if (pageMapsUsedInRequest != null)
 		{
@@ -1354,5 +1363,15 @@
 				pageMapsUsedInRequest.notifyAll();
 			}
 		}
+	}
+
+	// TODO remove after deprecation release
+
+	/**
+	 * @deprecated obsolete method (was meant for internal book keeping really).
+	 *             Clients should use {@link #detach()} instead.
+	 */
+	protected final void update()
+	{
 	}
 }

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java?view=diff&rev=528558&r1=528557&r2=528558
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java Fri Apr 13 10:16:39 2007
@@ -28,13 +28,8 @@
  */
 public class WebSession extends Session
 {
-	/** log. careful, this log is used to trigger profiling too! */
-	// private static final Log log = LogFactory.getLog(WebSession.class);
 	private static final long serialVersionUID = 1L;
 
-	/** True, if session has been invalidated */
-	private transient boolean sessionInvalidated = false;
-
 	/**
 	 * Constructor. Note that {@link RequestCycle} is not available until this
 	 * constructor returns.
@@ -61,66 +56,5 @@
 	public WebSession(final WebApplication application, Request request)
 	{
 		super(application, request);
-	}
-
-	/**
-	 * Invalidates this session at the end of the current request. If you need
-	 * to invalidate the session immediately, you can do this by calling
-	 * invalidateNow(), however this will remove all Wicket components from this
-	 * session, which means that you will no longer be able to work with them.
-	 */
-	public void invalidate()
-	{
-		sessionInvalidated = true;
-	}
-
-	/**
-	 * Invalidates this session immediately. Calling this method will remove all
-	 * Wicket components from this session, which means that you will no longer
-	 * be able to work with them.
-	 */
-	public void invalidateNow()
-	{
-		sessionInvalidated = true; // set this for isSessionInvalidated
-		getSessionStore().invalidate(RequestCycle.get().getRequest());
-	}
-
-	/**
-	 * Whether the session is invalid now, or will be invalidated by the end of
-	 * the request. Clients should rarely need to use this method if ever.
-	 * 
-	 * @return Whether the session is invalid when the current request is done
-	 * 
-	 * @see #invalidate()
-	 * @see #invalidateNow()
-	 */
-	public final boolean isSessionInvalidated()
-	{
-		return sessionInvalidated;
-	}
-
-	/**
-	 * Called on the end of handling a request, when the RequestCycle is about
-	 * to be detached from the current thread.
-	 * 
-	 * @see org.apache.wicket.Session#detach()
-	 */
-	protected void detach()
-	{
-		if (sessionInvalidated)
-		{
-			invalidateNow();
-		}
-	}
-
-	/**
-	 * Updates the session, e.g. for replication purposes.
-	 */
-	protected void update()
-	{
-		if (sessionInvalidated == false)
-		{
-			super.update();
-		}
 	}
 }