You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jo...@apache.org on 2008/03/30 17:05:10 UTC
svn commit: r642756 - in
/cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon:
components/flow/java/ samples/flow/java/
Author: joerg
Date: Sun Mar 30 08:05:08 2008
New Revision: 642756
URL: http://svn.apache.org/viewvc?rev=642756&view=rev
Log:
slightly better approach to minimize continuation's memory footprint (without an additional hook, instead storing function name in the continuation)
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/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java
cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/samples/flow/java/CalculatorFlow.java
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=642756&r1=642755&r2=642756&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 08:05:08 2008
@@ -76,7 +76,6 @@
throw new IllegalArgumentException("uri is not allowed to contain a scheme (cocoon:/ is always automatically used)");
}
- context.onSuspend();
Continuation.suspend();
}
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=642756&r1=642755&r2=642756&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 08:05:08 2008
@@ -32,6 +32,7 @@
private static final Map continuations = Collections.synchronizedMap(new HashMap());
+ private final String functionName;
private final ContinuationStack stack;
private Object context;
@@ -41,21 +42,27 @@
/**
* Create new continuation.
*/
- public Continuation(Object context) {
- stack = new ContinuationStack();
+ public Continuation(final String functionName, final Object context) {
+ this.functionName = functionName;
+ this.stack = new ContinuationStack();
this.context = context;
}
/**
* Create a new continuation, which continue a previous continuation.
*/
- public Continuation(Continuation parent, Object context) {
+ public Continuation(final Continuation parent, final Object context) {
if (parent == null)
throw new NullPointerException("Parent continuation is null");
- stack = new ContinuationStack(parent.stack);
+ this.functionName = parent.functionName;
+ this.stack = new ContinuationStack(parent.stack);
this.context = context;
- restoring = true;
+ this.restoring = true;
+ }
+
+ public String getFunctionName() {
+ return functionName;
}
/**
@@ -73,7 +80,11 @@
}
/**
- * Stop the running continuation.
+ * Suspend the running continuation or restore the suspended continuation.
+ *
+ * With the help of byte code manipulation this method is run twice, once at
+ * the end of request 1 to suspend the continuation and a second time at the
+ * beginning of the request 2.
*/
public static void suspend() {
Continuation continuation = Continuation.currentContinuation();
@@ -82,8 +93,11 @@
throw new IllegalStateException("No continuation is running");
if (continuation.restoring) {
+ // restoring
continuation.capturing = false;
} else {
+ // suspending
+ continuation.context = null;
continuation.capturing = true;
}
continuation.restoring = false;
@@ -126,4 +140,5 @@
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=642756&r1=642755&r2=642756&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 08:05:08 2008
@@ -46,19 +46,6 @@
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;
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java?rev=642756&r1=642755&r2=642756&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java Sun Mar 30 08:05:08 2008
@@ -154,7 +154,7 @@
}
context.setParameters(parameters);
- Continuation continuation = new Continuation(context);
+ Continuation continuation = new Continuation(function, context);
WebContinuation wk = continuationsMgr.createWebContinuation(
continuation, null, timeToLive, getInterpreterID(), null);
@@ -174,24 +174,23 @@
} catch (InvocationTargetException ite) {
if (ite.getTargetException() != null) {
- if (ite.getTargetException() instanceof Exception)
+ if (ite.getTargetException() instanceof Exception)
throw (Exception) ite.getTargetException();
else if (ite.getTargetException() instanceof Error)
throw new ProcessingException("An internal error occured", ite.getTargetException());
- else if (ite.getTargetException() instanceof RuntimeException)
- throw (RuntimeException) ite.getTargetException();
else
throw ite;
} else {
throw ite;
}
} finally {
- // remove last object reference, which is not needed to
- // reconstruct the invocation path
+ // remove last object reference, which is not needed to reconstruct
+ // the invocation path
if (continuation.isCapturing())
continuation.getStack().popReference();
continuation.deregisterThread();
}
+
userScopes.put(method.getDeclaringClass(), flow);
session.setAttribute(USER_GLOBAL_SCOPE, userScopes);
}
@@ -212,10 +211,17 @@
}
Continuation parentContinuation = (Continuation) parentwk.getContinuation();
- ContinuationContext parentContext = (ContinuationContext) parentContinuation.getContext();
+ Method method = (Method) methods.get(parentContinuation.getFunctionName());
+
+ Request request = ContextHelper.getRequest(this.avalonContext);
+ Session session = request.getSession(true);
+ HashMap userScopes = (HashMap) session.getAttribute(USER_GLOBAL_SCOPE);
+
+ Continuable flow = (Continuable) userScopes.get(method.getDeclaringClass());
+
ContinuationContext context = new ContinuationContext();
- context.setObject(parentContext.getObject());
- context.setMethod(parentContext.getMethod());
+ context.setObject(flow);
+ context.setMethod(method);
context.setAvalonContext(avalonContext);
context.setLogger(getLogger());
context.setServiceManager(manager);
@@ -229,13 +235,6 @@
Continuation continuation = new Continuation(parentContinuation, context);
- Request request = ContextHelper.getRequest(this.avalonContext);
- Session session = request.getSession(true);
- HashMap userScopes = (HashMap) session.getAttribute(USER_GLOBAL_SCOPE);
-
- Continuable flow = (Continuable) context.getObject();
- Method method = context.getMethod();
-
WebContinuation wk = continuationsMgr.createWebContinuation(
continuation, parentwk, timeToLive, getInterpreterID(), null);
FlowHelper.setWebContinuation(ContextHelper.getObjectModel(this.avalonContext), wk);
@@ -251,8 +250,6 @@
throw (Exception) ite.getTargetException();
else if (ite.getTargetException() instanceof Error)
throw new ProcessingException("An internal error occured", ite.getTargetException());
- else if (ite.getTargetException() instanceof RuntimeException)
- throw (RuntimeException) ite.getTargetException();
else
throw ite;
} else {
@@ -262,7 +259,7 @@
// remove last object reference, which is not needed to reconstruct
// the invocation path
if (continuation.isCapturing())
- continuation.getStack().popReference();
+ continuation.getStack().popReference();
continuation.deregisterThread();
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/samples/flow/java/CalculatorFlow.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/samples/flow/java/CalculatorFlow.java?rev=642756&r1=642755&r2=642756&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/samples/flow/java/CalculatorFlow.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/samples/flow/java/CalculatorFlow.java Sun Mar 30 08:05:08 2008
@@ -52,7 +52,7 @@
float value = 0f;
try {
value = Float.parseFloat(getRequest().getParameter(name));
- } catch (Exception e) {
+ } catch (NumberFormatException e) {
sendMessage("Error: \""+getRequest().getParameter(name)+"\" is not a correct number!");
}
return value;