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

Application Lifecycle Management

Search In Project

Search inClear

Tags:  not added yet

Initialize, Execute, and Finalize (IEF)

The basic OMS model component life cycle consisting of initialize, execute, and finalize methods.

Concept

The OMS annotations '@Initiaize', '@Execute', and '@Finalize' are used to organize and implement methods within a component.

The method tagged with the '@Initialize' annotation initializes the internal state of an OMS component. For example opening a file for reading, or a creating a data base connection would be something that would be done within '@Initialize'. These methods are not necessarily required in an OMS component.

The method that is tagged with the '@Execute' annotation provides the implementation logic of the component. In this method the component input is being transformed to output. The execution method can have any name, but it has to be non-static, public, void return type, no arguments. '@Execute' is required meta data for an OMS component.

The method tagged with the '@Finalize' annotation provides the notion of a final cleanup after model execution (e.g. closing a database connection). When an '@Finalize' method is present in an OMS component, usually a corresponding '@Initialize' method also is present. '@Finalize' methods are not necessarily required in an OMS component.

Implementation

The 'TimeControl' component from the Time Iteration example consumes four parameters: start and end time, type of calendar to use, and the time step to increment. The component outputs a current time 'current'.

 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
package ex15;

import java.util.Calendar;
import oms3.annotations.*;

/**
 * Time control
 * 
 * @author od
 */
public class TimeControl {

    @In public Calendar start;
    @In public Calendar end;
    @In public int calfield;
    @In public int amount;

    @Out public Calendar current;

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

    @Execute
    public void execute() {
        if (current == null) {
            current = (Calendar) start.clone();
        } else {
            current.add(calfield, amount);
        }
        done = current.before(end);
    }
}

'TimeConsumerComponent' also has been borrowed from the Time Iteration example containing the '@Execute' method, but then augmented to contain '@Initialize' and '@Finalize' methods. The '@Initialize' method prints a string at the beginning, and the '@Finalize' method a string at the end just to demonstrate the progression through the three types of methods.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package ex15;

import java.util.Calendar;
import oms3.annotations.*;

public class TimeConsumerComponent {

    @In public Calendar current;

    @Initialize
    public void init() {
        System.out.println("Consumer init");
    }

    @Execute
    public void execute() {
        System.out.println("Consumer " + current.getTime());
    }

    @Finalize
    public void done() {
        System.out.println("Consumer Done");
    }
}

The simulation file is the same as in the Time Iteration example, the '@Execute' method iterating between the specified start and end.

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

OMS3.sim {
    model(while:"c.done") {
       parameter {
          'c.start'       '2001-10-01'
          'c.end'         '2001-10-10'
          'c.calfield'    java.util.Calendar.DAY_OF_YEAR
          'c.amount'      1
       }

       components {
          'c'  'ex15.TimeControl'
          'c1' 'ex15.TimeConsumerComponent'
       }

       connect {
         'c.current'  'c1.current'
       }
    }
}