Package org.xmlBlaster.client.qos

Examples of org.xmlBlaster.client.qos.ConnectQos


      try {

         {  // setup the sender client ...
            sender = glob.getXmlBlasterAccess();

            ConnectQos qos = new ConnectQos(sender.getGlobal(), senderName, "secret");
            ConnectReturnQos conRetQos = sender.connect(qos, new I_Callback() {
               public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {
                  log.info("Receiving asynchronous message '" + updateKey.getOid() + "' in sender default handler" );
                  log.info("Received: " + updateKey.toXml() + "\n <content>" + new String(content) + "</content>" + updateQos.toXml());
                  return "";
               }
            })// Login to xmlBlaster, default handler for updates

            log.info("Sender connected to xmlBlaster " + conRetQos.getSessionName().getRelativeName());
         }


         {  // setup the receiver client ...
            Global globReceiver = glob.getClone(null);
            receiver = globReceiver.getXmlBlasterAccess();

            ConnectQos qos = new ConnectQos(receiver.getGlobal(), receiverName, "secret");
            ConnectReturnQos conRetQos = receiver.connect(qos, new I_Callback() {
               public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {
                  log.info("Receiving asynchronous message '" + updateKey.getOid() + "' in receiver default handler");
                  log.info("Received: " + updateKey.toXml() + "\n <content>" + new String(content) + "</content>" + updateQos.toXml());
View Full Code Here


      String user="ADMIN/1";
      String passwd="secret";
      try {
         Global gAdmin = glob.getClone(null);
         connAdmin = gAdmin.getXmlBlasterAccess();
         connAdmin.connect(new ConnectQos(gAdmin, user, passwd), null);
         GetKey gk = new GetKey(glob, command);
         GetQos gq = new GetQos(glob);
         MsgUnit[] msgs = connAdmin.get(gk, gq);
         return msgs;
      }
View Full Code Here

   /** Stop xmlBlaster server (invoked by junit automatically as name starts with 'test') */
   public void testStop() {
      try {
         I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess();

         ConnectQos qos = new ConnectQos(glob, "joe", "secret");
         con.connect(qos, null);

         con.publish(new MsgUnit("<key oid='__cmd:?exit=0'/>", "".getBytes(), "<qos/>"));

         con.disconnect(null);

         // xmlBlaster shuts down 2 sec later + time to process shutdown
         try { Thread.sleep(4000L); } catch( InterruptedException i) {}

         try {
            Global glob2 = this.glob.getClone(null);
            I_XmlBlasterAccess con2 = glob2.getXmlBlasterAccess();
            ConnectQos connectQos = new ConnectQos(glob2, "joe", "secret");
            con2.connect(connectQos, null);
            fail("No connection expected");
         }
         catch(org.xmlBlaster.util.XmlBlasterException e) {
            System.err.println("Success, connection not possible any more");
View Full Code Here

               }

            });


         ConnectQos qos = new ConnectQos(glob);
         conRetQos = con.connect(qos, new I_Callback() {

            public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {
               if (log.isLoggable(Level.FINEST)) log.finest("UpdateKey.toString()=" + updateKey.toString() +
                                          "UpdateQos.toString()=" + updateQos.toString());
               if (updateKey.isInternal()) {
                  log.severe("Receiving unexpected asynchronous internal message '" + updateKey.getOid() +
                                "' in default handler");
                  return "";
               }
               if (updateQos.isErased()) {
                  log.info("Message '" + updateKey.getOid() + "' is erased");
                  return "";
               }
               if (updateKey.getOid().equals("Banking"))
                  log.info("Receiving asynchronous message '" + updateKey.getOid() +
                               "' state=" + updateQos.getState() + " in default handler");
               else
                  log.severe("Receiving unexpected asynchronous message '" + updateKey.getOid() +
                                   "' in default handler");
               return "";
            }

         })// Login to xmlBlaster, default handler for updates


         if (con.isAlive())
            log.info("Connected as " + qos.getUserId() + " to xmlBlaster, your public session ID is " + conRetQos.getSessionName());
         else
            log.info("Not connected to xmlBlaster, proceeding in fail save mode ...");

         while (true) {
            // Wait a second for messages to arrive before we logout
View Full Code Here

   {
      Global glob = new Global(args);
      sleepTime = Long.parseLong(args[1]);
      random = new Random(100L);
      this.connection = glob.getXmlBlasterAccess();
      ConnectQos connectQos = new ConnectQos(glob, "chessMover", "secret");
      this.connection.connect(connectQos, null);
   }
View Full Code Here

                  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
               connectQos.getSessionCbQueueProperty().getCurrentCallbackAddress().setPingInterval(0L);
               connectQos.getAddress().setPingInterval(0L);
            }

            ConnectReturnQos retQos = this.xmlBlasterConnection.connect(connectQos, this);
           
            if (log.isLoggable(Level.FINE)) log.fine("Connected to server " + retQos.getServerInstanceId());
View Full Code Here

      }


      tmp  = info.get("mom.connectQos", (String)null);
      if (tmp != null) {
         this.connectQos = new ConnectQos(this.glob, this.glob.getConnectQosFactory().readObject(tmp));
      }
      else {
         this.connectQos = new ConnectQos(this.glob, this.loginName, this.password);
         int maxSessions = info.getInt("mom.maxSessions", 100);
         this.connectQos.setMaxSessions(maxSessions);
         this.connectQos.getAddress().setRetries(-1);
         this.connectQos.setSessionTimeout(0L);
         if (info.getBoolean("mom.updateBulkAck", false))
View Full Code Here

            return;
         }

         String tmp  = this.global.get("connectQos", (String)null, null, pluginInfo);
         if (tmp != null) {
            this.connectQos = new ConnectQos(this.global,
                  this.global.getConnectQosFactory().readObject(tmp));
         }
         else {
            String loginName = this.global.get("loginName", "_StartupTasks", null, this.pluginInfo);
            String password = this.global.get("password", "secret", null, this.pluginInfo);
            this.connectQos = new ConnectQos(this.global, loginName, password);
         }

         excuteStartupTasks();
      }
      finally {
View Full Code Here

      // 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);
      }
      else {
         String userId = this.global.get("mom.loginName", "_" + this.name, null, this.pluginConfig);
         String password = this.global.get("mom.password", (String)null, null, this.pluginConfig);
         this.connectQos = new ConnectQos(this.global, userId, password);
         this.global.addObjectEntry(Constants.OBJECT_ENTRY_ServerScope, globOrig.getObjectEntry(Constants.OBJECT_ENTRY_ServerScope));
      }

     
      momAdministered = this.global.get("mom.administered", false, null, pluginConfig);
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);
         this.connectQos = new ConnectQos(this.global, userId, password);
         global.addObjectEntry(Constants.OBJECT_ENTRY_ServerScope, globOrig.getObjectEntry(Constants.OBJECT_ENTRY_ServerScope));
      }

      this.fileFilter =  info_.get("filewatcher.fileFilter", null);
      this.directoryName = info_.get("filewatcher.directoryName", null);
View Full Code Here

TOP

Related Classes of org.xmlBlaster.client.qos.ConnectQos

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.