You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2004/04/09 21:52:54 UTC

cvs commit: cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom FOM_Cocoon.java FOM_WebContinuation.java

vgritsenko    2004/04/09 12:52:54

  Modified:    src/java/org/apache/cocoon/components/flow
                        ContinuationsManagerImpl.java WebContinuation.java
               src/java/org/apache/cocoon/components/flow/javascript/fom
                        FOM_Cocoon.java FOM_WebContinuation.java
  Log:
  Fix broken continuations trees when parent continuation was disposed
  (better fix is welcome).
  Add disposed() test to continuation.
  Encapsulate ContinuationDisposer.
  
  Revision  Changes    Path
  1.10      +13 -18    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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ContinuationsManagerImpl.java	5 Mar 2004 13:02:46 -0000	1.9
  +++ ContinuationsManagerImpl.java	9 Apr 2004 19:52:54 -0000	1.10
  @@ -1,12 +1,12 @@
   /*
    * Copyright 1999-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -113,7 +113,7 @@
   
       public WebContinuation createWebContinuation(Object kont,
                                                    WebContinuation parent,
  -                                                 int timeToLive, 
  +                                                 int timeToLive,
                                                    ContinuationsDisposer disposer) {
           int ttl = (timeToLive == 0 ? defaultTimeToLive : timeToLive);
   
  @@ -170,21 +170,16 @@
               _invalidate((WebContinuation) children.get(i));
           }
       }
  -    
  +
       /**
        * Makes the continuation inaccessible for lookup, and triggers possible needed
        * cleanup code through the ContinuationsDisposer interface.
  -     * 
  +     *
        * @param wk the continuation to dispose.
        */
       private void disposeContinuation(WebContinuation wk) {
           idToWebCont.remove(wk.getId());
  -           
  -        // Call specific possible implementation-specific clean-up on this continuation.
  -        ContinuationsDisposer disposer = wk.getDisposer();
  -        if (disposer != null) {
  -          disposer.disposeContinuation(wk);
  -        }
  +        wk.dispose();
       }
   
       public WebContinuation lookupWebContinuation(String id) {
  @@ -208,10 +203,10 @@
        * cleanup of the continuation.
        * @return the generated <code>WebContinuation</code> with unique identifier
        */
  -    private WebContinuation generateContinuation( Object kont, 
  -                                                  WebContinuation parent,
  -                                                  int ttl, 
  -                                                  ContinuationsDisposer disposer) {
  +    private WebContinuation generateContinuation(Object kont,
  +                                                 WebContinuation parent,
  +                                                 int ttl,
  +                                                 ContinuationsDisposer disposer) {
   
           char[] result = new char[bytes.length * 2];
           WebContinuation wk = null;
  @@ -328,7 +323,7 @@
           Iterator iter = expirations.iterator();
           while (iter.hasNext() && ((wk = (WebContinuation) iter.next()).hasExpired())) {
               iter.remove();
  -            this.removeContinuation(wk);
  +            removeContinuation(wk);
           }
   
           // log state after continuations clean up
  
  
  
  1.8       +23 -4     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WebContinuation.java	5 Mar 2004 13:02:46 -0000	1.7
  +++ WebContinuation.java	9 Apr 2004 19:52:54 -0000	1.8
  @@ -1,12 +1,12 @@
   /*
    * Copyright 1999-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -344,5 +344,24 @@
           long expireTime = this.getLastAccessTime() + this.timeToLive;
   
           return (currentTime > expireTime);
  +    }
  +
  +    /**
  +     * Dispose this continuation. Should be called on invalidation.
  +     */
  +    public void dispose() {
  +        // Call specific possible implementation-specific clean-up on this continuation.
  +        if (this.disposer != null) {
  +            this.disposer.disposeContinuation(this);
  +        }
  +        // Remove continuation object - will also serve as "disposed" flag
  +        this.continuation = null;
  +    }
  +
  +    /**
  +     * Return true if this continuation was disposed of
  +     */
  +    public boolean disposed() {
  +        return this.continuation == null;
       }
   }
  
  
  
  1.32      +23 -5     cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
  
  Index: FOM_Cocoon.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- FOM_Cocoon.java	5 Mar 2004 13:02:46 -0000	1.31
  +++ FOM_Cocoon.java	9 Apr 2004 19:52:54 -0000	1.32
  @@ -1,12 +1,12 @@
   /*
    * Copyright 1999-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -246,6 +246,7 @@
   
   
       public FOM_WebContinuation jsGet_continuation() {
  +        // FIXME: This method can return invalid continuation! Is it OK to do so?
           return currentCall.getLastContinuation();
       }
   
  @@ -1511,6 +1512,23 @@
       }
   
       /**
  +     * Return this continuation if it is valid, or first valid parent
  +     */
  +    private FOM_WebContinuation findValidParent(FOM_WebContinuation wk) {
  +        if (wk != null) {
  +            WebContinuation wc = wk.getWebContinuation();
  +            while (wc != null && wc.disposed()) {
  +                wc = wc.getParentContinuation();
  +            }
  +            if (wc != null) {
  +                return new FOM_WebContinuation(wc);
  +            }
  +        }
  +
  +        return null;
  +    }
  +
  +    /**
        * Create a Bookmark WebContinuation from a JS Continuation with the last
        * continuation of sendPageAndWait as its parent.
        * PageLocal variables will be shared with the continuation of
  @@ -1524,7 +1542,7 @@
           double d = org.mozilla.javascript.Context.toNumber(ttl);
           FOM_WebContinuation result =
               makeWebContinuation((Continuation)unwrap(k),
  -                                jsGet_continuation(),
  +                                findValidParent(jsGet_continuation()),
                                   (int)d);
           result.setPageLocal(pageLocal.getDelegate());
           currentCall.setLastContinuation(result);
  
  
  
  1.9       +19 -14    cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java
  
  Index: FOM_WebContinuation.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FOM_WebContinuation.java	5 Mar 2004 13:02:46 -0000	1.8
  +++ FOM_WebContinuation.java	9 Apr 2004 19:52:54 -0000	1.9
  @@ -1,12 +1,12 @@
   /*
    * Copyright 1999-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -112,7 +112,10 @@
   
       public FOM_WebContinuation jsFunction_getParent() {
           WebContinuation parent = wk.getParentContinuation();
  -        if (parent == null) return null;
  +        if (parent == null) {
  +            return null;
  +        }
  +
           FOM_WebContinuation pwk = new FOM_WebContinuation(parent);
           pwk.setParentScope(getParentScope());
           pwk.setPrototype(getClassPrototype(getParentScope(),
  @@ -141,10 +144,8 @@
       public void jsFunction_invalidate() throws Exception {
           ContinuationsManager contMgr = null;
           FOM_Cocoon cocoon =
  -            (FOM_Cocoon)getProperty(getTopLevelScope(this),
  -                                    "cocoon");
  -        ServiceManager componentManager =
  -            cocoon.getServiceManager();
  +            (FOM_Cocoon)getProperty(getTopLevelScope(this), "cocoon");
  +        ServiceManager componentManager = cocoon.getServiceManager();
           contMgr = (ContinuationsManager)
               componentManager.lookup(ContinuationsManager.ROLE);
           contMgr.invalidateWebContinuation(wk);
  @@ -201,7 +202,10 @@
   
       public FOM_WebContinuation jsGet_previousBookmark() {
           WebContinuation c = wk.getParentContinuation();
  -        if (c == null) return null;
  +        if (c == null) {
  +            return null;
  +        }
  +
           // If this is a continuation of sendPageAndWait()
           // and the immediate parent is a bookmark, then
           // it is the bookmark for this page, so skip it.
  @@ -211,12 +215,13 @@
           while (c != null && !isBookmark(c)) {
               c = c.getParentContinuation();
           }
  -        if (c == null) return null;
  +        if (c == null) {
  +            return null;
  +        }
  +
           FOM_WebContinuation pwk = new FOM_WebContinuation(c);
           pwk.setParentScope(getParentScope());
  -        pwk.setPrototype(getClassPrototype(getParentScope(),
  -                                           pwk.getClassName()));
  +        pwk.setPrototype(getClassPrototype(getParentScope(), pwk.getClassName()));
           return pwk;
  -
       }
   }