Adding and connecting user-defined nodes

Use the IBM Integration API to add user-defined nodes and to connect user-defined nodes to other nodes.

The code required to add and connect user-defined node is different to the code required for built-in nodes and subflow nodes.

When you write Java™ code for user-defined nodes you must be aware of the following information:
  • User-defined nodes are supported by instances of the GenericNode class. To add user-defined nodes to message flows, create instances of GenericNode and add them to the message flow instance.
  • To retrieve existing instances of a user-defined node, call getNodeByName() and cast the returned object to a GenericNode object.
  • The terminals defined on your user-defined nodes are not automatically available in the API. If you create an instance of a GenericNode class, it does not have any input or output terminals listed. The methods getInputTerminals() and getOutputTerminals() return empty lists.
  • To get an input terminal for a GenericNode, call getInputTerminal() and pass the terminal name that exists on the generic node. This method returns the input terminal and makes it available in the message flow object that contains your generic node. After you have used getInputTerminal() with a known terminal name, this input terminal is returned if getInputTerminals() is used.
  • To get an output terminal for a GenericNode, call getOutputTerminal() and pass the terminal name that exists on the generic node. This method returns the output terminal and makes it available in the message flow object that contains your generic node. After you have used getOutputTerminal() with a known terminal name, this output terminal is returned if getOutputTerminals() is used.

The following example shows how you can add a user-defined node to a message flow and connect it to a built-in node:

  1. An MQInput node is created and added to the message flow.
  2. A user-defined node is created by using the GenericNode class and is added to the message flow object.
  3. The static output terminal of the MQInput is assigned to the variable outputTerminal.
  4. The input terminal of the user-defined node is assigned to the variable inputTerminal by using the getInputTerminal() method with the known terminal name In.
  5. The nodes are connected by using the connect() method.
  6. The final section of code shows that the input node is now available for use in the message flow, by using the getInputTerminals() method of the user-defined node instance.
File msgFlow = new File("main.msgflow");
MessageFlow mf1 = FlowRendererMSGFLOW.read(msgFlow);

MQInputNode mqinNode = new MQInputNode();
mqinNode.setNodeName("My Input Node");
mqinNode.setQueueName("IN");
mf1.addNode(mqinNode);

GenericNode myNode = new GenericNode("MyUserDefinedNode");
myNode.setNodeName("MyNode");
mf1.addNode(myNode);

OutputTerminal outputTerminal = mqinNode.OUTPUT_TERMINAL_OUT;
InputTerminal inputTerminal = myNode.getInputTerminal("In");
mf1.connect(outputTerminal, inputTerminal);

InputTerminal[] inputTerminals = myNode.getInputTerminals();
System.out.println("Input terminals on my node:");
for (int i = 0; i < inputTerminals.length; i++) {
   InputTerminal inputTerminal = inputTerminals[i];
   System.out.println(inputTerminal.getName());
} 

Pattern authoring

The following example is the same as the previous example, but for pattern authoring:
MessageFlow mf1 = patternInstanceManager.getMessageFlow("MyFlowProject", "main.msgflow");

MQInputNode mqinNode = new MQInputNode();
mqinNode.setNodeName("My Input Node");
mqinNode.setQueueName("IN");
mf1.addNode(mqinNode);

GenericNode myNode = new GenericNode("MyUserDefinedNode");
myNode.setNodeName("MyNode");
mf1.addNode(myNode);

OutputTerminal outputTerminal = mqinNode.OUTPUT_TERMINAL_OUT;
InputTerminal inputTerminal = myNode.getInputTerminal("In");
mf1.connect(outputTerminal, inputTerminal);

InputTerminal[] inputTerminals = myNode.getInputTerminals();
System.out.println("Input terminals on my node:");
for (int i = 0; i < inputTerminals.length; i++) {
   InputTerminal inputTerminal = inputTerminals[i];
   System.out.println(inputTerminal.getName());
}