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/30 23:55:51 UTC

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

Author: hlship
Date: Fri Sep 30 21:55:50 2011
New Revision: 1177852

URL: http://svn.apache.org/viewvc?rev=1177852&view=rev
Log:
TAP5-1678: Add ability, in development mode, to force a reload of component classes

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PageCatalog.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSource.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalComponentInvalidationEventHub.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=1177852&r1=1177851&r2=1177852&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 Fri Sep 30 21:55:50 2011
@@ -24,6 +24,7 @@ import org.apache.tapestry5.beaneditor.V
 import org.apache.tapestry5.corelib.components.Zone;
 import org.apache.tapestry5.func.F;
 import org.apache.tapestry5.func.Predicate;
+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.annotations.Inject;
@@ -73,6 +74,9 @@ public class PageCatalog
     @Validate("required")
     private String pageName;
 
+    @Inject
+    private ComponentInstantiatorSource componentInstantiatorSource;
+
     public List<String> getPageNames()
     {
         return resolver.getPageNames();
@@ -83,6 +87,21 @@ public class PageCatalog
         return pageSource.getAllPages();
     }
 
+    Object onActionFromReloadClasses()
+    {
+        if (productionMode)
+        {
+            alertManager.error("Forcing a class reload is only allowed when executing in development mode.");
+            return null;
+        }
+
+        componentInstantiatorSource.forceComponentInvalidation();
+
+        alertManager.info("Forced a component class reload.");
+
+        return pagesZone.getBody();
+    }
+
     Object onSuccessFromSinglePageLoad()
     {
         boolean found = !F.flow(getPages()).filter(new Predicate<Page>()

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSource.java?rev=1177852&r1=1177851&r2=1177852&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSource.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSource.java Fri Sep 30 21:55:50 2011
@@ -15,10 +15,8 @@
 package org.apache.tapestry5.internal.services;
 
 import org.apache.tapestry5.ioc.annotations.UsesMappedConfiguration;
-import org.apache.tapestry5.ioc.internal.services.CtClassSource;
 import org.apache.tapestry5.ioc.services.ClassFactory;
 import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
-import org.apache.tapestry5.services.InvalidationEventHub;
 import org.apache.tapestry5.services.transform.ControlledPackageType;
 
 /**
@@ -31,7 +29,7 @@ import org.apache.tapestry5.services.tra
  * The strategy used is that when <em>any</em> class (in a controlled package) changes, the entire class loader is
  * discarded, along with any instances derived from those classes. A new class loader is created, and then invalidation
  * events are fired to listeners.
- * <p>
+ * <p/>
  * Starting in Tapestry 5.3, the packages that are loaded are controlled by a configuration that maps package names to
  * {@link ControlledPackageType}s.
  */
@@ -44,18 +42,16 @@ public interface ComponentInstantiatorSo
      * repeated calls to this method with the same class name will return the same instance; however, callers should
      * also be aware that the instantiators may lose validity after an invalidation (caused by changes to external Java
      * class files).
-     * 
-     * @param classname
-     *            FQCN to find (and perhaps transform and load)
+     *
+     * @param classname FQCN to find (and perhaps transform and load)
      * @return an object which can instantiate an instance of the component
      */
     Instantiator getInstantiator(String classname);
 
     /**
      * Checks to see if a fully qualified class name exists. This method appears to exist only for testing.
-     * 
-     * @param className
-     *            name of class to check
+     *
+     * @param className name of class to check
      * @return true if the class exists (there's a ".class" file), false otherwise
      */
     boolean exists(String className);
@@ -63,7 +59,7 @@ public interface ComponentInstantiatorSo
     /**
      * Returns a class factory that can be used to generate additional classes around enhanced classes, or create
      * subclasses of enhanced classes.
-     * 
+     *
      * @deprecated Deprecated in 5.3, to be removed in 5.4
      */
     ClassFactory getClassFactory();
@@ -71,8 +67,16 @@ public interface ComponentInstantiatorSo
     /**
      * Returns a proxy factory that can be used to generate additional classes around enhanced classes, or create
      * subclasses of enhanced classes.
-     * 
+     *
      * @since 5.3
      */
     PlasticProxyFactory getProxyFactory();
+
+    /**
+     * Forces invalidation logic, as if a component class on the disk had changed, forcing a reload
+     * of all pages and components.
+     *
+     * @since 5.3
+     */
+    void forceComponentInvalidation();
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java?rev=1177852&r1=1177851&r2=1177852&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java Fri Sep 30 21:55:50 2011
@@ -164,6 +164,12 @@ public final class ComponentInstantiator
         }
     }
 
+    public void forceComponentInvalidation()
+    {
+        changeTracker.clear();
+        invalidationHub.classInControlledPackageHasChanged();
+    }
+
     public void objectWasInvalidated()
     {
         changeTracker.clear();

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalComponentInvalidationEventHub.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalComponentInvalidationEventHub.java?rev=1177852&r1=1177851&r2=1177852&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalComponentInvalidationEventHub.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalComponentInvalidationEventHub.java Fri Sep 30 21:55:50 2011
@@ -18,10 +18,10 @@ import org.apache.tapestry5.services.Inv
 import org.apache.tapestry5.services.InvalidationListener;
 
 /**
- * Split-out implementation of {@link InvalidationEventHub} that seperates it from {@link ComponentInstantiatorSource}.
+ * Split-out implementation of {@link InvalidationEventHub} that separates it from {@link ComponentInstantiatorSource}.
  * This was necessary due to some refactoring that made {@link ComponentClassResolver} and ComponentInstantiatorSource
  * mutually dependent.
- * 
+ *
  * @since 5.3
  */
 public interface InternalComponentInvalidationEventHub extends InvalidationEventHub

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=1177852&r1=1177851&r2=1177852&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 Fri Sep 30 21:55:50 2011
@@ -16,6 +16,9 @@
                     <t:actionlink t:id="clearCache">clear the cache</t:actionlink>
                 </li>
                 <li>
+                    <t:actionlink t:id="reloadClasses" zone="pages">reload component classes</t:actionlink>
+                </li>
+                <li>
                     <t:actionlink t:id="runGC">Run the GC</t:actionlink>
                 </li>
             </t:if>
@@ -39,6 +42,10 @@
             <p:selectorCell>
                 ${page.selector.toShortString()}
             </p:selectorCell>
+            <p:empty>
+                <p><em>There are no pages in the page cache. This can only occur immediately after reloading all
+                    component classes.</em></p>
+            </p:empty>
         </t:grid>
 
     </t:zone>