ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Creating user defined node in java....

Post new topic  Reply to topic
 Creating user defined node in java.... « View previous topic :: View next topic » 
Author Message
vedantpatil
PostPosted: Tue Jun 21, 2005 4:22 am    Post subject: Creating user defined node in java.... Reply with quote

Novice

Joined: 10 Mar 2005
Posts: 19

I am creating user defined node in java. I got this sample code some another post.
I compiled the code and craeted jar file

javac com/ibm/jsample/SwitchNode.java
jar -cvf SwitchNode.jar com/ibm/jsample
I copied SwitchNode.jar file in install_root\jplugin directory.and put this jar in classpath.
I restarted the broker and open the toolkit but i am not able to see the node in toolkit.
Is this process is sufficient to see the user defined node in toolkit or i am missing something...


The code for SwitchNode.java is
--------------------------------------------------------------------------------

/*
* Sample program for use with Product 5648-C63
* (C) COPYRIGHT International Business Machines Corp., 1999, 2001
* All Rights Reserved * Licensed Materials - Property of IBM
*
* This sample program is provided AS IS and may be used, executed,
* copied and modified without royalty payment by customer
*
* (a) for its own instruction and study,
* (b) in order to develop applications designed to run with an IBM
* WebSphere product, either for customer's own internal use or for
* redistribution by customer, as part of such an application, in
* customer's own products.
*/


package com.ibm.jsamples;

import com.ibm.broker.plugin.*;
import java.io.*;

/**
* Sample plugin node.
* This node propagates the incoming message to one of several output terminals
* depending on the content of the message.
* A minimal test message for this node would be:
* <data><action>change</action></data>
*/
public class SwitchNode extends MbNode implements MbNodeInterface
{
String _nodeTraceSetting = "";
String _nodeTraceOutfile = "";
PrintWriter traceWriter = null;

/**
* Switch node constructor.
* This is where input and output terminal are created.
*/
public SwitchNode() throws MbException
{
createInputTerminal("in");
createOutputTerminal("add");
createOutputTerminal("change");
createOutputTerminal("delete");
createOutputTerminal("hold");
createOutputTerminal("failure");
}

/**
* This static method is called by the framework to identify this node.
* If this method is not supplied, a default name will be generated
* automatically based on the node's package/class name. In this case
* it would be 'ComIbmSamplesSwitchNode'.
*/
public static String getNodeName()
{
return "SwitchNode";
}

/**
* This evaluate message is called by the broker for each message passing
* through the flow. The message assembly is passed in with the 'assembly'
* parameter. It is possible for a node to have more than one input
* terminal. The terminal that the message has come in on is represented
* by the 'in' parameter.
*/
public void evaluate(MbMessageAssembly assembly, MbInputTerminal in)
throws MbException
{
// Navigate to the relevant syntax element in the XML message
MbElement rootElement = assembly.getMessage().getRootElement();
MbElement switchElement =
rootElement.getLastChild().getFirstChild().getFirstChild();

// To aid debugging, text can be printed to stdout/stderr.
// On NT this can be viewed by selecting 'Allow sevice to interact with
// desktop' on the NT Services properties dialog.
// On Unix set the environment variable MQSI_RUN_ATTACHED=1 before
// starting the broker.
if (_nodeTraceSetting.equals("debug"))
{
System.out.println("Element = " + switchElement.getName());
System.out.println("Value = " + switchElement.getValue());
if(traceWriter != null) {
traceWriter.println("Element = " + switchElement.getName());
traceWriter.println("Value = " + switchElement.getValue());
}
}

// Select the terminal indicated by the value of this element
String terminalName;
String elementValue = (String) switchElement.getValue();
if (elementValue.equals("add"))
terminalName = "add";
else if (elementValue.equals("change"))
terminalName = "change";
else if (elementValue.equals("delete"))
terminalName = "delete";
else if (elementValue.equals("hold"))
terminalName = "hold";
else
terminalName = "failure";

MbOutputTerminal out = getOutputTerminal(terminalName);

// Now propagate the message assembly.
// If the terminal is not attached, an exception will be thrown. The user
// can choose to handle this exception, but it is not neccessary since
// the framework will catch it and propagate the message to the failure
// terminal, or if it not attached, rethrow the exception back upstream.
if(_nodeTraceSetting.equals("debug") && traceWriter != null) {
traceWriter.println("Propagating to terminal: " + terminalName);
traceWriter.flush();
}

out.propagate(assembly);
}

/* Attributes are defined for a node by supplying get/set methods.
* The following two methods define an attribute 'nodeTraceSetting'.
* The capitalisation follows the usual JavaBean property convention.
*/
public String getNodeTraceSetting()
{
return _nodeTraceSetting;
}

public void setNodeTraceSetting(String nodeTraceSetting)
{
_nodeTraceSetting = nodeTraceSetting;
if(traceWriter != null) {
traceWriter.println("Attribute nodeTraceSetting set to: " + _nodeTraceSetting);
}
}

public String getNodeTraceOutfile()
{
return _nodeTraceOutfile;
}

public void setNodeTraceOutfile(String nodeTraceOutfile)
{
_nodeTraceOutfile = nodeTraceOutfile;
if(traceWriter != null) {
traceWriter.close();
traceWriter =null;
}
try {
traceWriter = new PrintWriter(new FileWriter(nodeTraceOutfile));
if(_nodeTraceSetting.equals("debug") && traceWriter != null) {
traceWriter.println("Attribute nodeTraceOutfile set to: " + nodeTraceOutfile);
traceWriter.flush();
}
}
catch(IOException e) {
System.out.println("Trace file could not be set: " + e);
}
}

/* The following method is used to close the trace output file handle.
*/
public void onDelete()
{
if( traceWriter != null) {
traceWriter.close();
traceWriter = null;
}
}


}

----------------------------------------------------
Thanks in advance.
VP
Code:
Back to top
View user's profile Send private message
JT
PostPosted: Tue Jun 21, 2005 5:41 am    Post subject: Reply with quote

Padawan

Joined: 27 Mar 2003
Posts: 1564
Location: Hartford, CT.

Quote:
I copied SwitchNode.jar file in install_root\jplugin directory.and put this jar in classpath.

Migrating the jar file to the jplugin directory has nothing to do with viewing the node within the Toolkit. It's the broker that loads the jar files from that directory.

If you haven't already done so, you need to review this section on User-defined plug-ins in the Help facility: http://publib.boulder.ibm.com/infocenter/wbihelp/topic/com.ibm.etools.mft.doc/as04510_.htm

Quote:
The node project is an Eclipse plug-in. It sits in the workbench while it is being developed. Each user of the workbench needs to have the node project in their install_dir\eclipse\plugins directory to be able to add the node to their message flows.
Back to top
View user's profile Send private message
vedantpatil
PostPosted: Tue Jun 21, 2005 8:09 am    Post subject: Reply with quote

Novice

Joined: 10 Mar 2005
Posts: 19

Thanks JT for the quick response.
I am able to see and node and its working fine..
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Creating user defined node in java....
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.