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/09/29 22:11:21 UTC
svn commit: r1177417 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/corelib/pages/
main/resources/org/apache/tapestry5/corelib/pages/
test/groovy/org/apache/tapestry5/integration/app3/
Author: hlship
Date: Thu Sep 29 20:11:21 2011
New Revision: 1177417
URL: http://svn.apache.org/viewvc?rev=1177417&view=rev
Log:
TAP5-1678: Improvements to PageCatalog
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
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app3/PageCatalogTests.groovy
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=1177417&r1=1177416&r2=1177417&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 Sep 29 20:11:21 2011
@@ -17,15 +17,20 @@ 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.corelib.components.Zone;
import org.apache.tapestry5.internal.services.PageSource;
import org.apache.tapestry5.internal.structure.Page;
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.services.ComponentClassResolver;
import org.apache.tapestry5.services.pageload.ComponentResourceSelector;
import java.util.Collection;
+import java.util.Set;
/**
* Lists out the currently loaded pages, using a {@link Grid}. Provides an option to force all pages to be loaded. In development mode,
@@ -54,39 +59,111 @@ public class PageCatalog
@Property
private Page page;
+ @InjectComponent
+ private Zone pagesZone;
+
+ @Persist
+ private Set<String> failures;
+
public Collection<Page> getPages()
{
return pageSource.getAllPages();
}
- void onActionFromForceLoad()
+ Object onActionFromForceLoad()
{
+ if (failures == null)
+ {
+ failures = CollectionFactory.newSet();
+ }
+
+ long startTime = System.currentTimeMillis();
+
+ Collection<Page> initialPages = getPages();
+
+ int loadedCount = 0;
- int startCount = getPages().size();
+ RuntimeException fail = null;
+
+ boolean someFail = false;
for (String name : resolver.getPageNames())
{
- pageSource.getPage(name);
+ if (failures.contains(name))
+ {
+ alertManager.warn(String.format("Skipping page %s due to prior load failure.", name));
+ someFail = true;
+ continue;
+ }
+
+ try
+ {
+ 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);
+ fail = ex;
+ break;
+ }
}
- int added = getPages().size() - startCount;
+ alertManager.info(String.format("Loaded %,d new pages for selector '%s' (in %,d ms).", loadedCount,
+ selector.toShortString(), System.currentTimeMillis() - startTime));
+
+ if (someFail)
+ {
+ alertManager.warn("Clear the cache to reset the list of failed pages.");
+ }
+
+ if (fail != null)
+ {
+ throw fail;
+ }
- alertManager.info(String.format("Loaded %,d new pages for selector '%s'.", added, selector.toShortString()));
+ return pagesZone.getBody();
}
void onActionFromClearCache()
{
if (productionMode)
{
- alertManager.error("Clearing the cache is not allowed in production mode");
+ alertManager.error("Clearing the cache is only allowed in development mode.");
return;
}
pageSource.clearCache();
+ failures = null;
+
alertManager.info("Page cache cleared.");
}
+ void onActionFromRunGC()
+ {
+ if (productionMode)
+ {
+ alertManager.error("Executing a garbage collection is only allowed in development mode.");
+ return;
+ }
+
+ Runtime runtime = Runtime.getRuntime();
+
+ long initialFreeMemory = runtime.freeMemory();
+
+ runtime.gc();
+
+ long delta = runtime.freeMemory() - initialFreeMemory;
+
+ alertManager.info(String.format("Garbage collection freed %,.2f Kb of memory.",
+ ((double) delta) / 1024.0d));
+ }
+
public String formatElapsed(long millis)
{
return String.format("%,d ms", millis);
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=1177417&r1=1177416&r2=1177417&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 Sep 29 20:11:21 2011
@@ -6,38 +6,43 @@
<h1>Tapestry Page Catalog</h1>
-<t:alerts/>
-
<p>
- This page provides a list of pages currently loaded in the application.
+ 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.
</p>
<p>Actions:</p>
<ul>
<li>
- <t:pagelink page="pagecatalog">refresh the page</t:pagelink>
+ <t:pagelink page="pagecatalog">refresh this page</t:pagelink>
</li>
<li>
- <t:actionlink t:id="forceLoad">load all pages</t:actionlink>
+ <t:actionlink t:id="forceLoad" zone="pages">load all pages</t:actionlink>
</li>
<t:if test="! productionMode">
<li>
<t:actionlink t:id="clearCache">clear the cache</t:actionlink>
</li>
+ <li>
+ <t:actionlink t:id="runGC">Run the Java Garbage Collector</t:actionlink>
+ </li>
</t:if>
</ul>
-<t:grid source="pages" row="page" add="selector" reorder="name,selector">
- <p:nameCell>
- <t:pagelink page="prop:page.name">${page.name}</t:pagelink>
- </p:nameCell>
- <p:assemblyTimeCell>
- ${formatElapsed(page.assemblyTime)}
- </p:assemblyTimeCell>
- <p:selectorCell>
- ${page.selector.toShortString()}
- </p:selectorCell>
-</t:grid>
+<t:alerts/>
+
+<t:zone t:id="pagesZone" id="pages">
+
+ <t:grid source="pages" row="page" add="selector" reorder="name,selector">
+ <p:assemblyTimeCell>
+ ${formatElapsed(page.assemblyTime)}
+ </p:assemblyTimeCell>
+ <p:selectorCell>
+ ${page.selector.toShortString()}
+ </p:selectorCell>
+ </t:grid>
+
+</t:zone>
</body>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app3/PageCatalogTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app3/PageCatalogTests.groovy?rev=1177417&r1=1177416&r2=1177417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app3/PageCatalogTests.groovy (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app3/PageCatalogTests.groovy Thu Sep 29 20:11:21 2011
@@ -9,7 +9,6 @@ class PageCatalogTests extends SeleniumT
@Test
void load_page_catalog_page()
{
-
open("${baseURL}pagecatalog")
assertTitle "Tapestry Page Catalog"
@@ -23,5 +22,10 @@ class PageCatalogTests extends SeleniumT
assertTitle "Tapestry Page Catalog"
assertTextPresent "Page cache cleared"
+
+ clickAndWait "link=Run the Java Garbage Collector"
+
+ assertTextPresent "Garbage collection freed"
+
}
}