Author: jcompagner
Date: Tue May 13 01:54:09 2008
New Revision: 655786

URL: http://svn.apache.org/viewvc?rev=655786&view=rev
Log:
WICKET-1409 RequestLogger counts active requests wrong
moved the call to end the RequestLogger as far down as we can in 
RequestCycle.detach()
RequestCycle.detach now try/catch with Throwable because everything really 
should be tried again else there will be loads of things hanging around.
Removed the thread local from RequestLogger

Modified:
    
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
    
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/RequestLogger.java

Modified: 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java?rev=655786&r1=655785&r2=655786&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
 (original)
+++ 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
 Tue May 13 01:54:09 2008
@@ -1048,7 +1048,7 @@
                                {
                                        target.detach(this);
                                }
-                               catch (RuntimeException e)
+                               catch (Throwable e)
                                {
                                        log.error("there was an error cleaning 
up target " + target + ".", e);
                                }
@@ -1066,26 +1066,12 @@
                                        getSession().cleanupFeedbackMessages();
                                }
                        }
-                       catch (RuntimeException re)
+                       catch (Throwable re)
                        {
                                log.error("there was an error cleaning up the 
feedback messages", re);
                        }
                }
 
-               // if we have a request logger, update that now
-               try
-               {
-                       IRequestLogger requestLogger = 
getApplication().getRequestLogger();
-                       if (requestLogger != null)
-                       {
-                               
requestLogger.requestTime((System.currentTimeMillis() - startTime));
-                       }
-               }
-               catch (RuntimeException re)
-               {
-                       log.error("there was an error in the RequestLogger 
ending.", re);
-               }
-
                // let the session cleanup after a request, flushing changes 
etc.
                if (sessionExists())
                {
@@ -1093,7 +1079,7 @@
                        {
                                getSession().requestDetached();
                        }
-                       catch (RuntimeException re)
+                       catch (Throwable re)
                        {
                                log.error("there was an error detaching the 
request from the session " + session +
                                        ".", re);
@@ -1106,7 +1092,7 @@
                        {
                                ((BufferedWebResponse)getResponse()).filter();
                        }
-                       catch (RuntimeException re)
+                       catch (Throwable re)
                        {
                                log.error("there was an error filtering the 
response.", re);
                        }
@@ -1116,7 +1102,7 @@
                {
                        onEndRequest();
                }
-               catch (RuntimeException e)
+               catch (Throwable e)
                {
                        log.error("Exception occurred during onEndRequest", e);
                }
@@ -1125,17 +1111,32 @@
                {
                        
getApplication().getSessionStore().onEndRequest(getRequest());
                }
-               catch (RuntimeException e)
+               catch (Throwable e)
                {
                        log.error("Exception occurred during onEndRequest of 
the SessionStore", e);
                }
 
+               // if we have a request logger, update that now
+               try
+               {
+                       IRequestLogger requestLogger = 
getApplication().getRequestLogger();
+                       if (requestLogger != null)
+                       {
+                               
requestLogger.requestTime((System.currentTimeMillis() - startTime));
+                       }
+               }
+               catch (Throwable re)
+               {
+                       log.error("there was an error in the RequestLogger 
ending.", re);
+               }
+
+
                // Release thread local resources
                try
                {
                        threadDetach();
                }
-               catch (RuntimeException re)
+               catch (Throwable re)
                {
                        log.error("Exception occurred during threadDetach", re);
                }

Modified: 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/RequestLogger.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/RequestLogger.java?rev=655786&r1=655785&r2=655786&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/RequestLogger.java
 (original)
+++ 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/RequestLogger.java
 Tue May 13 01:54:09 2008
@@ -28,7 +28,9 @@
 import org.apache.wicket.IClusterable;
 import org.apache.wicket.IPageMap;
 import org.apache.wicket.IRequestTarget;
+import org.apache.wicket.MetaDataKey;
 import org.apache.wicket.Page;
+import org.apache.wicket.RequestCycle;
 import org.apache.wicket.Session;
 import 
org.apache.wicket.request.target.component.IBookmarkablePageRequestTarget;
 import org.apache.wicket.request.target.component.IPageRequestTarget;
@@ -63,6 +65,11 @@
        protected static Logger log = 
LoggerFactory.getLogger(RequestLogger.class);
 
 
+       private static MetaDataKey REQUEST_DATA = new 
MetaDataKey(RequestData.class)
+       {
+               private static final long serialVersionUID = 1L;
+       };
+
        /**
         * This interface can be implemented in a custom session object. to 
give an object that has more
         * information for the current session (state of session).
@@ -91,8 +98,6 @@
 
        private final Map liveSessions;
 
-       private final ThreadLocal currentRequest = new ThreadLocal();
-
        private int active;
 
        /**
@@ -154,7 +159,7 @@
        public SessionData[] getLiveSessions()
        {
                SessionData[] sessions = 
(SessionData[])liveSessions.values().toArray(
-                               new SessionData[liveSessions.size()]);
+                       new SessionData[liveSessions.size()]);
                Arrays.sort(sessions);
                return sessions;
        }
@@ -182,11 +187,12 @@
 
        RequestData getCurrentRequest()
        {
-               RequestData rd = (RequestData)currentRequest.get();
+               RequestCycle requestCycle = RequestCycle.get();
+               RequestData rd = 
(RequestData)requestCycle.getMetaData(REQUEST_DATA);
                if (rd == null)
                {
                        rd = new RequestData();
-                       currentRequest.set(rd);
+                       requestCycle.setMetaData(REQUEST_DATA, rd);
                        synchronized (this)
                        {
                                active++;
@@ -200,7 +206,7 @@
         */
        public void requestTime(long timeTaken)
        {
-               RequestData rd = (RequestData)currentRequest.get();
+               RequestData rd = 
(RequestData)RequestCycle.get().getMetaData(REQUEST_DATA);
                if (rd != null)
                {
                        synchronized (this)
@@ -229,17 +235,15 @@
                                        // log the error and let the request 
logging continue (this is what happens in
                                        // the
                                        // detach phase of the request cycle 
anyway. This provides better diagnostics).
-                                       log
-                                                       .error(
-                                                                       
"Exception while determining the size of the session in the request logger: " +
-                                                                               
        e.getMessage(), e);
+                                       log.error(
+                                               "Exception while determining 
the size of the session in the request logger: " +
+                                                       e.getMessage(), e);
                                }
                        }
                        rd.setSessionSize(sizeInBytes);
                        rd.setTimeTaken(timeTaken);
 
                        requests.add(0, rd);
-                       currentRequest.set(null);
                        if (sessionId != null)
                        {
                                SessionData sd = 
(SessionData)liveSessions.get(sessionId);
@@ -345,7 +349,7 @@
                {
                        IPageMap map = (IPageMap)value;
                        rd.addEntry("PageMap removed, name: " +
-                                       (map.getName() == null ? "DEFAULT" : 
map.getName()));
+                               (map.getName() == null ? "DEFAULT" : 
map.getName()));
                }
                else if (value instanceof WebSession)
                {
@@ -372,7 +376,7 @@
                {
                        IPageMap map = (IPageMap)value;
                        rd.addEntry("PageMap updated, name: " +
-                                       (map.getName() == null ? "DEFAULT" : 
map.getName()));
+                               (map.getName() == null ? "DEFAULT" : 
map.getName()));
                }
                else if (value instanceof Session)
                {
@@ -404,7 +408,7 @@
                {
                        IPageMap map = (IPageMap)value;
                        rd.addEntry("PageMap created, name: " +
-                                       (map.getName() == null ? "DEFAULT" : 
map.getName()));
+                               (map.getName() == null ? "DEFAULT" : 
map.getName()));
                }
                else
                {
@@ -770,9 +774,9 @@
                public String toString()
                {
                        return "Request[timetaken=" + getTimeTaken() + 
",sessioninfo=" + sessionInfo +
-                                       ",sessionid=" + sessionId + 
",sessionsize=" + totalSessionSize + ",request=" +
-                                       eventTarget + ",response=" + 
responseTarget + ",alteredobjects=" +
-                                       getAlteredObjects() + ",activerequest=" 
+ activeRequest + "]";
+                               ",sessionid=" + sessionId + ",sessionsize=" + 
totalSessionSize + ",request=" +
+                               eventTarget + ",response=" + responseTarget + 
",alteredobjects=" +
+                               getAlteredObjects() + ",activerequest=" + 
activeRequest + "]";
                }
        }
 }


Reply via email to