System.exit(1);
}
StopWatch stop = new StopWatch();
try {
I_XmlBlasterAccess blasterConnection = glob.getXmlBlasterAccess();
// Login and install the Callback server
ConnectQos qos = new ConnectQos(glob);
blasterConnection.connect(qos, this);
String publishOid = "";
String xmlKey = "<key oid='' contentMime='text/xml'>\n" +
"<AGENT id='192.168.124.10' subId='1' type='generic'>" +
"<DRIVER id='FileProof' pollingFreq='10'>" +
"</DRIVER>"+
"</AGENT>" +
"</key>";
//----------- Construct a message and publish it ---------
{
String content = "<person><name>Ghandi</name></person>";
MsgUnit msgUnit = new MsgUnit(xmlKey, content.getBytes(), "");
log.fine("Publishing ...");
stop.restart();
try {
publishOid = blasterConnection.publish(msgUnit).getKeyOid();
log.info(" Returned oid=" + publishOid);
log.fine("Publishing done" + stop.nice());
} catch(XmlBlasterException e) {
log.severe("Punlishing failed, XmlBlasterException: " + e.getMessage());
}
}
//----------- Subscribe to the previous message OID -------
log.fine("Subscribing using the exact oid ...");
xmlKey = "<?xml version='1.0' encoding='ISO-8859-1' ?>\n" +
"<key oid='" + publishOid + "' queryType='EXACT'>\n" +
"</key>";
stop.restart();
try {
String subId = blasterConnection.subscribe(xmlKey, "<qos></qos>").getSubscriptionId();
log.fine("Subscribed to '" + subId + "' ..." + stop.nice());
} catch(XmlBlasterException e) {
log.severe("Subscribe failed, XmlBlasterException: " + e.getMessage());
}
try { Thread.currentThread().sleep(2000); } catch( InterruptedException i) {} // Wait a second
//----------- Unsubscribe from the previous message --------
log.fine("Unsubscribe ...");
stop.restart();
try {
blasterConnection.unSubscribe(xmlKey, "<qos></qos>");
log.info("Unsubscribe done" + stop.nice());
} catch(XmlBlasterException e) {
log.severe("Unsubscribe failed, XmlBlasterException: " + e.getMessage());
}
//----------- Subscribe to the previous message XPATH -------
log.fine("Subscribing using XPath syntax ...");
xmlKey = "<?xml version='1.0' encoding='ISO-8859-1' ?>\n" +
"<key oid='' queryType='XPATH'>\n" +
"/xmlBlaster/key/AGENT" +
"</key>";
stop.restart();
try {
blasterConnection.subscribe(xmlKey, "<qos></qos>");
log.fine("Subscribe done, there should be a Callback");
} catch(XmlBlasterException e) {
log.severe("subscribe failed, XmlBlasterException: " + e.getMessage());
}
try { Thread.currentThread().sleep(2000); } catch( InterruptedException i) {} // Wait a second
log.fine("Publishing 10 times ...");
{
for (int ii=0; ii<10; ii++) {
//----------- Construct a message and publish it ---------
String content = "<person><name>Castro</name><age>" + ii + "</age></person>";
xmlKey = "<key oid='" + publishOid + "' contentMime='text/xml'>\n</key>";
MsgUnit msgUnit = new MsgUnit(xmlKey, content.getBytes(), "");
log.fine("Publishing ...");
stop.restart();
try {
String str = blasterConnection.publish(msgUnit).getKeyOid();
log.fine("Publishing done" + stop.nice());
} catch(XmlBlasterException e) {
log.severe("Publishing failed, XmlBlasterException: " + e.getMessage());
}
}
}
try { Thread.currentThread().sleep(2000); } catch( InterruptedException i) {} // Wait a second
blasterConnection.disconnect(null);
}
catch (Exception e) {
e.printStackTrace();
}