Package org.xmlBlaster.engine.queuemsg

Examples of org.xmlBlaster.engine.queuemsg.ReferenceEntry


      int maxLength = getProperty().get("xmlBlaster/peekMessages/maxLength", 5000);

      ArrayList tmpList = new ArrayList();
      for (int i=0; i<list.size(); i++) {
         ReferenceEntry entry = (ReferenceEntry)list.get(i);
         MsgUnitWrapper wrapper = entry.getMsgUnitWrapper();
         tmpList.add("<MsgUnit index='"+i+"'>");
         if (wrapper == null) {
            tmpList.add("  NOT REFERENCED " + entry.getInfoWithoutMeat());
         }
         else {
            tmpList.add("  "+wrapper.getMsgKeyData().toXml());
            String content = wrapper.getMsgUnit().getContentStr();
            if (content.length() > (maxLength+5) ) {
View Full Code Here


         path = "";
      dumper.init(this, path);

      ArrayList tmpList = new ArrayList();
      for (int i=0; i<list.size(); i++) {
         ReferenceEntry entry = (ReferenceEntry)list.get(i);
         MsgUnitWrapper wrapper = entry.getMsgUnitWrapper();
         if (wrapper == null) {
            tmpList.add("NOT REFERENCED #" + i + " " + entry.getInfoWithoutMeat());
         }
         else {
            String fileName = dumper.store(wrapper);
            tmpList.add(fileName);
         }
View Full Code Here

      MsgQueueEntry[] entries = (MsgQueueEntry[])entryListChecked.toArray(new MsgQueueEntry[entryListChecked.size()]);
     
      ArrayList ret = new ArrayList(entries.length);
      for (int i=0; i < entries.length; i++) {
         // TODO: REQ engine.qos.update.queue states that the queue size is passed and not the curr msgArr.length
         ReferenceEntry entry = (ReferenceEntry)entries[i];
         MsgUnit mu = entry.getMsgUnitOrNull();
         if (mu == null)
            continue;
         MsgQosData msgQosData = (MsgQosData)mu.getQosData().clone();
         msgQosData.setTopicProperty(null);
         if (entry instanceof MsgQueueUpdateEntry) {
View Full Code Here

         // if (entries != null && entries.size() > 1)
         //    log.severe("the entries are '" + entries.size() + "' but we currently only can process one single entry at a time");
        
         // check if already processed ... and at the same time do the versioning transformation (if needed)
         for (int i=entries.size()-1; i > -1; i--) {
            ReferenceEntry entry = (ReferenceEntry)entries.get(i);
            MsgUnit msgUnit = entry.getMsgUnit();
            ClientProperty alreadyProcessed = msgUnit.getQosData().getClientProperty(ReplicationConstants.ALREADY_PROCESSED_ATTR);
            if (alreadyProcessed != null) {
               log.warning("Received entry for client '" + this.slaveSessionId + "' which was already processed. Will remove it");
               queue.removeRandom(entry);
               entries.remove(i);
            }
            else
               doTransform(msgUnit);
         }
        
         // check if one of the messages is the transition end tag, also check if the total size is exceeded
         ArrayList remoteEntries = new ArrayList();
         long totalSize = 0L;
         for (int i=0; i < entries.size(); i++) {
            ReferenceEntry entry = (ReferenceEntry)entries.get(i);
            MsgUnit msgUnit = entry.getMsgUnit();
            ClientProperty endMsg = msgUnit.getQosData().getClientProperty(ReplicationConstants.END_OF_TRANSITION);
           
            // check if the message is the end of the data (only sent in case the initial data has to be stored on
            // file in which case the dispatcher shall return in its waiting state.
            ClientProperty endOfData = msgUnit.getQosData().getClientProperty(ReplicationConstants.INITIAL_DATA_END);
            ClientProperty initialFilesLocation = msgUnit.getQosData().getClientProperty(ReplicationConstants.INITIAL_FILES_LOCATION);
            ClientProperty subDirName = msgUnit.getQosData().getClientProperty(ReplicationConstants.INITIAL_DATA_ID);
            if (endOfData != null) {
               final boolean doPersist = true;
               doPause(doPersist);
               queue.removeRandom(entry);
               // entries.remove(i); // endOfData will be kept locally, not sent to slave
               String dirName = "unknown";
               if (subDirName != null) {
                  if (initialFilesLocation != null) {
                     File base = new File(initialFilesLocation.getStringValue().trim());
                     File complete = new File(base, subDirName.getStringValue().trim());
                     dirName = complete.getAbsolutePath();
                  }
               }
               changeLastMessage("Manual Data transfer: WAITING (stored on '" + dirName + "')");
               break; // we need to interrupt here: all subsequent entries will be processed later.
            }

            // check if the message has to be stored locally
            ClientProperty endToRemote = msgUnit.getQosData().getClientProperty(ReplicationConstants.INITIAL_DATA_END_TO_REMOTE);
            if (initialFilesLocation != null && (endToRemote == null || !endToRemote.getBooleanValue()) && (endMsg == null || !endMsg.getBooleanValue())) {
               storeChunkLocally(entry, initialFilesLocation, subDirName);
               queue.removeRandom(entry);
               // entries.remove(i);
               continue;
            }
           
            if (endMsg != null) {
               log.info("Received msg marking the end of the initial for client '" + this.slaveSessionId + "' update: '" + this.name + "' going into NORMAL operations");
               startCascadedAndChangeStatus();
            }
            byte[] content = msgUnit.getContent();
            if (content != null)
               totalSize += content.length;
            if (totalSize <= this.maxChunkSize || i == 0)
               remoteEntries.add(entry);
            else
               break;
         }
         entries = null; // we can free it here since not needed anymore
        
         if (this.status == STATUS_NORMAL || this.status == STATUS_INCONSISTENT || this.status == STATUS_UNCONFIGURED)
            return remoteEntries;
        
         ArrayList ret = new ArrayList();
         for (int i=0; i < remoteEntries.size(); i++) {
            ReferenceEntry entry = (ReferenceEntry)remoteEntries.get(i);
            MsgUnit msgUnit = entry.getMsgUnit();
            long replKey = msgUnit.getQosData().getClientProperty(ReplicationConstants.REPL_KEY_ATTR, -1L);
            /* this is done when acknowledge comes
            if (replKey > -1L) {
               setMaxReplKey(replKey, this.tmpTransSeq, this.tmpMsgSeq);
            }
            */
            log.info("check: processing '" + replKey + "' for client '" + this.slaveSessionId + "' ");
            if (replKey < 0L) { // this does not come from the normal replication, so these are other messages which we just deliver
               ClientProperty endMsg = msgUnit.getQosData().getClientProperty(ReplicationConstants.END_OF_TRANSITION);
               if (endMsg == null) {
                  log.warning("the message unit with qos='" + msgUnit.getQosData().toXml() + "' and key '" + msgUnit.getKey() + "'  for client '" + this.slaveSessionId + "' has no 'replKey' Attribute defined.");
                  ret.add(entry);
                  continue;
               }
            }
            log.info("repl entry '" + replKey + "' for range [" + this.minReplKey + "," + this.maxReplKey + "] for client '" + this.slaveSessionId + "' ");
            if (replKey >= this.minReplKey || this.forceSending) {
               log.info("repl adding the entry for client '" + this.slaveSessionId + "' ");
               doTransform(msgUnit);
               ret.add(entry);
               /* TODO TEMPORARLY REMOVED FOR TESTING: also test no initial dump and manual transfer
               if (replKey > this.maxReplKey || this.forceSending) {
                  log.info("entry with replKey='" + replKey + "' is higher than maxReplKey)='" + this.maxReplKey + "' switching to normal operation again for client '" + this.slaveSessionId + "' ");
                  startCascadedAndChangeStatus();
               }
               */
            }
            else { // such messages have been already from the initial update. (obsolete messages are removed)
               log.info("removing entry with replKey='" + replKey + "' since older than minEntry='" + this.minReplKey + "' for client '" + this.slaveSessionId + "' ");
               queue.removeRandom(entry);
            }
         }
        
         // check if there are more than one entry the keep-transaction-flag has to be set:
         if (ret.size() > 1) {
            for (int i=0; i < ret.size()-1; i++) {
               ReferenceEntry entry = (ReferenceEntry)entries.get(i);
               MsgUnit msgUnit = entry.getMsgUnit();
               msgUnit.getQosData().addClientProperty(KEEP_TRANSACTION_OPEN, true);
            }
            log.info("Sending '" + ret.size() + "' entries in one single message");
         }
         return ret;
View Full Code Here

         return "The queue for the slave '" + this.name + "' is empty: not dumping anything";
      try {
         List<I_Entry> list = this.queue.peek(maxNum, maxSize);
         FileOutputStream out = new FileOutputStream(fileName);
         for (int i=0; i < list.size(); i++) {
            ReferenceEntry entry = (ReferenceEntry)list.get(i);
            byte[] ret = decompressQueueEntryContent(entry);
            out.write(ret);
         }
         out.close();
         String txt = "successfully dumped " + list.size() + " entries on file '" + fileName + "'";
View Full Code Here

                  }
                  if (relating.equals(Constants.RELATING_SUBJECT) || relating.equals(Constants.RELATING_CALLBACK)) {
                     // callback_nodeheronclientjack1
                     // clientsubscriber71
                     // New xbpostfix: "client/jack/session/1"
                     ReferenceEntry refEntry = (ReferenceEntry) ent;
                     // Reconstruct sessionName
                     // /node/heron/client/subscriberDummy <->
                     // clientsubscriberDummy1
                     SessionName sn = refEntry.getReceiver();
                     if (!transferClusterNode(sn.getNodeIdStr())) {
                        logToFile(relating + ": Ignoring wrong cluster node '"
                              + sn.getNodeIdStr() + "': "
                              + sn.getAbsoluteName());
                        return null;
                     }
                     // Fix pubSessionId if it was a PtP to subject
                     String queueName = refEntry.getStorageId().getOldPostfix();
                     // queueName=callback_nodeheronclientsubscriberDummy1
                     // subject_nodeheronclientsubscriberNotExist
                     String strippedLoginName = Global.getStrippedString(sn.getLoginName());
                     int pos = queueName.lastIndexOf(strippedLoginName);
                     if (pos != -1) {
                        String pubStr = queueName.substring(pos + strippedLoginName.length());
                        if (pubStr.length() > 0) { // has pubSessionId
                           try {
                              int pubSessionId = Integer.parseInt(pubStr);
                              sn = new SessionName(serverScopeThree, sn.getNodeId(), sn.getLoginName(), pubSessionId);
                           } catch (NumberFormatException e) {
                              logToFile(queueNamePattern + "[counter=" + processed + "]: SessionName problem queueName="
                                    + queueName + ": " + e.toString());
                              e.printStackTrace();
                           }
                        }
                     }
                     // logToFile(queueNamePattern + "[counter=" + counter
                     // + "]: queueName=" + queueName + " new=" +
                     // sn.getAbsoluteName() + " strippedLoginName=" +
                     // strippedLoginName + " oldPostfix=" +
                     // refEntry.getStorageId().getXBStore().getPostfix());
                     refEntry.setStorageId(new StorageId(serverScopeThree,
                           sn.getNodeId().getId()/* clusterNodeIdToTransfer */,
                           relating, sn));
                     /*
                      * } else { // Dangerous guess: String queueName =
                      * refEntry.getStorageId().getOldPostfix(); SessionName sn
                      * = SessionName.guessSessionName(serverScopeOne,
                      * clusterNodeIdToTransfer, queueName,
                      * limitPositivePubToOneDigit); refEntry.setStorageId(new
                      * StorageId(serverScopeThree, clusterNodeIdToTransfer,
                      * relating, sn)); }
                      */
                     XBStore xbStore = getXBStore(dbAccessorServerThree, serverScopeThree, refEntry.getStorageId());
                     dbAccessorServerThree.addEntry(xbStore, refEntry);
                  } else if (relating.equals(Constants.RELATING_HISTORY)) {
                     MsgQueueHistoryEntry entry = (MsgQueueHistoryEntry) ent;
                     entry.getStorageId().getXBStore().setPostfix(entry.getKeyOid());
                     if (!entry.getStorageId().getPostfix1().startsWith(relating + "_" + clusterNodeIdToTransfer)) {
                        logToFile(relating + ": Ignoring wrong cluster node "
                              + entry.getStorageId().getPostfix1()
                              + ": " + entry.getStorageId().getId());
                        return null;
                     }
                     XBStore xbStore = getXBStore(dbAccessorServerThree, serverScopeThree, entry.getStorageId());
                     dbAccessorServerThree.addEntry(xbStore, entry);
                  } else if (ent instanceof ReferenceEntry) {
                     ReferenceEntry refEntry = (ReferenceEntry) ent;
                     XBStore xbStore = getXBStore(dbAccessorServerThree, serverScopeThree, refEntry.getStorageId());
                     dbAccessorServerThree.addEntry(xbStore, refEntry);
                  } else {
                     I_MapEntry entry = (I_MapEntry) ent;
                     if (relating.equals(Constants.RELATING_MSGUNITSTORE)) {
                        if (!entry.getStorageId().getPostfix1().startsWith(
View Full Code Here

               log.severe("Didn't expect null element in MsgQueueEntry[], ignoring it");
               continue;
            }
            MsgUnit origMsgUnit = null;
            if (entry instanceof ReferenceEntry) {
               ReferenceEntry referenceEntry = (ReferenceEntry)entry;
               origMsgUnit = ((ReferenceEntry)entry).getMsgUnitOrNull();
               if (origMsgUnit == null) {
                  if (log.isLoggable(Level.FINE)) log.fine("Ignoring dead message for destroyed callback queue entry " + referenceEntry.getLogId());
                  continue;
               }
            }
            else {
               log.severe("PANIC: Internal error in deadMessage data type");
               retArr[ii] = "PANIC";
               continue;
            }
            // entry.getLogId()="callback:/node/heron/client/Subscriber/1/NORM/1196854278910000000/Hello"
            String clientPropertyKey = "__isErrorHandled" + entry.getLogId();
            String text = "Generating dead message '" + entry.getLogId() + "'" +
                         " from publisher=" + entry.getSender() +
                         " because delivery " +            // entry.getReceiver() is recognized in queueId
                         ((queue == null) ? "" : "with queue '"+queue.getStorageId().toString()+"' ") + "failed" +
                         ((reason != null) ? (": " + reason) : "");
            log.warning(text);
            retArr[ii] = publishDeadMessage(origMsgUnit, text, clientPropertyKey, entry.getReceiver());
         }
         return retArr;
      }
      catch (Throwable e) {
         log.severe("PANIC: " + entries.length + " dead letters are lost, no recovery possible:" + e.getMessage());
         for (int ii=0; ii<entries.length; ii++) {
            MsgQueueEntry entry = entries[ii];
            try {
               if (entry == null) {
                  continue;
               }
               /*
               else if (entry instanceof MsgUnitWrapper) {
                  MsgUnitWrapper msgUnitWrapper = (MsgUnitWrapper)entry;
                  String fileName = glob.getMsgFileDumper().store(msgUnitWrapper);
                  log.warn(ME, "Dumped lost message to file " + fileName);
               }
               */
               else if (entry instanceof MsgQueueHistoryEntry) {
                  log.warning("History entry is lost: " + entry.toXml());
               }
               else if (entry instanceof MsgQueueUpdateEntry) {
                  ReferenceEntry referenceEntry = (ReferenceEntry)entry;
                  if (referenceEntry.isDestroyed()) {
                     if (log.isLoggable(Level.FINE)) log.fine("Ignoring detroyed callback message " + entry.getLogId());
                  }
                  else {
                     log.warning("Callback of message failed unrecoverably: " + entry.toXml());
                  }
View Full Code Here

               manager.getEntriesLike(queueNamePattern, flag, -1, -1,
                     new I_EntryFilter() {
                  public I_Entry intercept(I_Entry ent, I_Storage storage) {
                     try {
                        if (ent instanceof ReferenceEntry) {
                           ReferenceEntry callbackEntry = (ReferenceEntry)ent;
                           //final long refId = callbackEntry.getMsgUnitWrapperUniqueId();
                           // TODO: extract if negative sessionId
                           SessionName sessionName = callbackEntry.getReceiver();
                           long publicSessionId = sessionName.getPublicSessionId();
                           if (publicSessionId < 0) {
                              SessionInfo sessionInfo = authenticate.getSessionInfoByName(sessionName);
                              if (sessionInfo == null) {
                                 leakedEntries.add(ent);
                                 out.write(("Found leak entry '" + ent.getLogId() + "' of unknown session " + sessionName.getAbsoluteName() + "\n").getBytes());
                              }
                           }
                        }
                        else {
                           // todo: other checks
                        }
                        return null; // Filter away so getAll returns nothing
                     }
                     catch (Throwable e) {
                        log.warning("Ignoring during callback queue processing exception: " + e.toString());
                        return null; // Filter away so getAll returns nothing
                     }
                  }
               });
               if (fixIt && leakedEntries.size() > 0) {
                  Properties props = new Properties();
                  props.put(Constants.TOXML_FORCEREADABLE, ""+true);
                  log.severe("Removing now "+leakedEntries.size()+" leak entries");
                  Iterator it = leakedEntries.iterator();
                  while (it.hasNext()) {
                     I_Entry entry = (I_Entry)it.next();
                     ReferenceEntry callbackEntry = (ReferenceEntry)entry;
                     try {
                        long num = manager.deleteEntry(callbackEntry.getStorageId().getStrippedId(), entry.getUniqueId());
                        out.write(("\nRemoving " + num + " leaking entry:").getBytes());
                        out.write(("'"+callbackEntry.getStorageId().getStrippedId() + "': " + entry.getLogId()).getBytes());
                        if (num > 0)
                           entry.embeddedObjectToXml(out, props);
                        log.fine("Removing " + num + " leaking entry '"+entry.getLogId()+"'");
                     }
                     catch (XmlBlasterException e) {
View Full Code Here

                     I_Queue historyQueue = topicHandler.getHistoryQueue();
                     if (historyQueue != null) {
                        historyQueue.getEntries(new I_EntryFilter() {
                           public I_Entry intercept(I_Entry ent, I_Storage storage) {
                              try {
                                 ReferenceEntry historyEntry = (ReferenceEntry)ent;
                                 final long refId = historyEntry.getMsgUnitWrapperUniqueId();
                                 if (refId == currMsgUnitId)
                                    foundInHistoryQueue.put(currMsgUnitIdL, historyEntry);
                                 //else
                                 //   notFoundInHistoryQueue.put(currMsgUnitIdL, entry);
                                 return null; // Filter away so getAll returns nothing
                              }
                              catch (Throwable e) {
                                 log.warning("Ignoring during history queue processing exception: " + e.toString());
                                 return null; // Filter away so getAll returns nothing
                              }
                           }
                        });
                     }
                     if (before == (foundInHistoryQueue.size() + notFoundInHistoryQueue.size())) // no hit
                        notFoundInHistoryQueue.put(currMsgUnitIdL, entry);

                     // Raw database access: process all queues used by plugins which also may reference the msgUnitStore
                     before = foundInCallbackQueue.size() + notFoundInCallbackQueue.size();
                     if (manager != null) {
                        try {
                           // needs tuning as we make a wildcard query for each msgUnit ...
                           //ArrayList ret = manager.getEntries(StorageId storageId, long[] dataids); // not possible as we need to lookup the referenced dataid
                           String queueNamePattern = Constants.RELATING_CALLBACK + "%";
                           String flag = "UPDATE_REF";
                           manager.getEntriesLike(queueNamePattern, flag, -1, -1,
                                 new I_EntryFilter() {
                              public I_Entry intercept(I_Entry ent, I_Storage storage) {
                                 try {
                                    if (ent instanceof ReferenceEntry) {
                                       ReferenceEntry callbackEntry = (ReferenceEntry)ent;
                                       final long refId = callbackEntry.getMsgUnitWrapperUniqueId();
                                       if (refId == currMsgUnitId)
                                          foundInCallbackQueue.put(currMsgUnitIdL, callbackEntry);
                                       //else
                                       //   notFoundInCallbackQueue.put(currMsgUnitIdL, entry);
                                    }
                                    else {
                                       // todo
                                    }
                                    return null; // Filter away so getAll returns nothing
                                 }
                                 catch (Throwable e) {
                                    log.warning("Ignoring during callback queue processing exception: " + e.toString());
                                    return null; // Filter away so getAll returns nothing
                                 }
                              }
                           });
                           if (before == (foundInCallbackQueue.size() + notFoundInCallbackQueue.size())) // no hit
                              notFoundInCallbackQueue.put(currMsgUnitIdL, entry);

                        }
                        catch (Throwable e) {
                           log.severe("Raw access to database failed: " + e.toString());
                        }
                     }
                     else {
                        log.warning("Raw access to database is not possible");
                     }

                     if (manager == null) { // fallback if raw access failed
                        // Process the callback queue of each loaded client (we won't find transient clients with positive session id and not yet re-connected)
                        SessionInfo[] arr = authenticate.getSessionInfoArr();
                        for (int i=0; i<arr.length; i++) {
                           SessionInfo sessionInfo = arr[i];
                           I_Queue callbackQueue = sessionInfo.getSessionQueue();
                           if (callbackQueue != null) {
                              callbackQueue.getEntries(new I_EntryFilter() {
                                 public I_Entry intercept(I_Entry ent, I_Storage storage) {
                                    try {
                                       ReferenceEntry callbackEntry = (ReferenceEntry)ent;
                                       final long refId = callbackEntry.getMsgUnitWrapperUniqueId();
                                       if (refId == currMsgUnitId)
                                          foundInCallbackQueue.put(currMsgUnitIdL, callbackEntry);
                                       //else
                                       //   notFoundInCallbackQueue.put(currMsgUnitIdL, entry);
                                       return null; // Filter away so getAll returns nothing
View Full Code Here

TOP

Related Classes of org.xmlBlaster.engine.queuemsg.ReferenceEntry

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.