You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/10/11 02:43:32 UTC

svn commit: r1181321 - /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PageCatalog.java

Author: hlship
Date: Tue Oct 11 00:43:31 2011
New Revision: 1181321

URL: http://svn.apache.org/viewvc?rev=1181321&view=rev
Log:
Use the OperationTracker to identify which page is being loaded

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PageCatalog.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PageCatalog.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PageCatalog.java?rev=1181321&r1=1181320&r2=1181321&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PageCatalog.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PageCatalog.java Tue Oct 11 00:43:31 2011
@@ -27,6 +27,7 @@ import org.apache.tapestry5.func.Predica
 import org.apache.tapestry5.internal.services.ComponentInstantiatorSource;
 import org.apache.tapestry5.internal.services.PageSource;
 import org.apache.tapestry5.internal.structure.Page;
+import org.apache.tapestry5.ioc.OperationTracker;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
@@ -76,6 +77,9 @@ public class PageCatalog
     private String pageName;
 
     @Inject
+    private OperationTracker operationTracker;
+
+    @Inject
     private ComponentInstantiatorSource componentInstantiatorSource;
 
     public List<String> getPageNames()
@@ -136,6 +140,13 @@ public class PageCatalog
         return pagesZone.getBody();
     }
 
+    private class PageLoadData
+    {
+        int loadedCount;
+        RuntimeException fail;
+        boolean someFail;
+    }
+
     Object onActionFromForceLoad()
     {
         if (failures == null)
@@ -145,57 +156,62 @@ public class PageCatalog
 
         long startTime = System.currentTimeMillis();
 
-        Collection<Page> initialPages = getPages();
-
-        int loadedCount = 0;
-
-        RuntimeException fail = null;
+        final Collection<Page> initialPages = getPages();
 
-        boolean someFail = false;
+        final PageLoadData data = new PageLoadData();
 
-        for (String name : resolver.getPageNames())
+        for (final String name : resolver.getPageNames())
         {
             if (failures.contains(name))
             {
                 alertManager.warn(String.format("Skipping page %s due to prior load failure.", name));
-                someFail = true;
+                data.someFail = true;
                 continue;
             }
 
-            try
+            operationTracker.run("Loading page " + name, new Runnable()
             {
-                Page newPage = pageSource.getPage(name);
-
-                if (!initialPages.contains(newPage))
-                {
-                    loadedCount++;
-                }
-            } catch (RuntimeException ex)
-            {
-                alertManager.error(String.format("Page %s failed to load.", name));
-                failures.add(name);
-
-                if (fail == null)
+                public void run()
                 {
-                    pageName = name;
-                    fail = ex;
+                    try
+                    {
+                        Page newPage = pageSource.getPage(name);
+
+                        if (!initialPages.contains(newPage))
+                        {
+                            data.loadedCount++;
+                        }
+                    } catch (RuntimeException ex)
+                    {
+                        alertManager.error(String.format("Page %s failed to load.", name));
+                        failures.add(name);
+
+                        if (data.fail == null)
+                        {
+                            pageName = name;
+                            data.fail = ex;
+                        }
+                    }
                 }
+            });
 
+            if (data.fail != null)
+            {
                 break;
             }
         }
 
-        alertManager.info(String.format("Loaded %,d new pages for selector '%s' (in %,d ms).", loadedCount,
+        alertManager.info(String.format("Loaded %,d new pages for selector '%s' (in %,d ms).", data.loadedCount,
                 selector.toShortString(), System.currentTimeMillis() - startTime));
 
-        if (someFail)
+        if (data.someFail)
         {
             alertManager.warn("Clear the cache to reset the list of failed pages.");
         }
 
-        if (fail != null)
+        if (data.fail != null)
         {
-            throw fail;
+            throw data.fail;
         }
 
         return pagesZone.getBody();