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/13 21:18:10 UTC

svn commit: r1183041 - in /tapestry/tapestry5/trunk/tapestry-core/src/main: java/org/apache/tapestry5/corelib/pages/ resources/org/apache/tapestry5/corelib/pages/

Author: hlship
Date: Thu Oct 13 19:18:09 2011
New Revision: 1183041

URL: http://svn.apache.org/viewvc?rev=1183041&view=rev
Log:
Display some total information on the PageCatalog page

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

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=1183041&r1=1183040&r2=1183041&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 Thu Oct 13 19:18:09 2011
@@ -16,14 +16,11 @@ package org.apache.tapestry5.corelib.pag
 
 import org.apache.tapestry5.SymbolConstants;
 import org.apache.tapestry5.alerts.AlertManager;
-import org.apache.tapestry5.annotations.ContentType;
-import org.apache.tapestry5.annotations.InjectComponent;
-import org.apache.tapestry5.annotations.Persist;
-import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.annotations.*;
+import org.apache.tapestry5.beaneditor.ReorderProperties;
 import org.apache.tapestry5.beaneditor.Validate;
 import org.apache.tapestry5.corelib.components.Zone;
-import org.apache.tapestry5.func.F;
-import org.apache.tapestry5.func.Predicate;
+import org.apache.tapestry5.func.*;
 import org.apache.tapestry5.internal.services.ComponentInstantiatorSource;
 import org.apache.tapestry5.internal.services.PageSource;
 import org.apache.tapestry5.internal.structure.Page;
@@ -31,6 +28,7 @@ import org.apache.tapestry5.ioc.Operatio
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.services.ComponentClassResolver;
 import org.apache.tapestry5.services.pageload.ComponentResourceSelector;
 
@@ -45,6 +43,33 @@ import java.util.Set;
 @ContentType("text/html")
 public class PageCatalog
 {
+    @ReorderProperties("definedPages,loadedPages,uniquePageNames,selectors,components")
+    public class Totals
+    {
+        /**
+         * Total number of pages loaded.
+         */
+        public int loadedPages;
+
+        /**
+         * Number of total page names.
+         */
+        public int definedPages;
+        /**
+         * Number of unique page names (remember, same page may appear for multiple selectors).
+         */
+        public int uniquePageNames;
+        /**
+         * Total number of components.
+         */
+        public int components;
+
+        /**
+         * All selectors represented in the pool, often just 'en'.
+         */
+        public String selectors;
+    }
+
     @Property
     @Inject
     @Symbol(SymbolConstants.PRODUCTION_MODE)
@@ -82,6 +107,46 @@ public class PageCatalog
     @Inject
     private ComponentInstantiatorSource componentInstantiatorSource;
 
+    @Cached
+    public Totals getTotals()
+    {
+
+        Totals result = new Totals();
+
+        Flow<Page> pages = F.flow(getPages());
+
+        result.loadedPages = pages.count();
+        result.definedPages = getPageNames().size();
+        result.uniquePageNames = pages.map(new Mapper<Page, String>()
+        {
+            public String map(Page element)
+            {
+                return element.getName();
+            }
+        }).toSet().size();
+
+        result.components = pages.reduce(new Reducer<Integer, Page>()
+        {
+            public Integer reduce(Integer accumulator, Page element)
+            {
+                return accumulator + element.getComponentCount();
+            }
+        }, 0);
+
+        Set<String> selectorIds = pages.map(new Mapper<Page, String>()
+        {
+            public String map(Page element)
+            {
+                return element.getSelector().toShortString();
+            }
+        }).toSet();
+
+        result.selectors = InternalUtils.joinSorted(selectorIds);
+
+        return result;
+
+    }
+
     public List<String> getPageNames()
     {
         return resolver.getPageNames();

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PageCatalog.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PageCatalog.properties?rev=1183041&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PageCatalog.properties (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PageCatalog.properties Thu Oct 13 19:18:09 2011
@@ -0,0 +1,3 @@
+loadedpages-title=Pages in Cache
+components-title=Total Number of Components
+selectors-title=Active Selectors

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PageCatalog.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PageCatalog.tml?rev=1183041&r1=1183040&r2=1183041&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PageCatalog.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PageCatalog.tml Thu Oct 13 19:18:09 2011
@@ -30,10 +30,10 @@
     <t:zone t:id="pagesZone" id="pages">
 
         <p xml:space="preserve">
-            This page provides a list of pages currently loaded in the application. There are currently
-            <strong>${pages.size()}</strong> page instances in the page cache.
+            This page provides a list of pages currently loaded in the application.
         </p>
 
+        <t:beandisplay object="totals"/>
 
         <t:grid source="pages" row="page" add="selector" reorder="name,selector">
             <p:assemblyTimeCell>