cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r642694 - in /cocoon/branches/BRANCH_2_1_X: ./ src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/
Date Sun, 30 Mar 2008 07:30:54 GMT
Author: joerg
Date: Sun Mar 30 00:30:41 2008
New Revision: 642694

URL: http://svn.apache.org/viewvc?rev=642694&view=rev
Log:
Minimize the data that's stored with ContinuationContext to limit the Continuation's memory
footprint.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/Continuation.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/ContinuationContext.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java?rev=642694&r1=642693&r2=642694&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java
Sun Mar 30 00:30:41 2008
@@ -38,9 +38,11 @@
 public abstract class AbstractContinuable implements Continuable {
 
     private ContinuationContext getContext() {
-        if (Continuation.currentContinuation()==null)
+        Continuation currentContinuation = Continuation.currentContinuation();
+        if (currentContinuation == null) {
             throw new IllegalStateException("No continuation is running");
-        return (ContinuationContext) Continuation.currentContinuation().getContext();
+        }
+        return (ContinuationContext) currentContinuation.getContext();
     }
   
     public Logger getLogger() {
@@ -55,14 +57,14 @@
 
         ContinuationContext context = getContext();
 
-				if (context.getLogger()!=null)
+        if (context.getLogger()!=null)
             context.getLogger().debug("send page and wait '" + uri + "'");
 
         FlowHelper.setContextObject(ContextHelper.getObjectModel(context.getAvalonContext()),
bizdata);
 
         if (SourceUtil.indexOfSchemeColon(uri) == -1) {
             uri = "cocoon:/" + uri;
-            if (getContext().getRedirector().hasRedirected()) {
+            if (context.getRedirector().hasRedirected()) {
                 throw new IllegalStateException("Pipeline has already been processed for
this request");
             }
             try {
@@ -74,6 +76,7 @@
             throw new IllegalArgumentException("uri is not allowed to contain a scheme (cocoon:/
is always automatically used)");
         }
 
+        context.onSuspend();
         Continuation.suspend();
     }
 
@@ -85,14 +88,14 @@
 
         ContinuationContext context = getContext();
 
-				if (context.getLogger()!=null)
+        if (context.getLogger()!=null)
             context.getLogger().debug("send page '" + uri + "'");
 
         FlowHelper.setContextObject(ContextHelper.getObjectModel(context.getAvalonContext()),
bizdata);
 
         if (SourceUtil.indexOfSchemeColon(uri) == -1) {
             uri = "cocoon:/" + uri;
-            if (getContext().getRedirector().hasRedirected()) {
+            if (context.getRedirector().hasRedirected()) {
                 throw new IllegalStateException("Pipeline has already been processed for
this request");
             }
             try {

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/Continuation.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/Continuation.java?rev=642694&r1=642693&r2=642694&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/Continuation.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/Continuation.java
Sun Mar 30 00:30:41 2008
@@ -16,10 +16,12 @@
  */
 package org.apache.cocoon.components.flow.java;
 
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.Map;
 
 /**
- * Continations object to store the current execution. The contiunation
+ * Continuation object to store the current execution. The continuation
  * object can only used once. 
  *
  * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
@@ -27,10 +29,11 @@
  * @version CVS $Id$
  */
 public class Continuation {
-    private ContinuationStack stack;
-    private Object context;
+    
+    private static final Map continuations = Collections.synchronizedMap(new HashMap());
 
-    private static HashMap continuationsmap = new HashMap();
+    private final ContinuationStack stack;
+    private Object context;
 
     public boolean restoring = false;
     public boolean capturing = false;
@@ -73,7 +76,6 @@
      * Stop the running continuation.
      */
     public static void suspend() {
-
         Continuation continuation = Continuation.currentContinuation();
 
         if (continuation == null)
@@ -96,7 +98,7 @@
     }
 
     /**
-     * True, is the continuation freeze the strack trace, and stops the continuation.
+     * True, if the continuation freezes the stack trace, and stops the continuation.
      */
     public boolean isCapturing() {
         return capturing;
@@ -106,18 +108,14 @@
      * Bind the continuation to running thread.
      */
     public void registerThread() {
-        synchronized (continuationsmap) {
-            continuationsmap.put(Thread.currentThread(), this);
-        }
+        continuations.put(Thread.currentThread(), this);
     }
 
     /**
      * Unbind the continuation to running thread.
      */
     public void deregisterThread() {
-        synchronized (continuationsmap) {
-            continuationsmap.remove(Thread.currentThread());
-        }
+        continuations.remove(Thread.currentThread());
     }
 
     /**
@@ -125,9 +123,7 @@
      * current thread.
      */
     public static Continuation currentContinuation() {
-        synchronized (continuationsmap) {
-            Thread t = Thread.currentThread();
-            return (Continuation) continuationsmap.get(t);
-        }
+        Thread t = Thread.currentThread();
+        return (Continuation) continuations.get(t);
     }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/ContinuationContext.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/ContinuationContext.java?rev=642694&r1=642693&r2=642694&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/ContinuationContext.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/ContinuationContext.java
Sun Mar 30 00:30:41 2008
@@ -46,6 +46,19 @@
     public ContinuationContext() {
     }
 
+    /**
+     * The Continuation has been suspended, now clean up the context.
+     * Only {@link #object} and {@link #method} should be carried over.
+     * See {@link JavaInterpreter#handleContinuation(String, java.util.List, Redirector)}
+     */
+    public void onSuspend() {
+        this.logger = null;
+        this.avalonContext = null;
+        this.manager = null;
+        this.redirector = null;
+        this.parameters = null;
+    }
+    
     public void setObject(Object object) {
         this.object = object;
     }
@@ -94,11 +107,12 @@
         return redirector;
     }
     
-	public Parameters getParameters() {
-		return parameters;
-	}
+    public Parameters getParameters() {
+        return parameters;
+    }
 	
-	public void setParameters(Parameters parameters) {
-		this.parameters = parameters;
-	}
+    public void setParameters(Parameters parameters) {
+        this.parameters = parameters;
+    }
+
 }

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?rev=642694&r1=642693&r2=642694&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Sun Mar 30 00:30:41 2008
@@ -182,6 +182,9 @@
 
   <changes>
   <release version="2.1.12" date="TBD">
+    <action dev="JH" type="fix">
+      Javaflow: Minimize the data that's stored with ContinuationContext to limit the Continuation's
memory footprint.
+    </action>
     <action dev="AG" type="fix" fixes-bug="COCOON-2163" due-to="Carlos Chávez" due-to-email="cchavez@agssa.net">
       Forms: Widget Label is not Show/Hide when we change the widget state in ajax mode.
     </action>



Mime
View raw message