conSub = globSub.getXmlBlasterAccess();
ConnectReturnQos crqSub = null;
{
ConnectQos qosSub = new ConnectQos(globSub, sessionNameSub, passwd);
CallbackAddress addr = new CallbackAddress(globSub);
addr.setRetries(-1);
String secretCbSessionId = "TrustMeSub";
addr.setSecretCbSessionId(secretCbSessionId);
qosSub.getSessionCbQueueProperty().setCallbackAddress(addr);
log.info("First subscribe connect QoS = " + qosSub.toXml());
crqSub = conSub.connect(qosSub, this.updateInterceptorSub); // Login to xmlBlaster
log.info("Connect as subscriber '" + crqSub.getSessionName() + "' success");
}
SubscribeKey sk = new SubscribeKey(globSub, oid);
SubscribeQos sq = new SubscribeQos(globSub);
sq.setWantInitialUpdate(false);
sq.setWantLocal(true);
sq.setWantContent(true);
HistoryQos historyQos = new HistoryQos(globSub);
historyQos.setNumEntries(1);
sq.setHistoryQos(historyQos);
/*SubscribeReturnQos srq = */conSub.subscribe(sk.toXml(), sq.toXml());
log.info("Subscription to '" + oid + "' done");
log.info("============ STEP 2: Start publisher");
Global globPub = glob.getClone(null);
conPub = globPub.getXmlBlasterAccess();
ConnectQos qosPub = new ConnectQos(globPub, sessionNamePub, passwd);
ConnectReturnQos crqPub = conPub.connect(qosPub, null); // Login to xmlBlaster, no updates
log.info("Connect success as " + crqPub.getSessionName());
log.info("============ STEP 3: Stop subscriber callback");
try {
Client.shutdownCb(conSub, Client.Shutdown.KEEP_LOGGED_IN);
// conSub.getCbServer().shutdown();
}
catch (XmlBlasterException e) {
fail("ShutdownCB: " + e.getMessage());
}
log.info("============ STEP 4: Publish messages");
int numPub = 8;
MsgUnit[] sentArr = new MsgUnit[numPub];
PublishReturnQos[] sentQos = new PublishReturnQos[numPub];
for(int i=0; i<numPub; i++) {
PublishKey pk = new PublishKey(globPub, oid, "text/xml", "1.0");
pk.setClientTags("<org.xmlBlaster><demo/></org.xmlBlaster>");
PublishQos pq = new PublishQos(globPub);
pq.setPriority(PriorityEnum.NORM_PRIORITY);
pq.setPersistent(false);
pq.setLifeTime(60000L);
if (i == 0) {
TopicProperty topicProperty = new TopicProperty(globPub);
topicProperty.setDestroyDelay(60000L);
topicProperty.setCreateDomEntry(true);
topicProperty.setReadonly(false);
topicProperty.getHistoryQueueProperty().setMaxEntries(numPub+5);
pq.setTopicProperty(topicProperty);
log.info("Added TopicProperty on first publish: " + topicProperty.toXml());
}
byte[] content = "Hello".getBytes();
MsgUnit msgUnit = new MsgUnit(pk, content, pq);
sentArr[i] = msgUnit;
PublishReturnQos prq = conPub.publish(msgUnit);
sentQos[i] = prq;
log.info("Got status='" + prq.getState() + "' rcvTimestamp=" + prq.getRcvTimestamp().toString() +
" for published message '" + prq.getKeyOid() + "'");
}
log.info("============ STEP 5: Start subscriber callback with same public sessionId");
Global globSub2 = glob.getClone(null);
MsgInterceptor updateInterceptorSub2 = new MsgInterceptor(globSub2, log, null);
updateInterceptorSub2.setLogPrefix("TrustMeSub2");
conSub2 = globSub2.getXmlBlasterAccess(); // Create a new client
String secretCbSessionId2 = "TrustMeSub2";
{
ConnectQos qosSub = new ConnectQos(globSub, sessionNameSub, passwd);
CallbackAddress addr = new CallbackAddress(globSub);
addr.setRetries(-1);
addr.setSecretCbSessionId(secretCbSessionId2);
qosSub.getSessionCbQueueProperty().setCallbackAddress(addr);
qosSub.getSessionQos().setSessionName(crqSub.getSessionQos().getSessionName());
log.info("Second subscribe connect QoS = " + qosSub.toXml());
ConnectReturnQos crqSub2 = conSub2.connect(qosSub, updateInterceptorSub2); // Login to xmlBlaster
log.info("Connect as subscriber '" + crqSub2.getSessionName() + "' success");
}
assertEquals("", 0, updateInterceptorSub.count()); // The first login session should not receive anything