final String secretSessionId = null;
final int pubSessionId = 1;
// "client/avalon/session/1" (we are heron and want to re-use avalons connection)
// Dangerous Precond: The remote cluster logs in with subjectId==his-nodeId and pubSessionId=1
final SessionName sessionName = new SessionName(this.remoteGlob, null, nodeInfo.getId(), pubSessionId);
SessionInfo myRemotePartnerLogin = this.fatherGlob.getRequestBroker().getAuthenticate(secretSessionId).getSessionInfo(sessionName);
this.remoteGlob.addObjectEntry(globalKey, "dummyPlaceHolder");
log.info(sessionName.toString() + " Adding initial 'dummyPlaceHolder' entryKey=" + globalKey + " global.instanceId=" +this.remoteGlob.getInstanceId() + "-" + remoteGlob.hashCode());
if (myRemotePartnerLogin == null) {
// Create the temporary SessionInfo until the real client arrives
String[] args = new String[0]; //{ "-queue/connection/defaultPlugin", "RAM,1.0" };
Global glob = this.remoteGlob; // Why?? .getClone(args);
String type = "SOCKET";
String version = "1.0";
String rawAddress = "socket://:7607";
boolean found = false;
I_Driver[] drivers = this.fatherGlob.getPluginRegistry().getPluginsOfInterfaceI_Driver();//register(pluginInfo.getId(), plugin);//getProtocolPluginManager().getPlugin(type, version)
for (int i=0; i<drivers.length; i++) {
if (drivers[i] instanceof SocketDriver) {
SocketDriver sd = (SocketDriver)drivers[i];
rawAddress = sd.getRawAddress();
type = sd.getType();
version = sd.getVersion();
found = true;
}
}
if (!found)
log.severe("No socket protocol driver found");
// TODO: How to avoid configuring the password (pass a flag to Authenticate?)
// TODO: Currently we can only configure loginName/password based credentials
// cluster/securityService/avalon=<securityService type='htpasswd' version='1.0'><user>avalon</user><passwd>secret</passwd></securityService>
String xml = this.fatherGlob.get("cluster/securityService/"+sessionName.getLoginName(), "", null, null);
if ("".equals(xml)) {
log.severe("To bootstrap an initial session of " + sessionName.getLoginName() + " cluster slave you need to give his password like this (adjust the password and the type if necessary): " +
"cluster/securityService/" + sessionName.getLoginName() + "=<securityService type='htpasswd' version='1.0'><user>" + sessionName.getLoginName() + "</user><passwd>secret</passwd></securityService>");
return null;
}
SecurityQos securityQos = new SecurityQos(glob, xml);
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 {