Using WS-Messenger (WSMG) for LEAD project

(wsnt.demo.leadCallBack and wsnt.demo.myLeadAgent packages)

1, Run and test the package:

All the following command runs at WSMG home directory.

1. Compile WS-Notification package:
Type "ant"

2, run demo TestController:
source setenv.sh
java wsnt.demo.leadCallBack.TestController
-broker rainier.extreme.indiana.edu:12346 -topic "dn=SCdemo/Hurricane Ivan/CompletelyNewExperiment" -listenPort 19998
You can see that the notification consumer is start, subscription is created, and "Doing other stuff" is displayed. Then the test publisher publish some test messages. When all the messages receives, the controller shuts down the service and deletes the subscription. Then exit the program.

The termination condition is determined by the boolean return value of deliverEvent(String eventString) method in EventCallBack interfave. (Please see section 2 for detail.) In this demo (and our SC demo), I set the termination condition to be a "Thredd done." and a "FINISHED_" substring in the message. (see section 3). You can use different termination condition by change your implementation of Eventcallbak interface.

3, run demo TestMyLeadAgent:

source setenv.sh
java -Dlog=:ALL wsnt.demo.myLeadAgent.TestMyLeadAgent

This is running using default port 19999. You can change port in the code.

This will start listening for notifications and display received notifications when you run the testController.

Note: The subscription is not created by myLeadAgent. Controller should create subscription for myLeadAgent. (You need to modify the code of controller, see section 3)

2, Modifying LeadEventCallback class:


See LeadEventCallBack.java (in wsnt.demo.leadCallBack package) for a sample implemetation of the interface EventCallBack.java. It has only one method needs to be implemented:

public boolean deliverEvent(String eventString);

Parameter: The eventString is the message string extracted from the WS-Eventing SOAP message.
Return value: If you want the NotificationConsumer to shut down after your return, return TRUE. Otherwise, return false.

This is a generic interface for any notification message string. You need to parse the received string to XML and handle it. Section 5 shows how to parse the NCSA events for LEAD project.

3, Explaination of TestController.java: (in wsnt.demo.leadCallBack package)


See comments below in the code:

public static void main(String[] args) {

StopableNotificationConsumer nc = new StopableNotificationConsumer();
LeadEventCallBack myEventCallback = new LeadEventCallBack();
nc.setEventCallback(myEventCallback);
// String brokerUrl="rainier.extreme.indiana.edu:12346";
//e.g. Set brokerURL=localhost:12346
//Set Topic=AAA
//listening to port 19999, non-blocking

nc.startNotificationConsumer(brokerUrl,topic,listenPort);

//Create subscription for MyLeadAgent
String subId=nc.subscribe("bitternut.cs.indiana.edu:19999",topic);

/**addExpectedMessage()is a method in myEventCallback Implementation,
* This method is not required in EventCallback Interface.
* We used this method in SC demo to detect the end of workflow by checking
* the substring "FINISHED_" in the notification message
*/

//Add expected messages
myEventCallback.addExpectedMessage("Thredd done.");
myEventCallback.addExpectedMessage("FINISHED_");

//launch other components here
System.out.println("#####Doing other stuff######");

/****Following part is used to publish test messages. If you want to test your publisher,
* you can comment out the following part and let the controller to wait for your messages.
*/

//Call test publisher to publish a simple String messages
TestWSE_Publisher publisher = null;
publisher.main(new String[] {"-consumer", brokerUrl, "-topic", topic,"-message", "Thredd done."});
//Use this line to publish messages used in SC2004 demo. which are based on xmlbean.
// TestXmlbeanPublisher xmlPublisher=new TestXmlbeanPublisher();
//Use following line to publish a message using NCSATools (OGRE) events (see section 4 for more information)
TestNCSAEventPublisher xmlPublisher = new TestNCSAEventPublisher();
xmlPublisher.main(new String[] {"-consumer", brokerUrl, "-topic", topic});
/**End of test publisher
*/


//Wait for all messages after launching all the components, blocks here
nc.waitAllMessages();
//Unscubscribe MyLeadAgent, sleep for some time to wait for the messages to arrive at myLeadAgent before unsubscribing
Thread.currentThread().sleep(100L);
nc.unSubscribe(subId);
//shut down other components after all "Done" messages arrive

}

4, Creating and publishing NCSAEvent in WS-Eventing messages.

TestNCSAEventPublisher.java (in wsnt.demo.myLeadAgent package) demonstrates how to create NCSA events and publish them in WS-Eventing messages.

I created a LeadEvent class to handle NCSAEvents. You need to add ncsatools-*.jar files and dom4j-full.jar and castor-0.9.4.3.jar to your classpath. All of them are in the lib and lib/compile directory of OGRE package.

To create LEAD event:

import wsnt.demo.lead.LeadEvent;

LeadEvent leadEvent=new LeadEvent();
String messageString=leadEvent.createMessage(status,message,source, topic);

All the parameters in createMessage() method are String.

5, Parsing and getting contents of Lead NCSAEvents for myLeadAgent.

MyLeadAgentNotificationHandler.java (in wsnt.demo.myLeadAgent package) demostrates how to handle NCSA events.

Following is a sample NCSAEvent:

<NCSAEvent dirty="true" id-at-sink="-1" priority="0" creation-timestamp="1107293746490">
<properties xsi:type="java:ncsa.common.types.Attribute" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>Status</name>
<value xsi:type="java:java.lang.String">FINISHED_SUCCESS</value>
</properties>
<properties xsi:type="java:ncsa.common.types.Attribute" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>source</name>
<value xsi:type="java:java.lang.String">decoder</value>
</properties>
<properties xsi:type="java:ncsa.common.types.Attribute" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>Topic</name>
<value xsi:type="java:java.lang.String">dn=SCdemo/Hurricane Ivan/CompletelyNewExperiment</value>
</properties>
<properties xsi:type="java:ncsa.common.types.Attribute" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>TimeStamp</name>
<value xsi:type="java:java.lang.String">Tue Feb 01 16:35:46 EST 2005</value>
</properties>
<id-at-origin>ogre_event_20050201163546_YiLaptop__3281509676439281874</id-at-origin>
<message>done!&lt;a href="http://test.com/">text&lt;/a></message>
</NCSAEvent>

You can pass the NCSA message string in the constructor of LeadEvent class, then use different get method to get the content of the message. See below:

import wsnt.demo.lead.LeadEvent;

LeadEvent leadEvent=new LeadEvent(eventString);
String status=leadEvent.getStatus();
String message=leadEvent.getMessage();
String source=leadEvent.getSource();
String timeStamp=leadEvent.getTimeStamp();
String topic=leadEvent.getTopic();

 

Contact: yihuan@cs.indiana.edu

updated: 2/1/2005