Building DataFlow Applications in Java : Composing an Application : Creating and Adding Operators
 
Share this page                  
Creating and Adding Operators
Operators are Java classes that are created by constructing a new instance of the operator class. All operators provide a no-argument constructor and you can use this constructor directly. Many operators also provide convenience constructors that accept properties as parameters. Optionally, these constructors can be used to set the properties for the operator instead of setting them later. To determine the available constructors, see the JavaDoc for each operator.
After an operator instance is constructed, it must be added to the LogicalGraph using the add() method. Adding an operator to a graph links the operator with the composition context of the graph.
This lets the ports of the added operator to be linked to other operators and also allows the operator to participate in the application execution at run time.
The following is an example of constructing a new operator and adding it into a LogicalGraph.
GenerateRandom generator = graph.add(new GenerateRandom(), "generator");
Note:  You must add the operators to the LogicalGraph after constructing them. The operators that are not linked with a LogicalGraph are not executed and they can create run time exceptions when they are linked to operators in a Logi calGraph. You can use the add() method of the LogicalGraph to return the correct type. This lets you combine the construction of an operator and add it to the graph in the same line of code.