Before you start
The Java Settings panel is displayed.
Any class that implements MbInputNodeInterface and is contained in the broker's LIL path is registered with the broker as an input node. When you implement 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 { ...
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 = "none"; }
An input node can receive data from any type of external source, such as a file system, a queue or a database, in the same way as any other Java program, as long as the output from the node is in the correct format.
You provide an input buffer (or bit stream) to contain input data, and associate it with a message object. You create a message from a byte array using the createMessage method of the MbInputNode class, and then generate a valid message assembly from this message. For details of these methods, see theJava API. For example, to read the input from a file:
When you have created a message assembly, you can then propagate it to one of the node's terminals.
MbOutputTerminal out = getOutputTerminal("out"); out.propagate(newAssembly);
msg.clearMessage();
To clear the memory that is allocated for the message tree, call the clearMessage() function within the final try/catch block.
The broker infrastructure handles transaction issues such as controlling the commit of any WebSphere MQ or database unit of work when message processing has completed. However, resources modified from within a user-defined node will not necessarily be under the transactional control of the broker.
Each message flow thread is allocated from a pool of threads maintained for each message flow, and starts execution in the run method.
The user-defined node uses return values to indicate whether a transaction has been successful, to control whether transactions are committed or rolled-back, and to control when the thread is returned to the pool. Any unhandled exceptions are caught by the broker infrastructure, and the transaction is rolled back.
You determine the behavior of transactions and threads using an appropriate return value from the following:
public int run( MbMessageAssembly assembly ) throws MbException { byte[] data = getDataWithTimeout(); // user supplied method // returns null if timeout if( data == null ) return TIMEOUT; MbMessage msg = createMessage( data ); msg.finalizeMessage( MbMessage.FINALIZE_VALIDATE ); MbMessageAssembly newAssembly = new MbMessageAssembly( assembly, msg ); dispatchThread(); getOutputTerminal( "out" ).propagate( newAssembly ); return SUCCESS_RETURN; }
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"; }
package com.ibm.pluginsamples; public class BasicInputNode extends MbInputNode implements MbInputNodeInterface { ...
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); }
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.
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:
You implement the onDelete method as follows:
public void onDelete() { // perform node cleanup if necessary }
Notices |
Trademarks |
Downloads |
Library |
Support |
Feedback
![]() ![]() |
as09950_ |