Return-Path:
It has the side effect of interning the continuation object in
* the WebContinuation
could be found.
*/
public WebContinuation lookupWebContinuation(String id);
+
+ /**
+ * Prints debug information about all web continuations into the log file.
+ * @see WebContinuation#display()
+ */
+ public void displayAllContinuations();
}
1.5 +31 -29 cocoon-2.1/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
Index: ContinuationsManagerImpl.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ContinuationsManagerImpl.java 20 Mar 2003 01:04:22 -0000 1.4
+++ ContinuationsManagerImpl.java 20 Mar 2003 02:46:32 -0000 1.5
@@ -114,6 +114,7 @@
*/
protected SortedSet expirations = Collections.synchronizedSortedSet(new TreeSet());
+
public ContinuationsManagerImpl() throws Exception {
random = SecureRandom.getInstance("SHA1PRNG");
random.setSeed(System.currentTimeMillis());
@@ -135,20 +136,20 @@
}
public WebContinuation createWebContinuation(Object kont,
- WebContinuation parentKont,
+ WebContinuation parent,
int timeToLive) {
int ttl = (timeToLive == 0 ? defaultTimeToLive : timeToLive);
- WebContinuation wk = new WebContinuation(kont, parentKont, this, ttl);
+ WebContinuation wk = generateContinuation(kont, parent, ttl);
wk.enableLogging(getLogger());
- if (parentKont == null) {
+ if (parent == null) {
forrest.add(wk);
}
// REVISIT: This Places only the "leaf" nodes in the expirations Sorted Set.
// do we really want to do this?
- if (parentKont != null) {
+ if (parent != null) {
if (wk.getParentContinuation().getChildren().size() < 2) {
expirations.remove(wk.getParentContinuation());
}
@@ -168,9 +169,9 @@
public void invalidateWebContinuation(WebContinuation wk) {
WebContinuation parent = wk.getParentContinuation();
- if (parent == null)
+ if (parent == null) {
forrest.remove(wk);
- else {
+ } else {
List parentKids = parent.getChildren();
parentKids.remove(wk);
}
@@ -178,7 +179,7 @@
_invalidate(wk);
}
- protected void _invalidate(WebContinuation wk) {
+ private void _invalidate(WebContinuation wk) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("WK: Manual Expire of Continuation " + wk.getId());
}
@@ -188,8 +189,9 @@
// Invalidate all the children continuations as well
List children = wk.getChildren();
int size = children.size();
- for (int i = 0; i < size; i++)
+ for (int i = 0; i < size; i++) {
_invalidate((WebContinuation) children.get(i));
+ }
}
public WebContinuation lookupWebContinuation(String id) {
@@ -199,22 +201,21 @@
}
/**
- * Generate a unique identifier for a
- * WebContinuation
. The identifier is generated using a
- * cryptographically strong algorithm to prevent people to generate
- * their own identifiers.
+ * Create WebContinuation
and generate unique identifier
+ * for it. The identifier is generated using a cryptographically strong
+ * algorithm to prevent people to generate their own identifiers.
*
* idToWebCont
hash table.
*
- * @param wk a WebContinuation
object for which the
- * identifier should be generated.
- * @return the String
identifier of the
- * WebContinuation
+ * @param kont an Object
value representing continuation
+ * @param parent value representing parent WebContinuation
+ * @param ttl WebContinuation
time to live
+ * @return the generated WebContinuation
with unique identifier
*/
- public String generateContinuationId(WebContinuation wk) {
+ private WebContinuation generateContinuation(Object kont, WebContinuation parent, int ttl) {
char[] result = new char[bytes.length * 2];
- String continuationId = null;
+ WebContinuation wk = null;
while (true) {
random.nextBytes(bytes);
@@ -224,19 +225,20 @@
result[2 * i] = Character.forDigit(Math.abs(ch >> 4), 16);
result[2 * i + 1] = Character.forDigit(Math.abs(ch & 0x0f), 16);
}
- continuationId = new String(result);
+
+ String id = new String(result);
synchronized (idToWebCont) {
- if (!idToWebCont.containsKey(continuationId)) {
- idToWebCont.put(continuationId, wk);
+ if (!idToWebCont.containsKey(id)) {
+ wk = new WebContinuation(id, kont, parent, ttl);
+ idToWebCont.put(id, wk);
break;
}
}
}
- return continuationId;
+ return wk;
}
-
/**
* Removes an expired leaf WebContinuation
node
* from its continuation tree, and recursively removes its
@@ -244,7 +246,7 @@
*
* @param wk WebContinuation
node
*/
- public void removeContinuation(WebContinuation wk) {
+ private void removeContinuation(WebContinuation wk) {
if (wk.getChildren().size() != 0) {
return;
}
@@ -270,12 +272,11 @@
}
}
-
/**
* Dump to Log file the current contents of
* the expirations SortedSet
*/
- public void displayExpireSet() {
+ private void displayExpireSet() {
Iterator iter = expirations.iterator();
StringBuffer wkSet = new StringBuffer("\nWK; Expire Set Size: " + expirations.size());
while (iter.hasNext()) {
@@ -311,7 +312,7 @@
* Remove all continuations which have
* already expired
*/
- public void expireContinuations() {
+ private void expireContinuations() {
// log state before continuations clean up
if (getLogger().isDebugEnabled()) {
getLogger().debug("WK: Forrest size: " + forrest.size());
@@ -346,7 +347,8 @@
m_commandSink = (Sink) context.get(Queue.ROLE);
}
- public final class ContinuationInterrupt implements RepeatedCommand {
+
+ final class ContinuationInterrupt implements RepeatedCommand {
private final long m_interval;
private final long m_initialDelay;
1.4 +11 -10 cocoon-2.1/src/java/org/apache/cocoon/components/flow/WebContinuation.java
Index: WebContinuation.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/WebContinuation.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebContinuation.java 20 Mar 2003 01:04:23 -0000 1.3
+++ WebContinuation.java 20 Mar 2003 02:46:32 -0000 1.4
@@ -46,7 +46,6 @@
package org.apache.cocoon.components.flow;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
@@ -69,6 +68,7 @@
*/
public class WebContinuation extends AbstractLogEnabled
implements Comparable {
+
/**
* The continuation this object represents.
*/
@@ -128,20 +128,21 @@
*
* @param continuation an Object
value
* @param parentContinuation a WebContinuation
value
- * @param manager a ContinuationsManagerImpl
value
+ * @param timeToLive time this continuation should live
*/
- public WebContinuation(Object continuation,
- WebContinuation parentContinuation,
- ContinuationsManagerImpl manager,
- int timeToLive) {
+ WebContinuation(String id,
+ Object continuation,
+ WebContinuation parentContinuation,
+ int timeToLive) {
+ this.id = id;
this.continuation = continuation;
this.parentContinuation = parentContinuation;
- id = manager.generateContinuationId(this);
this.updateLastAccessTime();
this.timeToLive = timeToLive;
- if (parentContinuation != null)
+ if (parentContinuation != null) {
this.parentContinuation.children.add(this);
+ }
}
/**
@@ -336,7 +337,7 @@
* Update the continuation in the
*/
protected void updateLastAccessTime() {
- lastAccessTime = new Date().getTime();
+ lastAccessTime = System.currentTimeMillis();
}
/**
1.2 +2 -1 cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/Database.js
Index: Database.js
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/Database.js,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Database.js 17 Mar 2003 00:32:35 -0000 1.1
+++ Database.js 20 Mar 2003 02:46:32 -0000 1.2
@@ -1,4 +1,6 @@
//
+// CVS $Id$
+//
// Prototype Database API
//
// TBD: Move this Database stuff to its own library outside of flow
@@ -16,5 +18,4 @@
cocoon.componentManager.release(selector);
}
}
-
1.7 +12 -17 cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JSCocoon.java
Index: JSCocoon.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JSCocoon.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JSCocoon.java 17 Mar 2003 00:38:39 -0000 1.6
+++ JSCocoon.java 20 Mar 2003 02:46:32 -0000 1.7
@@ -70,7 +70,6 @@
import org.apache.cocoon.components.modules.output.OutputModule;
import org.apache.cocoon.components.modules.input.InputModule;
import org.apache.cocoon.components.CocoonComponentManager;
-import org.apache.cocoon.components.flow.ContinuationsManagerImpl;
import org.apache.cocoon.components.flow.ContinuationsManager;
import org.apache.cocoon.components.flow.WebContinuation;
import org.apache.cocoon.acting.Action;
@@ -221,8 +220,9 @@
WebContinuation kont = null;
- if (cont != null)
+ if (cont != null) {
kont = ((JSWebContinuation)cont).getWebContinuation();
+ }
interpreter.forwardTo(uri, bizData, kont, environment);
} catch (JavaScriptException e) {
@@ -283,10 +283,8 @@
= (ContinuationsManager)manager.lookup(ContinuationsManager.ROLE);
try {
- if (continuationsMgr instanceof ContinuationsManagerImpl)
- ((ContinuationsManagerImpl)continuationsMgr).displayAllContinuations();
- }
- finally {
+ continuationsMgr.displayAllContinuations();
+ } finally {
manager.release((Component)continuationsMgr);
}
}
@@ -346,8 +344,7 @@
this.environment.getObjectModel(),
source,
jsobjectToParameters(parameters));
- }
- finally {
+ } finally {
actionSelector.release(action);
}
@@ -363,10 +360,11 @@
for (int i = 0; i < ids.length; i++) {
String key = ScriptRuntime.toString(ids[i]);
Object value = jsobject.get(key, jsobject);
- if (value == Undefined.instance)
+ if (value == Undefined.instance) {
value = null;
- else
+ } else {
value = ScriptRuntime.toString(value);
+ }
params.setParameter(key, (String) value);
}
return params;
@@ -385,8 +383,7 @@
try {
result = input.getAttribute(attribute, null,
this.environment.getObjectModel());
- }
- finally {
+ } finally {
inputSelector.release(input);
}
return result;
@@ -422,8 +419,7 @@
OutputModule output = (OutputModule) outputSelector.select(type);
try {
output.commit(null, this.environment.getObjectModel());
- }
- finally {
+ } finally {
outputSelector.release(output);
}
}
@@ -439,8 +435,7 @@
OutputModule output = (OutputModule) outputSelector.select(type);
try {
output.rollback(null, this.environment.getObjectModel(), null);
- }
- finally {
+ } finally {
outputSelector.release(output);
}
}
1.7 +21 -18 cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java
Index: JavaScriptInterpreter.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JavaScriptInterpreter.java 17 Mar 2003 04:29:48 -0000 1.6
+++ JavaScriptInterpreter.java 20 Mar 2003 02:46:32 -0000 1.7
@@ -49,10 +49,8 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.util.Collections;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -72,9 +70,20 @@
import org.apache.commons.jxpath.JXPathIntrospector;
import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
import org.apache.excalibur.source.Source;
-import org.mozilla.javascript.*;
+
import org.mozilla.javascript.tools.debugger.ScopeProvider;
import org.mozilla.javascript.tools.ToolErrorReporter;
+import org.mozilla.javascript.Script;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.PropertyException;
+import org.mozilla.javascript.EvaluatorException;
+import org.mozilla.javascript.JavaScriptException;
+import org.mozilla.javascript.ScriptRuntime;
+import org.mozilla.javascript.NativeArray;
+import org.mozilla.javascript.Function;
+import org.mozilla.javascript.Wrapper;
/**
* Interface with the JavaScript interpreter.
@@ -233,11 +242,9 @@
// Define some functions on the top level scope
String[] names = { "print" };
try {
- ((ScriptableObject)scope)
- .defineFunctionProperties(names, JSGlobal.class,
- ScriptableObject.DONTENUM);
- }
- catch (PropertyException e) {
+ scope.defineFunctionProperties(names, JSGlobal.class,
+ ScriptableObject.DONTENUM);
+ } catch (PropertyException e) {
throw new Error(e.getMessage());
}
@@ -262,7 +269,6 @@
* can have a scope associated with it.
*
* @param environment an Environment
value
- * @param createSession a boolean
value
* @return a Scriptable
value
*/
public Scriptable getSessionScope(Environment environment)
@@ -333,11 +339,9 @@
* script cocoon.createSession()
. This will place the
* newly create Scriptable object in the user's session, where it
* will be retrieved from at the next invocation of
- * callFunction().
Environment
value
- * @param createNew a boolean
value
- * @param sourcesToBeCompiled list of Source's to compile
* @return a Scriptable
value
* @exception Exception if an error occurs
*/
@@ -492,6 +496,7 @@
Source src) throws Exception {
InputStream is = src.getInputStream();
Reader reader = new BufferedReader(new InputStreamReader(is));
+ // FIXME: scope or this.scope?
Script compiledScript = cx.compileReader(this.scope, reader,
src.getURI(),
1, null);
@@ -551,15 +556,13 @@
callFun = "callFunction"; // this will produce a better error message
}
ScriptRuntime.call(context, callFun, thrScope, callFunArgs, thrScope);
- }
- catch (JavaScriptException ex) {
- EvaluatorException ee =
+ } catch (JavaScriptException ex) {
+ EvaluatorException ee =
Context.reportRuntimeError(ToolErrorReporter.getMessage("msg.uncaughtJSException",
ex.getMessage()));
throw new CascadingRuntimeException(ee.getMessage(), unwrap(ex));
- }
- finally {
+ } finally {
exitContext(thrScope);
}
}
1.3 +2 -1 cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/system.js
Index: system.js
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/system.js,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- system.js 17 Mar 2003 00:32:35 -0000 1.2
+++ system.js 20 Mar 2003 02:46:32 -0000 1.3
@@ -1,4 +1,5 @@
-// system.js
+//
+// CVS $Id$
//
// JavaScript definitions
//
1.4 +2 -0 cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/xmlForm.js
Index: xmlForm.js
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/xmlForm.js,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- xmlForm.js 18 Mar 2003 18:24:10 -0000 1.3
+++ xmlForm.js 20 Mar 2003 02:46:32 -0000 1.4
@@ -1,4 +1,6 @@
//
+// CVS $Id$
+//
// XMLForm Support
//