public HelloWorld3(Global glob) {
this.glob = glob;
I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess();
try {
// Check if other login name or password was given on command line:
// (This is redundant as it is done by ConnectQos already)
String name = glob.getProperty().get("session.name", "HelloWorld3");
String passwd = glob.getProperty().get("passwd", "secret");
ConnectQos qos = new ConnectQos(glob, name, passwd);
con.connect(qos, this); // Login to xmlBlaster, register for updates
PublishKey pk = new PublishKey(glob, "HelloWorld3", "text/xml", "1.0");
pk.setClientTags("<org.xmlBlaster><demo/></org.xmlBlaster>");
PublishQos pq = new PublishQos(glob);
pq.addClientProperty("myAge", 84);
MsgUnit msgUnit = new MsgUnit(pk, "Hi", pq);
con.publish(msgUnit);
GetKey gk = new GetKey(glob, "HelloWorld3");
GetQos gq = new GetQos(glob);
MsgUnit[] msgs = con.get(gk, gq);
if (msgs.length > 0) {
GetReturnQos grq = new GetReturnQos(glob, msgs[0].getQos());
log.info("Accessed xmlBlaster message with content '" + new String(msgs[0].getContent()) +
"' and status=" + grq.getState());
}
SubscribeKey sk = new SubscribeKey(glob, "HelloWorld3");
SubscribeQos sq = new SubscribeQos(glob);
SubscribeReturnQos subRet = con.subscribe(sk, sq);
msgUnit = new MsgUnit(pk, "Ho".getBytes(), pq);
PublishReturnQos prq = con.publish(msgUnit);
log.info("Got status='" + prq.getState() + "' for published message '" + prq.getKeyOid());
try { Thread.sleep(1000); }
catch( InterruptedException i) {} // wait a second to receive update()
UnSubscribeKey uk = new UnSubscribeKey(glob, subRet.getSubscriptionId());
UnSubscribeQos uq = new UnSubscribeQos(glob);
UnSubscribeReturnQos[] urq = con.unSubscribe(uk, uq);
if (urq.length > 0) log.info("Unsubscribed from topic");
EraseKey ek = new EraseKey(glob, "HelloWorld3");
EraseQos eq = new EraseQos(glob);
EraseReturnQos[] eraseArr = con.erase(ek, eq);
if (eraseArr.length > 0) log.info("Erased topic");
DisconnectQos dq = new DisconnectQos(glob);
con.disconnect(dq);
glob.shutdown(); // free resources
}
catch (XmlBlasterException e) {
log.severe(e.getMessage());
}