Creating an input node in Java

Before you start

Ensure that you have read and understood the following topics:

WebSphere Message Broker provides the source for two sample user-defined nodes called SwitchNode and TransformNode. You can use these nodes in their current state, or you can modify them.

A Java user-defined node is distributed as a .jar file. This topic describes the steps you need to take to create an input node using Java. It outlines the following steps:
  1. Creating a new Java project
  2. Declaring the input node class
  3. Defining the node constructor
  4. Declaring the node name
  5. Declaring attributes
  6. Implementing the node functionality
  7. Deleting an instance of the node

Do not develop Java nodes on z/OS that you intend to deploy to a broker on a distributed platform. This is because the level of Java on z/OS might not produce code that is compatible with the level of Java on the distributed platform.

Creating a new Java project

You can create Java nodes from within the workbench, using the provided plug-in development environment (PDE). To do this, you must create a new Java project, as follows:
  1. Switch to the Plug-in Development perspective.
  2. Click File > New > Project. Select Java from the left menu, and then select Java Project from the right menu
  3. Give the project a name.

    The Java Settings panel is displayed.

  4. Select the Libraries tab, and click Add External JARs.
  5. Select install_dir\classes\jplugin2.jar.
  6. Follow the prompts on the other tabs to define any other build settings.
  7. Click Finish.
You can then develop the source for your Java node within this project.

Declaring the input node class

Any class that implements the MbInputNodeInterface, and is contained in the broker's classpath (or LIL path) is registered with the broker as an input node. When you implement the MbInputNodeInterface, you also need to implement a run method for this class. The run method represents the start of the message flow, contains the data that formulates the message, and propagates it down the flow. The broker calls the run method when threads become available in accordance with your specified threading model.

For example, to declare the input node class:

package com.ibm.jplugins;

import com.ibm.broker.plugin.*;

public class BasicInputNode extends MbInputNode implements MbInputNodeInterface
{
...
You can do this in the workbench as follows:
  1. Click File > New > Class.
  2. Set the package and class name fields to appropriate values.
  3. Delete the text in the Superclass text field and click the Browse button
  4. Select MbInputNode.
  5. Click the Add button next to Interfaces text field, and select MbInputNodeInterface.
  6. Click Finish.

Defining the node constructor

When the node is instantiated, the constructor of the user's node class is called. This is where you create the terminals of the node, and initialize any default values for the attributes.

An input node has a number of output terminals associated with it, but does not typically have any input terminals. Use the createOutputTerminal method to add output terminals to a node when the node is instantiated. For example, to create a node with three output terminals:

public BasicInputNode() throws mbException
{
	createOutputTerminal ("out");
	createOutputTerminal ("failure");
	createOutputTerminal ("catch");
   setAttribute ("firstParserClassName","myParser");
   attributeVariable  = new String ("none");
}

Declaring the node name

You need to declare the name of the node as it will be identified by the workbench. All node names must end with "Node". You declare the name using the following method:

public static String getNodeName()
{
   return "BasicInputNode";
}
If this method is not declared, the Java API framework creates a default node name using the following rules:
  • The class name is appended to the package name.
  • The dots are removed, and the first letter of each part of the package and class name are capitalized.
For example, by default, the following class is assigned the node name "ComIbmPluginsamplesBasicInputNode":
package com.ibm.pluginsamples;
public class BasicInputNode extends MbInputNode implements MbInputNodeInterface
{
   ...

Declaring attributes

You declare node attributes in the same way as Java Bean properties. You are responsible for writing getter and setter methods for the attributes, and the API framework infers the attribute names using the Java Bean introspection rules. For example, if you declare the following two methods:

private String attributeVariable;

public String getFirstAttribute()
{
  return attributeVariable;
}

publc void setFirstAttribute(String value)
{
  attributeVariable = value;
}

The broker infers that this node has an attribute called firstAttribute. This name is derived from the names of the get or set methods, not from any internal class member variable names. Attributes can only be exposed as strings, so you must convert any numeric types to and from strings in the get or set methods. For example, the following method defines an attribute called timeInSeconds:

int seconds;

public String getTimeInSeconds()
{
  return Integer.toString(seconds);
}

public void setTimeInSeconds(String value)
{
  seconds = Integer.parseInt(value);
}

Implementing the node functionality

As already described, the run method is called by the broker to create the input message. This method should provide all the processing function for the input node.

Overriding default message parser attributes (optional)

An input node implementation normally determines what message parser initially parses an input message. For example, the primitive MQInput node dictates that an MQMD parser is required to parse the MQMD header. A user-defined input node can select an appropriate header or message parser, and the mode in which the parsing is controlled, by using the following attributes that are included as default, which you can override:

rootParserClassName
Defines the name of the root parser that parses message formats supported by the user-defined input node. It defaults to GenericRoot, a supplied root parser that causes the broker to allocate and chain parsers together. It is unlikely that a node would need to modify this attribute value.
firstParserClassName
Defines the name of the first parser, in what might be a chain of parsers that are responsible for parsing the bitstream. It defaults to XML.
messageDomainProperty
An optional attribute that defines the name of the message parser required to parse the input message. The supported values are the same as those supported by the MQInput node. (See MQInput node for more information about the MQInput node.)
messageSetProperty
An optional attribute that defines the message set identifier, or the message set name, in the Message Set field, only if the MRM parser was specified by the messageDomainProperty attribute.
messageTypeProperty
An optional attribute that defines the identifier of the message in the MessageType field, only if the MRM parser was specified by the messageDomainProperty attribute.
messageFormatProperty
An optional attribute that defines the format of the message in the Message Format field, only if the MRM parser was specified by the messageDomainProperty attribute.

Deleting an instance of the node

An instance of the node is deleted when either:
  • You shutdown the broker.
  • You remove the node or the message flow containing the node, and redeploy the configuration.
During node deletion, the node might want to be informed so that it can perform any cleanup operations, such as closing sockets. If the node implements the optional onDelete method, this is called by the broker just before the node is deleted.

You implement the onDelete method as follows:

public void onDelete()
{
  // perform node cleanup if necessary
}
Related information
Java API