You are not logged in. Click here to log in.

Application Lifecycle Management

Search In Project

Search inClear

Tags:  not added yet

Output Destination

Specifying the destination for model output

Concept

Model output prints to a file in a specified directory, the path provided as an input parameter to the model.

Implementation

The 'IterationControl' component consumes the 'count' and 'output' path and file name, and while 'done' is false, prints the count to the file and prints the count to system output. When 'done' is true, a summary message is printed to standard output.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package ex20;

import java.io.PrintWriter;
import java.io.IOException;
import java.io.File;
import oms3.annotations.*;
import static oms3.annotations.Role.*;

public class IterationControl {

    @Role(PARAMETER)
    @In public int count;

    @Role(PARAMETER + OUTPUT)
    @In public File output;

    // flag for controlling the iteration
    @Out public boolean done;

    // current iteration variable
    int i;
    PrintWriter w;

    @Execute
    public void execute() throws IOException {
        if (i==0) {
            output.getParentFile().mkdirs();
            w = new PrintWriter(output);
            i = count;
        }
        w.println(i);
        done = i-- > 1;
        System.out.println("Count " + i);
    }


    @Finalize
    public void done() throws IOException {
        if (w != null)
            w.close();
        System.out.println("Wrote output to " + output);
    }
}

The model simulation file specifies one component in the model (lines 14-16), sets iteration (line 5), parameter 'count' is set to 5 (line 9), and parameter 'output' is set to the path shown (line 11).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import static oms3.SimBuilder.instance as OMS3

OMS3.sim {
    // the iteration is controlled by the 'c' component's 'done' field.
    model(iter:"c.done") {

       parameter {
          // repeat the iteration 5 times
          'c.count'  5
          // output file, using the variable $oms_prj
          'c.output' "$oms_prj/output/ex16/Out.txt"
       }

       components {
          // c is the counter control component.
          'c' 'ex20.IterationControl'
       }
    }
}