Package org.xmlBlaster.client.qos

Examples of org.xmlBlaster.client.qos.PublishReturnQos


            }

            byte[] content = "Hello".getBytes();
            MsgUnit msgUnit = new MsgUnit(pk, content, pq);
            sentArr[i] = msgUnit;
            PublishReturnQos prq = conSnd.publish(msgUnit);
            sentQos[i] = prq;
            log.info("Got status='" + prq.getState() + "' rcvTimestamp=" + prq.getRcvTimestamp().toString() +
                        " for published message '" + prq.getKeyOid() + "'");
         }

         log.info("============ STEP 3: Stop xmlBlaster");
         this.serverThread.stopServer(true);
View Full Code Here


      try {
         PublishKey pk = new PublishKey(glob, publishOid, "text/xml", "1.0");
         PublishQos pq = new PublishQos(glob);
         pq.setTopicProperty(topicProperty);
         MsgUnit msgUnit = new MsgUnit(pk, senderContent, pq);
         PublishReturnQos publishReturnQos = con.publish(msgUnit);
         assertEquals("Retunred oid is invalid", publishOid, publishReturnQos.getKeyOid());
         log.info("Topic oid=" + publishOid + " created: " + msgUnit.toXml());
      } catch(XmlBlasterException e) {
         log.severe("publish() XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
View Full Code Here

            topicProperty.setDestroyDelay(topicDestroyDelay);
            topicProperty.setCreateDomEntry(false);
            pq.setTopicProperty(topicProperty);
         }
         MsgUnit msgUnit = new MsgUnit(pk, senderContent, pq);
         PublishReturnQos publishReturnQos = con.publish(msgUnit);
         assertEquals("Retunred oid is invalid", publishOid, publishReturnQos.getKeyOid());
         log.info("Sending of '" + senderContent + "' done, returned oid=" + publishOid + " " + msgUnit.toXml());
      } catch(XmlBlasterException e) {
         log.severe("publish() XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
View Full Code Here

            Destination dest = new Destination(globSnd, new SessionName(globSnd, sessionNameRcv));
            pq.addDestination(dest);
            pq.setSubscribable(false);
            byte[] content = "Hello".getBytes();
            MsgUnit msgUnit = new MsgUnit(pk, content, pq);
            PublishReturnQos prq = conSnd.publish(msgUnit);
            log.info("Got status='" + prq.getState() + "' rcvTimestamp=" + prq.getRcvTimestamp().toString() +
                         " for published message '" + prq.getKeyOid() + "'");
            assertEquals("", 1, this.updateInterceptorRcv.waitOnUpdate(1000L, oid, Constants.STATE_OK));
            assertEquals("", secretCbSessionId, this.updateInterceptorRcv.getMsg(oid, Constants.STATE_OK).getCbSessionId());
            assertEquals("", 0, this.updateInterceptorSnd.waitOnUpdate(1000L, oid, Constants.STATE_OK));
           
            this.updateInterceptorRcv.clear();
            this.updateInterceptorSnd.clear();
         }

         {
            log.info("============ STEP 5: Publish PtP message which IS subscribable");
            PublishKey pk = new PublishKey(globSnd, oid, "text/xml", "1.0");
            PublishQos pq = new PublishQos(globSnd);
            Destination dest = new Destination(globSnd, new SessionName(globSnd, sessionNameRcv));
            pq.addDestination(dest);
            pq.setSubscribable(true);
            byte[] content = "Hello".getBytes();
            MsgUnit msgUnit = new MsgUnit(pk, content, pq);
            PublishReturnQos prq = conSnd.publish(msgUnit);
            log.info("Got status='" + prq.getState() + "' rcvTimestamp=" + prq.getRcvTimestamp().toString() +
                         " for published message '" + prq.getKeyOid() + "'");

            assertEquals("", 1, this.updateInterceptorRcv.waitOnUpdate(1000L, oid, Constants.STATE_OK));
            assertEquals("", secretCbSessionId, this.updateInterceptorRcv.getMsg(oid, Constants.STATE_OK).getCbSessionId());
            assertEquals("", 1, this.updateInterceptorSnd.waitOnUpdate(1000L, oid, Constants.STATE_OK));
            assertEquals("", secretSndCbSessionId, this.updateInterceptorSnd.getMsg(oid, Constants.STATE_OK).getCbSessionId());
View Full Code Here

     * Publish one message
     */
    public PublishReturnQos publish(MsgUnit msgUnit)
        throws XmlBlasterException {
        checkSanity();
        PublishReturnQos ret = null;
        try {
            ret = mc.getBlasterConnection().publish(msgUnit);
        }catch(XmlBlasterException ex) {
                    //Try one more time
            try {
View Full Code Here

            key = new PublishKey(this.glob, changeKey);
         else
            key = new PublishKey(this.glob, "dbWatcherUnspecified");
         key.setContentMime("text/xml");
         MsgUnit msg = new MsgUnit(key, out, qos);
         PublishReturnQos prq = this.con.publish(msg);
         String id = (prq.getRcvTimestamp()!=null)?prq.getRcvTimestamp().toString():"queued";
         if (log.isLoggable(Level.FINE)) log.fine("Published '" + prq.getKeyOid() + "' '" + id + "'");
         return id;
      }
      if (this.eraseOnDrop && "DROP".equals(command)) {
         String oid = this.glob.getMsgKeyFactory().readObject(pk).getOid();
         EraseKey ek = new EraseKey(glob, oid);
         EraseQos eq = new EraseQos(glob);
         con.erase(ek, eq);
         log.info("Topic '" + pk + "' is erased:" + out);
         return "0";
      }
      if (this.eraseOnDelete && "DELETE".equals(command)) {
         String oid = this.glob.getMsgKeyFactory().readObject(pk).getOid();
         EraseKey ek = new EraseKey(glob, oid);
         EraseQos eq = new EraseQos(glob);
         con.erase(ek, eq);
         log.info("Topic '" + pk + "' is erased:" + out);
         return "0";
      }
      if (log.isLoggable(Level.FINER))
         log.finer("Topic '" + pk + "' is published: " + out);
      try {
         String oid = (String)attrMap.remove(ContribConstants.TOPIC_NAME); // consume it since only used to inform this method
         if (destination != null) {
            pk = this.adminKey;
         }
         if (oid != null)
            pk = "<key oid='" + oid + "'/>";
         MsgUnit msgUnit = new MsgUnit(pk, out, this.publishQos);
         String tmp = msgUnit.getKeyData().getContentMime();
         // FIXME pass this in the map and set only if explicitly set in the map
         if (tmp == null || tmp.equals("text/plain")) {
            msgUnit.getKeyData().setContentMime("text/xml");
         }
         if (destination != null)
            ((MsgQosData)msgUnit.getQosData()).addDestination(destination);
         // to force to fill the client properties map !!
         ClientPropertiesInfo tmpInfo = new ClientPropertiesInfo(attrMap);
         new ClientPropertiesInfo(msgUnit.getQosData().getClientProperties(), tmpInfo);
         addStringPropToQos(attrMap, (MsgQosData)msgUnit.getQosData());

         PublishReturnQos prq = this.con.publish(msgUnit);
         String id = (prq.getRcvTimestamp()!=null)?prq.getRcvTimestamp().toString():"queued";
         if (log.isLoggable(Level.FINE))
            log.fine("Published '" + prq.getKeyOid() + "' '" + id + "'");
         this.lastPublishTime = System.currentTimeMillis() - t0;
         return id;
      }
      catch (XmlBlasterException e) {
         log.severe("Can't publish to xmlBlaster: " + e.getMessage());
View Full Code Here

         SubscribeQos sq = new SubscribeQos(glob);
         SubscribeReturnQos subRet = con.subscribe(sk, sq);


         msgUnit = new MsgUnit(pk, "Ho".getBytes(), pq);
         PublishReturnQos prq = con.publish(msgUnit);

         log.info("Got status='" + prq.getState() + "' for published message '" + prq.getKeyOid());

         try { Thread.sleep(1000); }
         catch( InterruptedException i) {} // wait a second to receive update()

View Full Code Here

                     // Send reply back ...
                     PublishKey pk = new PublishKey(receiver.getGlobal(), tempTopicOid, "text/plain", "1.0");
                     PublishQos pq = new PublishQos(receiver.getGlobal());
                     MsgUnit msgUnit = new MsgUnit(pk, "On doubt no ultimate truth, my dear.", pq);
                     //try { Thread.sleep(8000); } catch (InterruptedException e) { e.printStackTrace(); }
                     PublishReturnQos retQos = receiver.publish(msgUnit);
                     log.info(receiverName+": Published reply message using temporary topic " + retQos.getKeyOid());
                  }
                  catch (XmlBlasterException e) {
                     log.severe(receiverName+": Sending reply to " + updateQos.getSender() + " failed: " + e.getMessage());
                  }
                  return "";
View Full Code Here

            public void postSend(MsgQueueEntry[] entries) {
               try {
                  for (int i=0; i<entries.length; i++) {
                     if (MethodName.PUBLISH.equals(entries[i].getMethodName())) {
                        MsgUnit msg = entries[i].getMsgUnit();
                        PublishReturnQos retQos = (PublishReturnQos)entries[i].getReturnObj();
                        log.info("Send asynchronously message '" + msg.getKeyOid() + "' from queue: " + retQos.toXml());
                     }
                     else
                        log.info("Send asynchronously " + entries[i].getMethodName() + " message from queue");
                  }
               } catch (Throwable e) {
                  e.printStackTrace();
               }
            }

            /**
             * @see I_PostSendListener#sendingFailed(MsgQueueEntry[], XmlBlasterException)
             */
            public boolean sendingFailed(MsgQueueEntry[] entries, XmlBlasterException ex) {
               try {
                  for (int i=0; i<entries.length; i++) {
                     if (MethodName.PUBLISH.equals(entries[i].getMethodName())) {
                        MsgUnit msg = entries[i].getMsgUnit();
                        log.info("Send asynchronously message '" + msg.getKeyOid() + "' from queue failed: " + ex.getMessage());
                     }
                     else
                        log.info("Send asynchronously " + entries[i].getMethodName() + " message from queue");
                  }
               } catch (Throwable e) {
                  e.printStackTrace();
               }
               //return true; // true: We have handled the case (safely stored the message) and it may be removed from connection queue
               return false; // false: Default error handling: message remains in queue and we go to dead
            }
         });

         // ConnectQos checks -session.name and -passwd from command line
         log.info("============= CreatingConnectQos");
         ConnectQos qos = new ConnectQos(glob);
         if (connectPersistent) {
            qos.setPersistent(connectPersistent);
         }
         // "__remoteProperties"
         qos.getData().addClientProperty(Constants.CLIENTPROPERTY_REMOTEPROPERTIES, true);
         if (connectQosClientPropertyMap != null) {
            Iterator it = connectQosClientPropertyMap.keySet().iterator();
            while (it.hasNext()) {
               String key = (String)it.next();
               qos.addClientProperty(key, connectQosClientPropertyMap.get(key).toString());
            }
         }
         log.info("ConnectQos is " + qos.toXml());
         ConnectReturnQos crq = con.connect(qos, new I_Callback() {
      public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) throws XmlBlasterException {
        try {
          log.info("Received '" + updateKey.getOid() + "':" + new String(content, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
          log.severe("Update failed: " + e.toString());
        }
        return "";
      }
         })// Login to xmlBlaster, register for updates
         log.info("Connect success as " + crq.toXml());

         org.xmlBlaster.util.StopWatch stopWatch = new org.xmlBlaster.util.StopWatch();
         for(int i=0; true; i++) {
            if (numPublish != -1)
               if (i>=numPublish)
                  break;

            String currCounter = ""+(i+1);
            if (numPublish > 0) { // Add leading zeros to have nice justified numbers in dump
               String tmp = ""+numPublish;
               int curLen = currCounter.length();
               currCounter = "";
               for (int j=curLen; j<tmp.length(); j++) {
                  currCounter += "0";
               }
               currCounter += (i+1);
            }

            String currOid = org.xmlBlaster.util.ReplaceVariable.replaceAll(oid, "%counter", currCounter);

            if (interactive) {
               char ret = (char)Global.waitOnKeyboardHit("Hit 'b' to break, hit other key to publish '" + currOid + "' #" + currCounter + "/" + numPublish);
               if (ret == 'b')
                  break;
            }
            else {
               if (sleep > 0 && i > 0) {
                  try { Thread.sleep(sleep); } catch( InterruptedException e) {}
               }
               log.info("Publish '" + currOid + "' #" + currCounter + "/" + numPublish);
            }

            PublishKey pk = new PublishKey(glob, currOid, "text/xml", "1.0");
            if (domain != null) pk.setDomain(domain);
            pk.setClientTags(org.xmlBlaster.util.ReplaceVariable.replaceAll(clientTags, "%counter", currCounter));
            PublishQos pq = new PublishQos(glob);
            pq.setPriority(priority);
            pq.setPersistent(persistent);
            pq.setLifeTime(lifeTime);
            pq.setForceUpdate(forceUpdate);
            pq.setForceDestroy(forceDestroy);
            pq.setSubscribable(subscribable);
            if (clientPropertyMap != null) {
               Iterator it = clientPropertyMap.keySet().iterator();
               while (it.hasNext()) {
                  String key = (String)it.next();
                  pq.addClientProperty(key, clientPropertyMap.get(key).toString());
               }
               //Example for a typed property:
               //pq.getData().addClientProperty("ALONG", (new Long(12)));
            }

            if (i == 0) {
               TopicProperty topicProperty = new TopicProperty(glob);
               topicProperty.setDestroyDelay(destroyDelay);
               topicProperty.setCreateDomEntry(createDomEntry);
               topicProperty.setReadonly(readonly);
               if (historyMaxMsg >= 0L) {
                  HistoryQueueProperty prop = new HistoryQueueProperty(this.glob, null);
                  prop.setMaxEntries(historyMaxMsg);
                  topicProperty.setHistoryQueueProperty(prop);
               }
               if (consumableQueue)
                  topicProperty.setMsgDistributor("ConsumableQueue,1.0");
               pq.setTopicProperty(topicProperty);
               log.info("Added TopicProperty on first publish: " + topicProperty.toXml());
            }

            if (destination != null) {
               log.fine("Using destination: '" + destination + "'");
               Destination dest = new Destination(glob, new SessionName(glob, destination));
               dest.forceQueuing(forceQueuing);
               pq.addDestination(dest);
            }

            byte[] content;
            if (contentSize >= 0) {
               content = new byte[contentSize];
               Random random = new Random();
               for (int j=0; j<content.length; j++) {
                  content[j] = (byte)(random.nextInt(96)+32);
                  //content[j] = (byte)('X');
                  //content[j] = (byte)(j % 255);
               }
            }
            else if (contentFile != null && contentFile.length() > 0) {
               content = FileLocator.readFile(contentFile);
            }
            else {
               content = org.xmlBlaster.util.ReplaceVariable.replaceAll(contentStr, "%counter", ""+(i+1)).getBytes();
            }

            if (log.isLoggable(Level.FINEST)) log.finest("Going to parse publish message: " + pk.toXml() + " : " + content + " : " + pq.toXml());
            MsgUnit msgUnit = new MsgUnit(pk, content, pq);
            if (log.isLoggable(Level.FINEST)) log.finest("Going to publish message: " + msgUnit.toXml());

            if (oneway) {
               MsgUnit msgUnitArr[] = { msgUnit };
               con.publishOneway(msgUnitArr);
               log.info("#" + (i+1) + "/" + numPublish +
                         ": Published oneway message '" + msgUnit.getKeyOid() + "'");
            }
            else {
               PublishReturnQos prq = con.publish(msgUnit);
               if (log.isLoggable(Level.FINEST)) log.finest("Returned: " + prq.toXml());

               log.info("#" + currCounter + "/" + numPublish +
                         ": Got status='" + prq.getState() +
                         (prq.getData().hasStateInfo()?"' '" + prq.getStateInfo():"") +
                         "' rcvTimestamp=" + prq.getRcvTimestamp() +
                         " for published message '" + prq.getKeyOid() + "'");
            }
         }
         log.info("Elapsed since starting to publish: " + stopWatch.nice(numPublish));

         if (erase) {
View Full Code Here


         PublishKey pk = new PublishKey(glob, "HelloWorld6", "text/plain", "1.0");
         PublishQos pq = new PublishQos(glob);
         MsgUnit msgUnit = new MsgUnit(pk, "Hi".getBytes(), pq);
         PublishReturnQos retQos = con.publish(msgUnit);
         log.info("Published message '" + pk.getOid() + "' " + retQos.getState());


         pk = new PublishKey(glob, "Banking", "text/plain", "1.0");
         pk.setClientTags("<Account><withdraw/></Account>"); // Add banking specific meta data
         pq = new PublishQos(glob);
View Full Code Here

TOP

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

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.