You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Brent Johnson <bl...@gmail.com> on 2004/10/28 22:50:31 UTC

Endless Looping in Flow

I've got a page where the user can modify something (the title of an
XML document in this case).  Here's what I'm doing in the flowscript:

function showLayoutListPage() {
    var page = cocoon.parameters.page;

    if (isLoggedIn()) {

        while (true) {
            cocoon.sendPageAndWait("content/" + page + ".html", {
"page" : page, "user" : cocoon.session.getAttribute("user"), "layouts"
: getLayoutList() });

            var action = cocoon.request.get("doit");
            var filename = cocoon.request.get("filename");

            if (action == "setTitle") {
                // set the title for the layout
                var layout = getLayoutByFilename(filename);
                layout.setTitle(cocoon.request.get("title"));
                layout.save();
            }
        }

    } else {
        cocoon.redirectTo("/public/index.html");
    }
}

So there's an infinite loop there.  Is that going to be a problem? 
See there's really no "end" to this flow.  As long as they're sitting
on the layout manager page they're wanting to "do" something.  The
only end to this continuation would be when they clicked on some other
page rather than clicking "Set Title" or something similar.

Anyone have any thoughts on this?  Will this continually eat up
resources as time goes on or anything?

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Endless Looping in Flow

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 29/ott/04, alle 00:03, Brent Johnson ha scritto:

> I'm just somewhat concerned about it because it looks like the
> flowscript is cached while in continuation.  So if I'm in a
> continuation and I change my code.. the change doesnt take affect
> until I enter the continuation again.. which makes me think that its
> cached in memory somewhere and over time it may end up sucking up
> resources.

Yes, having a continuation available will suck up resources. For one 
thing, all local variables will still be reachable as long as the 
continuation is valid, so they won't be garbage-collected.

To alleviate this problem, I suggest that you invalidate continuations 
like this:

    var k = cocoon.sendPageAndWait(...);
    k.invalidate();

Keep also in mind that continuations expire after a timeout that can be 
configured in cocoon.xconf. So eventually all memory should be 
reclaimed.

	Ugo

-- 
Ugo Cei - http://beblogging.com/

Re: Endless Looping in Flow

Posted by Brent Johnson <bl...@gmail.com>.
Yeah thats what I was thinking (the !done thing that is).  But the
problem is.. I cant really force them to signal when they're done. 
You know end users... they're just going to close their browser when
done, or click up at the top of the page on another link and leave the
process.

I think I'll add a "Cancel" or "Done" button that'll stop the flow in
the hopes that some people may actually use it.  It doesnt sound like
its a big deal though.

I'm just somewhat concerned about it because it looks like the
flowscript is cached while in continuation.  So if I'm in a
continuation and I change my code.. the change doesnt take affect
until I enter the continuation again.. which makes me think that its
cached in memory somewhere and over time it may end up sucking up
resources.

Thanks for the help.

On Thu, 28 Oct 2004 16:26:23 -0500, Tony Collen <co...@umn.edu> wrote:
> Brent Johnson wrote:
> 
> 
> 
> > I've got a page where the user can modify something (the title of an
> > XML document in this case).  Here's what I'm doing in the flowscript:
> > So there's an infinite loop there.  Is that going to be a problem?
> > See there's really no "end" to this flow.  As long as they're sitting
> > on the layout manager page they're wanting to "do" something.  The
> > only end to this continuation would be when they clicked on some other
> > page rather than clicking "Set Title" or something similar.
> >
> > Anyone have any thoughts on this?  Will this continually eat up
> > resources as time goes on or anything?
> 
> Well, it won't keep running because the execution is halted on
> sendPageAndWait().  My only guess is if there's a memory leak in Rhino,
> but it seems fine.  If you're really paranoid you could add a "quit"
> function that breaks out of the loop, but it should be fine.  From what
> I've seen, a lot of Flowscript makes use of while(true) to keep doing
> something over and over.   It might be better to do while (!done)  and
> set done=true when the person signals they're done with whatever process.
> 
> Tony
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Endless Looping in Flow

Posted by Tony Collen <co...@umn.edu>.
Brent Johnson wrote:

> I've got a page where the user can modify something (the title of an
> XML document in this case).  Here's what I'm doing in the flowscript:
> So there's an infinite loop there.  Is that going to be a problem? 
> See there's really no "end" to this flow.  As long as they're sitting
> on the layout manager page they're wanting to "do" something.  The
> only end to this continuation would be when they clicked on some other
> page rather than clicking "Set Title" or something similar.
> 
> Anyone have any thoughts on this?  Will this continually eat up
> resources as time goes on or anything?

Well, it won't keep running because the execution is halted on 
sendPageAndWait().  My only guess is if there's a memory leak in Rhino, 
but it seems fine.  If you're really paranoid you could add a "quit" 
function that breaks out of the loop, but it should be fine.  From what 
I've seen, a lot of Flowscript makes use of while(true) to keep doing 
something over and over.   It might be better to do while (!done)  and 
set done=true when the person signals they're done with whatever process.

Tony

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Endless Looping in Flow

Posted by Antonio Gallardo <ag...@agssa.net>.
Hi Brent!

Another option is to not use a loop. See between lines:

Brent Johnson dijo:
> I've got a page where the user can modify something (the title of an
> XML document in this case).  Here's what I'm doing in the flowscript:
>
> function showLayoutListPage() {
>     var page = cocoon.parameters.page;
>
>     if (isLoggedIn()) {
>
         while (true) { // remove this line
>             cocoon.sendPageAndWait("content/" + page + ".html", {
> "page" : page, "user" : cocoon.session.getAttribute("user"), "layouts"
> : getLayoutList() });
>
>             var action = cocoon.request.get("doit");
>             var filename = cocoon.request.get("filename");
>
>             if (action == "setTitle") {
>                 // set the title for the layout
>                 var layout = getLayoutByFilename(filename);
>                 layout.setTitle(cocoon.request.get("title"));
>                 layout.save();
>             }
         }   // remove this line
          // Add a sendPage to the initial link
          cocoon.sendPage("my_initial_link");
>
>     } else {
>         cocoon.redirectTo("/public/index.html");
>     }
> }

That way you can avoid the loop. Also you can invalidate the continuation
once it is over.

Best Regards,

Antonio Gallardo


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org