Code Generation

This page explains the use of the Java code generation framework for Reo. For details of the implementation please see the draft technical report attached at the bottom of the page.

The code generator is invoked from the Reo editor as shown below:

The wizard presents several options all of which may be left at their default values.

Writing Components

The coordinator code generated expects components to implement the cwi.ea.runtime.ReoComponent interface:

public interface ReoComponent extends Runnable {
        public ReoComponent withSourcePorts(Source...  sources);
        public ReoComponent withSinkPorts(Sink...  sinks);
}

Note the varargs parameter of these methods is an array of Sink our Source ports and the return value is simply this. The main() method that is generated instantiates components and calls these methods to set ports as in the following example:

public static void main(String[] args) throws Exception {
        TimeoutPort a,b,c,d,e;
//...
        ReoComponent xxx0 = new XXX().withSinkPorts(a,b,c).withSourcePorts(d,e);
}

For examples see the standard reader and writer components in cwi.ea.runtime. components:

public class Reader implements ReoComponent {
        private Sink out;
        public void run() {
                Thread.currentThread().setName(name);
                int i=0;
                try {
                        for (i=0; i<count; i++) {
                                System.out.println(name + " got " + out.take());
                                
                                if (Thread.interrupted())
                                        break;
                        } 
                } catch (InterruptedException e) { }
                finally {
                        System.out.println("*** "+ name + " read total of "+ i + " items ***");
                }
        }

        public ReoComponent  withSinkPorts(Sink... sinks) {
                out = sinks[0];
                return this;
        }

        public ReoComponent withSourcePorts(Source... sources) {
                return this;
        }
}
/**
Component which sums the inputs read from ports "in1" and "in2" 
and writes the result on port "out"
**/
public class Sum implements ReoComponent {
        private Sink in1, in2;
        private Source out;

        public void run() {
                int sum = 0;
                //We stop when there's an overflow
                while (sum >=0) {
                    sum = in1.take() + in2.take();
                    out.write(sum);
                }
        }

        public ReoComponent  withSinkPorts(Sink... sinks) {
                in1 = sinks[0]; in2 = sinks[1];
                return this;
        }

        public ReoComponent withSourcePorts(Source... sources) {
                out = sources[0];
                return this;
        }
}

Todo/ Bugs

  • Create code stubs for components and Filter predicates
  • Tickets: #4