this.glob = glob;
try {
ConnectQos loginQos = new ConnectQos(null); // creates "<qos></qos>" string
I_XmlBlasterAccess blasterConnection = glob.getXmlBlasterAccess();
blasterConnection.connect(loginQos, this); // Now we are connected to xmlBlaster MOM server.
// Subscribe to messages with XPATH using some helper classes
log.info("Subscribing #1 for anonymous callback class using XPath syntax ...");
SubscribeKey key = new SubscribeKey(glob, "//DispatchTest", "XPATH");
SubscribeQos qos = new SubscribeQos(glob);
blasterConnection.subscribe(key, qos, new I_Callback() {
public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {
log.info("Receiving message with specialized update() #1 ...");
numReceived1++;
System.out.println(updateKey.toXml());
System.out.println((new String(content)).toString());
System.out.println(updateQos.toXml());
return "";
}
});
log.info("Subscribing #2 for anonymous callback class using XPath syntax ...");
key = new SubscribeKey(glob, "A message id");
blasterConnection.subscribe(key, qos, new I_Callback() {
public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {
log.info("Receiving message with specialized update() #2 ...");
numReceived2++;
System.out.println(updateKey.toXml());
System.out.println((new String(content)).toString());
System.out.println(updateQos.toXml());
return "";
}
});
// Construct a message and publish it ...
String publishOid1 = "";
// This time, as an example, we don't use the wrapper helper classes,
// and create the string 'by hand':
String xmlKey = "<key oid='' contentMime='text/xml'>\n" +
" <DispatchTest>" +
" </DispatchTest>" +
"</key>";
String content = "Some content #1";
MsgUnit msgUnit = new MsgUnit(xmlKey, content.getBytes(), "<qos></qos>");
publishOid1 = blasterConnection.publish(msgUnit).getKeyOid();
log.info("Publishing done, returned oid=" + publishOid1);
try { Thread.sleep(1000); } catch( InterruptedException i) {} // Wait a second
String publishOid2 = "";
xmlKey = "<key oid='A message id' contentMime='text/xml'>\n" +
"</key>";
content = "Some content #2";
msgUnit = new MsgUnit(xmlKey, content.getBytes(), "<qos></qos>");
publishOid2 = blasterConnection.publish(msgUnit).getKeyOid();
log.info("Publishing done, returned oid=" + publishOid2);
try { Thread.sleep(1000); } catch( InterruptedException i) {} // Wait a second
if (numReceived1 == 1)
log.info("Success, got Callback #1 after publishing");
else
log.severe(numReceived1 + " callbacks arrived, did expect one after a simple subscribe with a publish");
if (numReceived2 == 1)
log.info("Success, got Callback #2 after publishing");
else
log.severe(numReceived2 + " callbacks arrived, did expect one after a simple subscribe with a publish");
// cleaning up .... erase() the previous published message
xmlKey = "<key oid='" + publishOid1 + "' queryType='EXACT'>\n" +
"</key>";
EraseReturnQos[] strArr = blasterConnection.erase(xmlKey, "<qos></qos>");
if (strArr.length != 1) log.severe("Erased " + strArr.length + " message.");
xmlKey = "<key oid='" + publishOid2 + "' queryType='EXACT'>\n" +
"</key>";
strArr = blasterConnection.erase(xmlKey, "<qos></qos>");
if (strArr.length != 1) log.severe("Erased " + strArr.length + " message.");
blasterConnection.disconnect(null);
}
catch(XmlBlasterException e) {
log.severe("XmlBlasterException: " + e.getMessage());
}
catch (Exception e) {