click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r958255 - /click/trunk/click/mock/src/org/apache/click/MockContext.java
Date Sat, 26 Jun 2010 17:48:56 GMT
Author: sabob
Date: Sat Jun 26 17:48:55 2010
New Revision: 958255

URL: http://svn.apache.org/viewvc?rev=958255&view=rev
Log:
added reset method to release object references and avoid memory leaks

Modified:
    click/trunk/click/mock/src/org/apache/click/MockContext.java

Modified: click/trunk/click/mock/src/org/apache/click/MockContext.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/src/org/apache/click/MockContext.java?rev=958255&r1=958254&r2=958255&view=diff
==============================================================================
--- click/trunk/click/mock/src/org/apache/click/MockContext.java (original)
+++ click/trunk/click/mock/src/org/apache/click/MockContext.java Sat Jun 26 17:48:55 2010
@@ -75,8 +75,13 @@ import org.apache.click.util.ClickUtils;
  *
  *     // Check that nameField value is now bound to request value
  *     Assert.assertEquals(requestValue, nameField.getValueObject());
- * }
- * </pre>
+ * } </pre>
+ *
+ * <b>Please note:</b> using MockContext to run performance tests over a large
+ * number of Controls could lead to <tt>out of memory</tt> errors. If you run
+ * into memory issues, you can either re-recreate a MockContext or invoke
+ * {@link #reset()}, which removes all references to Controls,
+ * ActionListeners and Behaviors.
  */
 public class MockContext extends Context {
 
@@ -301,20 +306,58 @@ public class MockContext extends Context
     }
 
     /**
-     * Execute all listeners that was registered by the processed Controls.
+     * Execute all listeners that was registered by processed Controls.
      *
      * @return true if all listeners returned true, false otherwise
      */
     public boolean executeActionListeners() {
-        ActionEventDispatcher controlRegistry = ActionEventDispatcher.getThreadLocalDispatcher();
+        ActionEventDispatcher dispatcher = ActionEventDispatcher.getThreadLocalDispatcher();
 
         // Fire action events
-        return controlRegistry.fireActionEvents(this);
+        return dispatcher.fireActionEvents(this);
+    }
+
+    /**
+     * Execute all behaviors that was registered by processed Controls.
+     *
+     * @return true if all behaviors returned true, false otherwise
+     */
+    public boolean executeBehaviors() {
+        ActionEventDispatcher dispatcher = ActionEventDispatcher.getThreadLocalDispatcher();
+
+        // Fire behaviors
+        return dispatcher.fireBehaviors(this);
+    }
+
+    /**
+     * Execute the preResponse callback event for all registered callbacks.
+     */
+    public void executePreResponseCallbackEvent() {
+        CallbackDispatcher dispatcher = CallbackDispatcher.getThreadLocalDispatcher();
+
+        dispatcher.processPreResponse(this);
+    }
+
+    /**
+     * Execute the preGetHeadElements callback event for all registered callbacks.
+     */
+    public void executePreGetHeadElementsCallbackEvent() {
+        CallbackDispatcher dispatcher = CallbackDispatcher.getThreadLocalDispatcher();
+
+        dispatcher.processPreGetHeadElements(this);
     }
 
     /**
-     * Fire all action events that was registered by the processed Controls, and
-     * clears all registered listeners from the ControlRegistry.
+     * Execute the preDestroy callback event for all registered callbacks.
+     */
+    public void executePreDestroyCallbackEvent() {
+        CallbackDispatcher dispatcher = CallbackDispatcher.getThreadLocalDispatcher();
+
+        dispatcher.processPreDestroy(this);
+    }
+
+    /**
+     * Fire all action events that was registered by the processed Controls.
      *
      * @deprecated use {@link #executeActionListeners()} instead
      *
@@ -323,4 +366,17 @@ public class MockContext extends Context
     public boolean fireActionEventsAndClearRegistry() {
         return executeActionListeners();
     }
+
+    /**
+     * Reset mock internal state. Running a large number of tests using the same
+     * MockContext could lead to <tt>out of memory</tt> errors. Calling this
+     * method will remove any references to objects, thus freeing up memory.
+     */
+    public void reset() {
+        CallbackDispatcher callbackDispatcher = CallbackDispatcher.getThreadLocalDispatcher();
+        callbackDispatcher.clear();
+
+        ActionEventDispatcher actionEventDispatcher = ActionEventDispatcher.getThreadLocalDispatcher();
+        actionEventDispatcher.clear();
+    }
 }



Mime
View raw message