Dashboard > RIFE > ... > Web engine > Parallel and simultaneous continuations
RIFE Log In | Sign Up   View a printable version of the current page.
Parallel and simultaneous continuations


Added by Geert Bevin, last edited by Geert Bevin on Jul 31, 2006  (view change)
Labels: 
(None)

Continuations can run in embedded elements and any number of them can be active at the same time.

Below is the implementation of a page with multiple counters that all run independently as continuations with while loops.

The Counter.java element:

@Elem(url="", submissions = {
    @Submission(name = "decrease"),
    @Submission(name = "increase")})
public class Counter extends Element {
    public void processElement() {
        int counter = 0;
        Template t = getHtmlTemplate("counter");
        while (true) {
            t.setValue("counter", counter);
            print(t);
            pause();
            if (hasSubmission("decrease")) counter--;
            if (hasSubmission("increase")) counter++;
        }
    }
}

The counter.html template that is used by the element above:

<div>
    <r:v name="counter"/>
     
    <form action="${v SUBMISSION:FORM:decrease/}" method="post">
        <r:v name="SUBMISSION:PARAMS:decrease"/>
        <input type="submit" value=" - " />
    </form>
     
    <form action="${v SUBMISSION:FORM:increase/}" method="post">
        <r:v name="SUBMISSION:PARAMS:increase"/>
        <input type="submit" value=" + " />
    </form>
</div>

The main template that includes three counters as embedded elements:

<body>
    <r:v name="ELEMENT:Counter:1"/>
    <br />
    <r:v name="ELEMENT:Counter:2"/>
    <br />
    <r:v name="ELEMENT:Counter:3"/>
</body>

It would help a lot in the examples if they were compilable. Why not add the necessary import statements?

On the other side it is great to have such examples. That is what I appreciate a lot.

Posted by Klaus Meffert at Feb 11, 2007 15:40 | Permalink


Are you enjoying Confluence? Please consider purchasing it today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.1a Build:#515 May 19, 2006) - Bug/feature request - Contact Administrators