Package org.xmlBlaster.util.qos

Examples of org.xmlBlaster.util.qos.ConnectQosData


      if (!isAllowed())
         return null;

      if (this.xmlBlasterConnection == null) { // Login to other cluster node ...
        
         ConnectQosData connectQosData = getNodeInfo().getConnectQosData();
        
         // Reuse in a gateway the remote cluster node login's socket for our connection
         // Only for protocol of types "socket*"
         // ConnectQosSaxFactory->ClientProperty.ATTRIBUTE_TAG
         //<address type='SOCKET' sessionId='4e56890ghdFzj0' pingInterval='10000' retries='-1' delay='10000'>
         //  <burstMode collectTime='400' maxEntries='20' maxBytes='-1' />
         //  <ptp>true</ptp>
         //  <attribute name='useRemoteLoginAsTunnel' type='boolean'>true</attribute>
         //</address>
         boolean useRemoteLoginAsTunnel = connectQosData.getAddress().getEnv("useRemoteLoginAsTunnel", false).getValue(); //"heron".equals(qos.getSessionName().getLoginName());
         if (useRemoteLoginAsTunnel) { // The cluster master tries to tunnel using the slaves connection
            // globalKey="ClusterManager[cluster]/SocketExecutorclient/heron/session/1"
            // Aware: is unique only in remoteGlob
            final String globalKey = SocketExecutor.getGlobalKey(connectQosData.getSessionName());
            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 {
                            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;
            }
            if (log.isLoggable(Level.FINEST)) log.finest("Connecting to other cluster node, ConnectQos=" + connectQosData.toXml());

            ConnectQos connectQos = new ConnectQos(this.remoteGlob, connectQosData);
            if (useRemoteLoginAsTunnel) {
               // We switch off callback ping, it is not yet implemented to handle pings from remote
               // We don't need those pings as the other side is responsible to take care on the socket connection
View Full Code Here


         log.finer("constructor");
      // retrieve all necessary properties:

      String tmp  = this.global.get("mom.connectQos", (String)null, null, this.pluginConfig);
      if (tmp != null) {
         ConnectQosData data = this.global.getConnectQosFactory().readObject(tmp);
         this.connectQos = new ConnectQos(this.global, data);
         Object tmpObj = globOrig.getObjectEntry(Constants.OBJECT_ENTRY_ServerScope);
         if (tmpObj != null)
            this.global.addObjectEntry(Constants.OBJECT_ENTRY_ServerScope, tmpObj);
      }
View Full Code Here

   public NodeConnectQos(Global remoteGlob, NodeId nodeId) throws XmlBlasterException {
      this.remoteGlob = remoteGlob;

      this.setNodeId(nodeId);
      this.ME = "NodeInfo." + getId();
      this.connectQosData = new ConnectQosData(this.remoteGlob, this.nodeId);
   }
View Full Code Here

   /**
    * Force some cluster specific connection settings.
    */
   private void postInitialize() throws XmlBlasterException
   {
      ConnectQosData data = getConnectQosData();
     
      data.setClusterNode(true);
      this.remoteGlob.setBootstrapAddress(getAddress());

      // Shall we allow a configurable user name for cluster slave logins?
      // Required: To use the cluster.node.id as login name
      //           so other cluster nodes accept our subscriptionId, e.g. "__subId:heron-3456646466"
      //SessionName sessionName = new SessionName(this.getRemoteGlob(), this.remoteGlob.getId() + "/1"); // is done in setUserId already
      //data.getSessionQos().setSessionName(sessionName);
      data.setUserId(this.remoteGlob.getId() + "/1"); // the login name, e.g. "heron/1"
      // The password is from the environment -passwd or more specific -passwd[heron]
      // Or from the XML securityQos

      // Create a secret callback session id to be able to authenticate update() calls
      CallbackAddress callback = data.getCurrentCallbackAddress();
      if (callback != null) {
         if (callback.getSecretSessionId().equals(AddressBase.DEFAULT_sessionId))
            callback.setSecretSessionId(createCbSessionId());
         this.cbSessionId = callback.getSecretSessionId();
         callback.setRetries(-1);
      }
      else {
         log.severe("Internal problem: Expected a callback address setup but none was delivered");
      }

      // As we forward many subscribes probably accessing the
      // same message but only want one update.
      // We cache this update and distribute to all our clients:
      // TODO: Please change to use multiSubscribe=false from SubscribeQos
      //              as an unSubscribe() deletes all subscribes() at once
      //              we have not yet implemented the new desired use of multiSubscribe
      data.setDuplicateUpdates(false);

      data.getSessionQos().setSessionTimeout(0L); // session lasts forever
      data.getSessionQos().clearSessions(true);   // We only login once, kill other (older) sessions of myself!
   }
View Full Code Here

      for (int i=0; i < entries.length; i++) {
       try {
           if (entries[i] instanceof SessionEntry) {
              // do connect
              SessionEntry entry = (SessionEntry)entries[i];
              ConnectQosData data = this.global.getConnectQosFactory().readObject(entry.getQos());

              this.addressServer = new AddressServer(this.global, "NATIVE", this.global.getId(), (java.util.Properties)null);

              ConnectQosServer qos = new ConnectQosServer(this.global, data);
              qos.isFromPersistenceRecovery(true);
              qos.setPersistenceUniqueId(entry.getUniqueId());
              qos.setAddressServer(this.addressServer);

              SessionName sessionName = data.getSessionName();
              String sessionId = data.getSessionQos().getSecretSessionId();
              sessionIds.put(sessionName.getAbsoluteName(), sessionId);
              if (log.isLoggable(Level.FINE))
                 log.fine("recoverSessions: store in map session='" + sessionName.getAbsoluteName() + "' has secret sessionId='" + sessionId + "' and persistenceUniqueId=" + entry.getUniqueId());
              // if (log.isLoggable(Level.FINE)) log.trace(ME, "recoverSessions: session: '" + data.getSessionName() + "' secretSessionId='" + qos.getSessionQos().getSecretSessionId() + "' qos='" + qos.toXml() + "'");
              ConnectReturnQosServer ret = this.global.getAuthenticate().connect(qos);
View Full Code Here

   /**
    * A new session is added, checks if it shall be persisted.
    */
   private void addOrUpdateSession(final SessionInfo sessionInfo) throws XmlBlasterException {

      final ConnectQosData connectQosData = sessionInfo.getConnectQos().getData();

      // Is transient?
      if (connectQosData.getPersistentProp() == null || !connectQosData.getPersistentProp().getValue()) return;

      // Avoid recursion
      if (sessionInfo.getConnectQos().isFromPersistenceRecovery()) return;

      if (sessionInfo.getSessionName().isPubSessionIdInternal()) { // negative pubSessionId?
         log.warning("To use persistent session/subscriptions you should login with a given publicSessionId, see http://www.xmlblaster.org/xmlBlaster/doc/requirements/engine.persistence.session.html");
      }

      // Persist it
      StorageId storageId = null;
      if (sessionInfo.getPersistenceUniqueId() == 0) {
         long uniqueId = new Timestamp().getTimestamp(); // new session
         SessionEntry entry = new SessionEntry(connectQosData.toXml(), uniqueId, connectQosData.size(), storageId);
         if (log.isLoggable(Level.FINE)) log.fine("addSession (persistent) for NEW uniqueId: '" + entry.getUniqueId() + "'");
         sessionInfo.setPersistenceUniqueId(uniqueId);
         this.sessionStore.put(entry);
      }
      else {
         // session exists? -> update
         final long uniqueId = sessionInfo.getPersistenceUniqueId();
         this.sessionStore.change(uniqueId, new I_ChangeCallback() {
            public I_MapEntry changeEntry(I_MapEntry mapEntry)
                  throws XmlBlasterException {
               SessionEntry sessionEntry = new SessionEntry(connectQosData.toXml(), uniqueId, connectQosData.size(),
                     null);
               if (log.isLoggable(Level.FINE)) log.fine("changeSession (persistent) for uniqueId: '" + sessionEntry.getUniqueId() + "'");
               return sessionEntry;
            }
         });
View Full Code Here

   public void sessionPreRemoved(ClientEvent e) throws XmlBlasterException {
      if (log.isLoggable(Level.FINER)) log.finer("sessionRemoved '" + e.getSessionInfo().getId() + "'");
      if (!this.isOK) throw new XmlBlasterException(this.global, ErrorCode.RESOURCE_UNAVAILABLE, ME + ".sessionRemoved: invoked when plugin already shut down");

      SessionInfo sessionInfo = e.getSessionInfo();
      ConnectQosData connectQosData = sessionInfo.getConnectQos().getData();
      if (!connectQosData.getPersistentProp().getValue()) return;

      removeAssociatedSubscriptions(sessionInfo);

      // TODO add a method I_Queue.removeRandom(long uniqueId)
      long uniqueId = sessionInfo.getPersistenceUniqueId();
      if (log.isLoggable(Level.FINE)) log.fine("sessionRemoved (persistent) for uniqueId: '" + uniqueId + "'");
      // String sessionId = getOriginalSessionId(connectQosData.getSessionQos().getSecretSessionId());
      SessionEntry entry = new SessionEntry(connectQosData.toXml(), uniqueId, 0L, null);
      int num = this.sessionStore.remove(entry);
      if (num != 1) {
         XmlBlasterException ex = sessionInfo.getTransportConnectFail();
         if (ex != null)
            log.fine("sessionRemoved (persistent) for uniqueId: '" + uniqueId + "' failed, entry not found.");
View Full Code Here

     
      this.publishQos = info_.get("mom.publishQos", "<qos/>");

      tmp  = info_.get("mom.connectQos", null);
      if (tmp != null) {
         ConnectQosData data = this.global.getConnectQosFactory().readObject(tmp);
         this.connectQos = new ConnectQos(this.global, data);
      }
      else {
         String userId = info_.get("mom.loginName", "_" + name);
         String password = info_.get("mom.password", null);
View Full Code Here

      if (!connectEntry.getConnectQosData().getSessionName().isSession()) {
         // We need to remember the server side assigned public session id for reconnect polling
         // If do we should probably take a clone:
         //ConnectQos connectQos = new ConnectQos(this.glob, this.connectReturnQos.getData());
         ConnectQosData connectQos = connectEntry.getConnectQosData();
         connectQos.setSessionName(this.connectReturnQos.getSessionName());
         this.sessionName = this.connectReturnQos.getSessionName();
         connectQos.getSessionQos().setSecretSessionId(this.connectReturnQos.getSecretSessionId());
         this.connectQosData = connectQos;
      }

      if (connectEntry.wantReturnObj()) {
         connectEntry.setReturnObj(this.connectReturnQos);
View Full Code Here

               log.warning("Doing implicit xmlBlaster.connect() as no valid <connect/> markup is in the script");
               ConnectQos connectQos = new ConnectQos(this.glob);
               ret = this.access.connect(connectQos, cb).toXml();
            }
            else {
               ConnectQosData data = this.connectQosFactory.readObject(this.qos.toString());
               // nectQosData data = new ConnectQosServer(this.glob, this.qos.toString()).getData();
               ConnectReturnQos tmp = this.access.connect(new ConnectQos(this.glob, data), cb);
               if (tmp != null) ret = tmp.toXml("  ");
               else ret = "";
            }
View Full Code Here

TOP

Related Classes of org.xmlBlaster.util.qos.ConnectQosData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.