Author: jcompagner
Date: Sun Jun  3 05:32:56 2007
New Revision: 543885

URL: http://svn.apache.org/viewvc?view=rev&rev=543885
Log:
moved the restoredPages/usedPages too SecondLevelStore itself so that over the 
whole request
one page is only once deserialized and constructed
onEnd and onBeginRequest of the ISessionStore are implemented now (the methods 
where there but never called!)

Modified:
    
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
    
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/FilePageStore.java
    
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/SecondLevelCacheSessionStore.java

Modified: 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java?view=diff&rev=543885&r1=543884&r2=543885
==============================================================================
--- 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
 (original)
+++ 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
 Sun Jun  3 05:32:56 2007
@@ -962,7 +962,7 @@
                                                + ".", re);
                        }
                }
-
+               
                if (getResponse() instanceof BufferedWebResponse)
                {
                        try
@@ -983,7 +983,16 @@
                {
                        log.error("Exception occurred during onEndRequest", e);
                }
-
+               
+               try
+               {
+                       
getApplication().getSessionStore().onEndRequest(getRequest());
+               }
+               catch (RuntimeException e)
+               {
+                       log.error("Exception occurred during onEndRequest of 
the SessionStore", e);
+               }
+               
                // Release thread local resources
                try
                {
@@ -1001,6 +1010,14 @@
         */
        private void prepare()
        {
+               try
+               {
+                       
getApplication().getSessionStore().onBeginRequest(getRequest());
+               }
+               catch (RuntimeException e)
+               {
+                       log.error("Exception occurred during onEndRequest of 
the SessionStore", e);
+               }
                // Event callback
                onBeginRequest();
        }

Modified: 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/FilePageStore.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/FilePageStore.java?view=diff&rev=543885&r1=543884&r2=543885
==============================================================================
--- 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/FilePageStore.java
 (original)
+++ 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/FilePageStore.java
 Sun Jun  3 05:32:56 2007
@@ -390,8 +390,6 @@
 
        private volatile long totalSerializationTime = 0;
        
-       private static final ThreadLocal restoredPages = new ThreadLocal();
-
        /**
         * Construct.
         */
@@ -532,14 +530,12 @@
         */
        private Page readPage(int versionNumber, byte[] bytes)
        {
+               boolean set = Page.serializer.get() == null; 
                Page page = null;
-               Map map = null;
                try
                {
-                       if (restoredPages.get() == null)
+                       if (set)
                        {
-                               map = new HashMap();
-                               restoredPages.set(map);
                                Page.serializer.set(new PageSerializer(null));
                        }
                        IPageMapEntry entry = 
(IPageMapEntry)Objects.byteArrayToObject(bytes);
@@ -551,10 +547,9 @@
                } 
                finally
                {
-                       if (map != null)
+                       if (set)
                        {
                                Page.serializer.set(null);
-                               restoredPages.set(null);
                        }
                }
                return page;
@@ -860,21 +855,20 @@
 
                public Page deserializePage(int id, String name, Page page, 
ObjectInputStream stream) throws IOException, ClassNotFoundException
                {
-                       HashMap map = (HashMap)restoredPages.get();
-                       if (map != null)
+                       HashMap pageMaps = 
(HashMap)SecondLevelCacheSessionStore.usedPages.get();
+                       if (pageMaps == null)
                        {
-                               IntHashMap pagesMap = (IntHashMap)map.get(name);
-                               if (pagesMap == null)
-                               {
-                                       pagesMap = new IntHashMap();
-                                       map.put(name, pagesMap);
-                               }
-                               
-                               pagesMap.put(id, page);
+                               pageMaps = new HashMap();
+                               
SecondLevelCacheSessionStore.usedPages.set(pageMaps);
                        }
-                       
+                       IntHashMap pages = (IntHashMap)pageMaps.get(name);
+                       if (pages == null)
+                       {
+                               pages = new IntHashMap();
+                               pageMaps.put(name, pages);
+                       }
+                       pages.put(id, page);
                        boolean b = stream.readBoolean();
-                       
                        if (b == false) 
                        {
                                stream.defaultReadObject();
@@ -906,27 +900,7 @@
                
                protected Object readResolve() throws ObjectStreamException
                {
-                       IntHashMap intHashMap = null;
-                       Map map = (Map)restoredPages.get();
-                       if (map != null)
-                       {
-                               intHashMap = (IntHashMap)map.get(pagemap);
-                               if (intHashMap == null)
-                               {
-                                       intHashMap = new IntHashMap();
-                                       map.put(pagemap, intHashMap);
-                               }
-                       }
-                       Page page = (Page)intHashMap.get(pageid);
-                       if (page == null)
-                       {
-                               page = Session.get().getPage(pagemap, 
Integer.toString(pageid), -1);
-                               if (page != null)
-                               {
-                                       intHashMap.put(pageid, page);
-                               }
-                       }
-                       return page;
+                       return Session.get().getPage(pagemap, 
Integer.toString(pageid), -1);
                }
        }
 }

Modified: 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/SecondLevelCacheSessionStore.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/SecondLevelCacheSessionStore.java?view=diff&rev=543885&r1=543884&r2=543885
==============================================================================
--- 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/SecondLevelCacheSessionStore.java
 (original)
+++ 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/SecondLevelCacheSessionStore.java
 Sun Jun  3 05:32:56 2007
@@ -18,6 +18,7 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 
 import org.apache.wicket.Application;
@@ -28,6 +29,7 @@
 import org.apache.wicket.PageMap;
 import org.apache.wicket.Request;
 import org.apache.wicket.session.pagemap.IPageMapEntry;
+import org.apache.wicket.util.collections.IntHashMap;
 import org.apache.wicket.version.IPageVersionManager;
 import org.apache.wicket.version.undo.Change;
 
@@ -41,8 +43,8 @@
 {
        /**
         * This interface is used by the SecondLevelCacheSessionStore so that 
pages
-        * can be stored to a persistent layer. Implemenation should store the 
page
-        * that it gets under the id and versionnumber. So that every page 
version
+        * can be stored to a persistent layer. Implementation should store the 
page
+        * that it gets under the id and version number. So that every page 
version
         * can be reconstructed when asked for.
         * 
         * @see FilePageStore as default implementation.
@@ -70,8 +72,8 @@
 
                /**
                 * This method is called when the page is accessed. A IPageStore
-                * implemenation can block until a save of that page version is 
done. So
-                * that a specifiek page version is always restoreable.
+                * implementation can block until a save of that page version 
is done. So
+                * that a specific page version is always restore able.
                 * 
                 * @param sessionId
                 * @param page
@@ -126,6 +128,25 @@
 
                public Page get(int id, int versionNumber)
                {
+                       HashMap pageMaps = (HashMap)usedPages.get();
+                       if (pageMaps == null)
+                       {
+                               pageMaps = new HashMap();
+                               usedPages.set(pageMaps);
+                       }
+                       IntHashMap pages = (IntHashMap)pageMaps.get(getName());
+                       if (pages == null)
+                       {
+                               pages = new IntHashMap();
+                               pageMaps.put(getName(), pages);
+                       }
+                       
+                       // for now i only get by id.
+                       // does it really make any sense that there are 
multiply instances of the 
+                       // same page are alive in one session??
+                       Page page = (Page)pages.get(id);
+                       if (page != null) return page;
+                       
                        PageVersions pv = null;
                        if (versionNumber == -1)
                        {
@@ -143,11 +164,12 @@
                        String sessionId = getSession().getId();
                        if (lastPage != null && lastPage.getNumericId() == id)
                        {
-                               Page page = lastPage.getVersion(versionNumber);
+                               page = lastPage.getVersion(versionNumber);
                                if (page != null)
                                {
                                        // ask the page store if it is ready 
saving the page.
                                        getStore().pageAccessed(sessionId, 
page);
+                                       pages.put(id,page);
                                        return page;
                                }
                        }
@@ -167,7 +189,10 @@
                                        ajaxVersionNumber = pv.ajaxversionid;
                                }
                                lastPage = null;
-                               return getStore().getPage(sessionId, getName(), 
id, versionNumber, ajaxVersionNumber);
+                               page = getStore().getPage(sessionId, getName(), 
id, versionNumber, ajaxVersionNumber);
+                               pages.put(id,page);
+                               return page;
+                               
                        }
                        return null;
                }
@@ -465,6 +490,8 @@
                }
 
        }
+       
+       static final ThreadLocal usedPages = new ThreadLocal();
 
        private IPageStore pageStore;
 
@@ -483,10 +510,10 @@
 
                this.pageStore = pageStore;
 
-               // turn automatic multiwindow support off by default, as we 
don't really
+               // turn automatic multi window support off by default, as we 
don't really
                // need to be afraid to run out of history with this 
implementation.
                // note that the session store is created before 
Application#init is
-               // called, so if users set this setting explicitly, it'll be 
overriden
+               // called, so if users set this setting explicitly, it'll be 
overridden
                // (and that's exactly what we want: provide a better default, 
but not
                // forcing people to do away with this feature).
                
Application.get().getPageSettings().setAutomaticMultiWindowSupport(false);
@@ -501,6 +528,14 @@
                return new SecondLevelCachePageMap(name);
        }
 
+       /**
+        * @see 
org.apache.wicket.protocol.http.AbstractHttpSessionStore#onEndRequest(org.apache.wicket.Request)
+        */
+       public void onEndRequest(Request request)
+       {
+               super.onEndRequest(request);
+               usedPages.set(null);
+       }
        /**
         * @see 
org.apache.wicket.protocol.http.AbstractHttpSessionStore#destroy()
         */


Reply via email to