ConnectQos tmpQos = new ConnectQos(glob, sessionName.getRelativeName(), "");
tmpQos.getData().setSecurityQos(securityQos);
tmpQos.setSessionName(sessionName);
ClientQueueProperty prop = new ClientQueueProperty(glob, null);
prop.setType("RAM");
Address address = new Address(glob);
address.setDelay(40000L);
address.setRetries(-1);
address.setPingInterval(20000L);
address.setType(type);
address.setVersion(version);
//address.addClientProperty(new ClientProperty("useRemoteLoginAsTunnel", true));
address.addClientProperty(new ClientProperty("acceptRemoteLoginAsTunnel", true));
address.setRawAddress(rawAddress); // Address to find ourself
//address.addClientProperty(new ClientProperty("acceptRemoteLoginAsTunnel", "", "", ""+true));
prop.setAddress(address);
tmpQos.addClientQueueProperty(prop);
CallbackAddress cbAddress = new CallbackAddress(glob);
cbAddress.setDelay(40000L);
cbAddress.setRetries(-1);
cbAddress.setPingInterval(20000L);
cbAddress.setDispatcherActive(false);
cbAddress.setType(type);
cbAddress.setVersion(version);
//cbAddress.addClientProperty(new ClientProperty("useRemoteLoginAsTunnel", true));
cbAddress.addClientProperty(new ClientProperty("acceptRemoteLoginAsTunnel", true));
tmpQos.addCallbackAddress(cbAddress);
tmpQos.setPersistent(true);
glob.getXmlBlasterAccess().setServerNodeId(getId());
log.info("Creating temporary session " + sessionName.getRelativeName() + " until real cluster node "
+ glob.getXmlBlasterAccess().getServerNodeId() + " arrives");
glob.getXmlBlasterAccess().connect(tmpQos, new I_Callback() {
public String update(String cbSessionId, UpdateKey updateKey,
byte[] content, UpdateQos updateQos)
throws XmlBlasterException {
return null;
}
});
glob.getXmlBlasterAccess().leaveServer(null);
myRemotePartnerLogin = this.fatherGlob.getRequestBroker().getAuthenticate(secretSessionId).getSessionInfo(sessionName);
if (myRemotePartnerLogin == null) {
log.severe("Can't create session " + sessionName.getAbsoluteName());
return null;
}
}
DispatchManager mgr = myRemotePartnerLogin.getDispatchManager();
if (mgr != null) {
boolean fireInitial = true;
mgr.addConnectionStatusListener(new I_ConnectionStatusListener() {
// The !remote! node has logged in (not our client connection)
public void toAlive(DispatchManager dispatchManager, ConnectionStateEnum oldState) {
SessionInfo myRemotePartnerLogin = fatherGlob.getRequestBroker().getAuthenticate(secretSessionId).getSessionInfo(sessionName);
if (myRemotePartnerLogin != null && myRemotePartnerLogin.getAddressServer() != null) {
Object obj = myRemotePartnerLogin.getAddressServer().getCallbackDriver();
if (obj != null && obj instanceof CallbackSocketDriver) {
// cbDriver.callbackAddress: socket://192.168.1.20:8920
CallbackSocketDriver cbDriver = (CallbackSocketDriver)myRemotePartnerLogin.getAddressServer().getCallbackDriver();
log.info("toAlive(" + sessionName.getAbsoluteName() + ")... found existing session to back-tunnel '" + getId() + "' on address '" + myRemotePartnerLogin.getAddressServer().getRawAddress() + "' protocol=" + myRemotePartnerLogin.getAddressServer().getType() + " cbDriver-Handler " + ((cbDriver.getHandler()==null)?"null":cbDriver.getHandler().getAddressServer().getRawAddress()));
//log.severe("Register toAlive: CallbackSocketDriver.handler=" + cbDriver.getHandler());
remoteGlob.addObjectEntry(globalKey, cbDriver.getHandler());
log.info(sessionName.toString() + " Adding toAlive '" + cbDriver.getHandler() + "' entryKey=" + globalKey + " global.instanceId=" + remoteGlob.getInstanceId() + "-" + remoteGlob.hashCode());
}
else {
log.info("toAlive(" + sessionName.getAbsoluteName() + ")... no CallbackSocketDriver to back-tunnel '" + getId() + "' found");
remoteGlob.addObjectEntry(globalKey, "dummyPlaceHolder");
log.info(sessionName.toString() + " Adding toAlive 'dummyPlaceHolder' entryKey=" + globalKey + " global.instanceId=" + remoteGlob.getInstanceId() + "-" + remoteGlob.hashCode());
}
}
else {
log.info("toAlive(" + sessionName.getAbsoluteName() + ")... no session to back-tunnel '" + getId() + "' found");
remoteGlob.addObjectEntry(globalKey, "dummyPlaceHolder");
log.info(sessionName.toString() + " Adding toAlive 'dummyPlaceHolder' (myRemotePartnerLogin=null) entryKey=" + globalKey + " global.instanceId=" + remoteGlob.getInstanceId() + "-" + remoteGlob.hashCode());
}
}
public void toPolling(DispatchManager dispatchManager, ConnectionStateEnum oldState) {
log.warning("toPolling(" + sessionName.getAbsoluteName() + ") for cluster back-tunnel ...");
remoteGlob.addObjectEntry(globalKey, "dummyPlaceHolder");
log.info(sessionName.toString() + " Adding toPolling 'dummyPlaceHolder' entryKey=" + globalKey + " global.instanceId=" + remoteGlob.getInstanceId() + "-" + remoteGlob.hashCode());
if (oldState == ConnectionStateEnum.ALIVE)
ping(); // Force our client connection to POLLING as
// well
}
public void toDead(DispatchManager dispatchManager, ConnectionStateEnum oldState, XmlBlasterException xmlBlasterException) {
log.severe("toDead(" + sessionName.getAbsoluteName() + ") for cluster back-tunnel ...");
remoteGlob.addObjectEntry(globalKey, "dummyPlaceHolder");
log.info(sessionName.toString() + " Adding toDead 'dummyPlaceHolder' entryKey=" + globalKey + " global.instanceId=" + remoteGlob.getInstanceId() + "-" + remoteGlob.hashCode());
if (oldState == ConnectionStateEnum.ALIVE)
ping(); // Force our client connection to POLLING
}
public void toAliveSync(DispatchManager dispatchManager, ConnectionStateEnum oldState) {
}
}, fireInitial);
}
/* done by fireInitial
if (myRemotePartnerLogin != null && myRemotePartnerLogin.getAddressServer() != null) {
Object obj = myRemotePartnerLogin.getAddressServer().getCallbackDriver();
if (obj != null && obj instanceof CallbackSocketDriver) {
CallbackSocketDriver cbDriver = (CallbackSocketDriver)myRemotePartnerLogin.getAddressServer().getCallbackDriver();
this.remoteGlob.addObjectEntry(globalKey, cbDriver.getHandler());
}
}
*/
}
boolean acceptRemoteLoginAsTunnel = connectQosData.getAddress().getEnv("acceptRemoteLoginAsTunnel", false).getValue(); //"heron".equals(qos.getSessionName().getLoginName());
if (acceptRemoteLoginAsTunnel) { // The cluster slave accepts publish(), subscribe() etc callbacks
this.remoteGlob.addObjectEntry("ClusterManager[cluster]/I_Authenticate", this.fatherGlob.getAuthenticate());
this.remoteGlob.addObjectEntry("ClusterManager[cluster]/I_XmlBlaster", this.fatherGlob.getAuthenticate().getXmlBlaster());
}
this.xmlBlasterConnection = this.remoteGlob.getXmlBlasterAccess();
this.xmlBlasterConnection.setUserObject(this);
// force client side queue unique name, instead of setStorageIdStr()
this.xmlBlasterConnection.setServerNodeId(getId());
this.xmlBlasterConnection.registerConnectionListener(this);
final XmlBlasterAccess xbAccess = (XmlBlasterAccess)this.xmlBlasterConnection;
this.xmlBlasterConnection.registerPostSendListener(new I_PostSendListener() {
public void postSend(MsgQueueEntry[] msgQueueEntries) {
}
// For example on user.security.authorization.notAuthorized
public boolean sendingFailed(MsgQueueEntry[] entries,
XmlBlasterException exception) {
try {
for (int i=0; i<entries.length; i++) {
MsgUnit msgUnit = entries[i].getMsgUnit();
String fn = xbAccess.getFileDumper().dumpMessage(msgUnit.getKeyData(), msgUnit.getContent(), msgUnit.getQosData());
log.severe("Async sending of cluster message failed for " + msgUnit.getKeyOid() +", is dumped to " + fn + ": " + exception.getMessage());
}
}
catch (Throwable e) {
e.printStackTrace();
for (int i=0; i<entries.length; i++)
log.severe("Async sending of message failed for message " + entries[i].toXml() +"\nreason is: " + exception.getMessage());
}
// If PtP send back to sender?
return true; // Remove from connection queue! Now other messages can be delivered
}
});
/*
* // fixed to be unique since 1.5.2 boolean oldQueueNameBehavior =
* this.remoteGlob.getProperty().get(
* "xmlBlaster/cluster/useLegacyClientQueueName", false); if
* (!oldQueueNameBehavior)
* this.xmlBlasterConnection.setStorageIdStr(getId
* ()+connectQosData.getSessionName().getRelativeName()); //now
* setServerNodeId since 1.6.2+
*/
try {
Address addr = connectQosData.getAddress();
log.info("Trying to connect to node '" + getId() + "' on address '" + addr.getRawAddress() + "' using protocol=" + addr.getType());
// TODO: Check if physical IP:PORT is identical
if (this.fatherGlob.getClusterManager().getMyClusterNode().getId().equals(getId())) {
log.severe("We want to connect to ourself, route to node'" + getId() + "' ignored: ConnectQos=" + connectQosData.toXml());
return null;