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

Application Lifecycle Management

Search In Project

Search inClear

Tags:  not added yet

Three Components

Three components in chain with @In/@Out pass through.

Concept

Similar to the Connect Two Components example, data passes via @In/@Out from component 1 to component 2 to component 3. The component in the middle uses an @In/@Out annotated field used for passing the data through the same object. Connecting components in this manner is fundamental to building models with OMS.

Implementation

'Comp1' consumes a string value, adds characters, and outputs the augmented string.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
package ex04;

import oms3.annotations.*;

public class Comp1 {

    @Role(Role.PARAMETER)
    @In public String in;

    @Out public String out;

    @Execute
    public void execute() {
        out = in + " -> Comp1 ";
    }
}

'Comp2' consumes 'c1.out', adds characters, then outputs the augmented string. With this component 'var' is used for both the @In and @Out variable.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
package ex04;

import oms3.annotations.*;

public class Comp2 {

    @In @Out public String var;

    @Execute
    public void execute() {
        var = var + "-> Comp2";
    }
}

'Comp3' consumes 'c2.var', adds characters, and prints the augmented string.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
package ex04;

import oms3.annotations.*;

public class Comp3 {

    @In public String in;

    @Execute
    public void execute() {
        in = in + " -> Comp3";
        System.out.println(in);
    }
}

In the simulation, the model contains the three components connected in the order shown. 'c1.in' is instantiated, and the simulation prints out the augmented string.

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

OMS3.sim {
    model {
       parameter {
          // pass in the coordinated as native integer to the
          // first component.
          'c1.in'  "simulation start"
       }

       components {
          'c1' 'ex04.Comp1'
          'c2' 'ex04.Comp2'
          'c3' 'ex04.Comp3'
       }

       connect {
          'c1.out' 'c2.var'
          'c2.var' 'c3.in'
       }
    }
}