Flow Component Resources

Each flow component extends a base component that provides access to the following resources:

Properties

Property values can be retrieved by:

this.props["<name>"]

The <name> must be substituted with the corresponding property name. The returned values have the types of the declaration in descriptor.json. A string type is returned as a string, an integer as a number, an array as a JSON array. If a property is defined as optional (mandatory: false) and the value is not set and there is no default value, the returned value is undefined.

Assertions

Flow components usually require that specific properties of an incoming message must be defined. To check this and throw an error if not, this function can be called on the inbound message for every required property:

this.assertProperty(<msg>, "<name>");

<msg> is the message to check (usually the inbound message received by a connector) and <name> is the name of the property.

Output connectors are available from the base component by executing this function:

this.executeOutputLink("<name>", <object>);

<name> is the name of the output link, <object> the object that is passed to the output link. It must be of the type that is specified in descriptor.json.

Input References

Input references can be obtained by:

this.getInputReference("<name>");

<name> is the name of the input reference. Note that a reference is always a function. To get the actual result of this function, it must be executed. 

Example:

this.refProp = this.getInputReference("Property")();

Output References

A flow component that provides an output reference must provide this reference as a function so that it is possible to pass static or dynamic results. Example:

function handler(In) {
var self = this;
this.setOutputReference("Property", execRef);

function execRef() {
return self.property;
}
}

The actual reference is set by:

this.setOutputReference("<name>", <function>);

<name> is the name of the output reference and <function> is the pointer to a function that is executed when the reference is executed from another component.

Automatic Notifications

The base component does many things automatically behind the scenes so the flow component just needs to implement its functionality.

Automatic notifications are sent to the flow's log file and the app log (upper right corner of Flow Director) on:

  • Flow start
  • Flow stop 

Error Handling

Invocations of input connectors of a flow component are guarded invocations. That is, exceptions thrown by a flow component are caught and sent to the flow's error stream, log file and to the app log. 

If a flow component detects an error it just needs to throw an exception in the respective handlers.

Example (init handler of flow component Property):

function handler() {
this.properties = this.props["properties"];
this.types = this.props["types"];
this.values = this.props["values"];
this.BOOLEAN = Java.type("java.lang.Boolean");
this.INTEGER = Java.type("java.lang.Integer");
this.LONG = Java.type("java.lang.Long");
this.DOUBLE = Java.type("java.lang.Double");
this.FLOAT = Java.type("java.lang.Float");

if (this.properties.length !== this.types.length || this.properties.length !== this.values.length)
throw "Invalid number of entries for types or values";

for (var i=0;i<this.types.length;i++) {
var t = this.types[i];
if (!(t === 'boolean' || t === 'string' || t === 'integer' || t === 'long' || t === 'double' || t === 'float'))
throw "Invalid property type: " + t;
}
}