Package org.xmlBlaster.util.queue

Examples of org.xmlBlaster.util.queue.I_Queue


         XmlBlasterException xmlBlasterException = msgErrorInfo.getXmlBlasterException();
         ErrorCode errorCode = xmlBlasterException.getErrorCode();
         message = xmlBlasterException.getMessage();
         MsgQueueEntry[] msgQueueEntries = msgErrorInfo.getMsgQueueEntries();
         DispatchManager dispatchManager = (this.sessionInfo == null) ? null : this.sessionInfo.getDispatchManager();
         I_Queue msgQueue = msgErrorInfo.getQueue()// is null if entry is not yet in queue
  
         if (log.isLoggable(Level.FINER)) log.finer("Error handling started: " + msgErrorInfo.toString());
  
         if (msgQueueEntries != null && msgQueueEntries.length > 0) {
            // 1. Generate dead letters from passed messages
            glob.getRequestBroker().deadMessage(msgQueueEntries, msgQueue, message);
  
            if (msgQueue != null) {
               // Remove the above published dead message from the queue
               try {
                  if (log.isLoggable(Level.FINE)) log.fine("Removing " + msgQueueEntries.length + " dead messages from queue");
                  long removed = 0L;
                  boolean tmp[] = msgQueue.removeRandom(msgQueueEntries);
                  for (int i=0; i < tmp.length; i++) if (tmp[i]) removed++;
                  if (removed != msgQueueEntries.length) {
                     log.warning("Expected to remove " + msgQueueEntries.length + " messages from queue but where only " + removed + ": " + message);
                  }
               }
               catch (XmlBlasterException e) {
                  log.warning("Can't remove " + msgQueueEntries.length + " messages from queue: " + e.getMessage() + ". Original cause was: " + message);
               }
            }
         }
  
         if (xmlBlasterException.isUser()) {
            // The update() method from the client has thrown a ErrorCode.USER* error
            if (log.isLoggable(Level.FINE)) log.fine("Error handlig for exception " + errorCode.toString() + " done");
            return;
         }
  
         // 2a. Generate dead letters if there are some entries in the queue
         size = (msgQueue == null) ? 0 : msgQueue.getNumOfEntries();
         if (log.isLoggable(Level.FINE)) log.fine("Flushing " + size + " remaining message from queue");
         if (size > 0) {
            try {
               QueuePropertyBase queueProperty = (QueuePropertyBase)msgQueue.getProperties();
               if (queueProperty == null || queueProperty.onFailureDeadMessage()) {
                  while (msgQueue.getNumOfEntries() > 0L) {
                     List<I_Entry> list = msgQueue.peek(-1, MAX_BYTES);
                     MsgQueueEntry[] msgArr = (MsgQueueEntry[])list.toArray(new MsgQueueEntry[list.size()]);
                     if (msgArr.length > 0) {
                        glob.getRequestBroker().deadMessage(msgArr, (I_Queue)null, message);
                     }
                     if (msgArr.length > 0) {
                        msgQueue.removeRandom(msgArr);
                     }
                  }
               }
               else {
                  log.severe("PANIC: Only onFailure='" + Constants.ONOVERFLOW_DEADMESSAGE +
                        "' is implemented, " + msgQueue.getNumOfEntries() + " messages are lost: " + message);
               }
            }
            catch(Throwable e) {
               e.printStackTrace();
               log.severe("PANIC: givingUpDelivery failed, " + size +
                              " messages are lost: " + message + ": " + e.toString());
            }
         }

         // 2b. Generate dead letters if there is a raw message which we could not parse
         if (msgErrorInfo.getMsgUnitRaw() != null) {
             MsgUnitRaw msgUnitRaw = msgErrorInfo.getMsgUnitRaw();
             glob.getRequestBroker().publishDeadMessageRaw(msgErrorInfo.getSessionName(), msgUnitRaw, message, null);
         }

         // We do a auto logout if the callback is down
         if (dispatchManager == null || dispatchManager.isDead()) {
            if (log.isLoggable(Level.FINE)) log.fine("Doing error handling for dead connection state ...");
  
            if (dispatchManager!=null) dispatchManager.shutdown();
  
            // 3. Kill login session
            if (this.sessionInfo != null && // if callback has been configured (async)
                sessionInfo.getConnectQos().getSessionCbQueueProperty().getCallbackAddresses().length > 0) {
              
                     log.warning("Callback server is lost, killing login session of client " +
                                   ((msgQueue == null) ? "unknown" : msgQueue.getStorageId().toString()) +
                                   ": " + message);
                     try {
                        DisconnectQos disconnectQos = new DisconnectQos(glob);
                        disconnectQos.deleteSubjectQueue(false);
                        glob.getAuthenticate().disconnect(this.sessionInfo.getAddressServer(),
View Full Code Here


         QueuePluginManager pluginManager = new QueuePluginManager(glob);
         PluginInfo pluginInfo = new PluginInfo(glob, pluginManager, type, "1.0");
         java.util.Properties prop = (java.util.Properties)pluginInfo.getParameters();
         prop.put("tableNamePrefix", "TEST");
         prop.put("entriesTableName", "_entries");
         I_Queue tmpQueue = pluginManager.getPlugin(pluginInfo, queueId, cbProp);
         tmpQueue.clear();
         // add some persistent entries and then shutdown ...
         DummyEntry entry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), 100, true);
         tmpQueue.put(entry, false);
         entry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), 100, true);
         tmpQueue.put(entry, false);
         entry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), 100, true);
         tmpQueue.put(entry, false);
         tmpQueue.shutdown(); // to allow to initialize again
         I_Queue tmpQueue2 = pluginManager.getPlugin(pluginInfo, queueId, cbProp);
         long numOfEntries = tmpQueue2.getNumOfEntries();
         assertEquals("Wrong number of entries in queue", 3L, numOfEntries);
         List<I_Entry> lst = tmpQueue2.peek(-1, -1L);
         assertEquals("Wrong number of entries retrieved from queue", 3, lst.size());
         queue.shutdown();
      }
      catch (Exception ex) {
         log.severe("setUp: error when setting the property 'cb.queue.persistent.tableNamePrefix' to 'TEST'");
View Full Code Here

         QueuePluginManager pluginManager = new QueuePluginManager(glob);
         PluginInfo pluginInfo = new PluginInfo(glob, pluginManager, type, "1.0");
         java.util.Properties prop = (java.util.Properties)pluginInfo.getParameters();
         prop.put("tableNamePrefix", "TEST");
         prop.put("entriesTableName", "_entries");
         I_Queue tmpQueue = pluginManager.getPlugin(pluginInfo, queueId, cbProp);
         tmpQueue.clear();
         // add some persistent entries and then shutdown ...
         int nmax = 1;
         int size = 100;

         for (int j=0; j < 4; j++) {
            DummyEntry[] entries = new DummyEntry[nmax];
            for (int i=0; i < nmax; i++) {
               entries[i] = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), size, true);
            }
            long time1 = System.currentTimeMillis();
            tmpQueue.put(entries, false);
            long delta = System.currentTimeMillis() - time1;
            log.info("multiple put '" + nmax + "' entries took '" + 0.001 * delta + "' seconds which is '" + 1.0 * delta / nmax + "' ms per entry");
          
            List<I_Entry> list = tmpQueue.peek(-1, -1L);
            assertEquals("Wrong number of entries in queue", nmax, list.size());
          
            time1 = System.currentTimeMillis();
            tmpQueue.removeRandom(entries);
            delta = System.currentTimeMillis() - time1;
            log.info("multiple remove '" + nmax + "' entries took '" + 0.001 * delta + "' seconds which is '" + 1.0 * delta / nmax + "' ms per entry");
            tmpQueue.clear();
          
            time1 = System.currentTimeMillis();
            for (int i=0; i < nmax; i++) {
               tmpQueue.put(entries[i], false);
            }
            delta = System.currentTimeMillis() - time1;
            log.info("repeated single put '" + nmax + "' entries took '" + 0.001 * delta + "' seconds which is '" + 1.0 * delta / nmax + "' ms per entry");
          
            time1 = System.currentTimeMillis();
            for (int i=0; i < nmax; i++) tmpQueue.removeRandom(entries[i]);
            delta = System.currentTimeMillis() - time1;
            log.info("repeated single remove '" + nmax + "' entries took '" + 0.001 * delta + "' seconds which is '" + 1.0 * delta / nmax + "' ms per entry");
            nmax *= 10;
         }
         tmpQueue.shutdown(); // to allow to initialize again
      }
      catch (Exception ex) {
         log.severe("setUp: error when setting the property 'cb.queue.persistent.tableNamePrefix' to 'TEST'");
         ex.printStackTrace();
         assertTrue("exception occured when testing initialEntries", false);
View Full Code Here

            buf.append("\n   ").append("<session id='").append(sessionInfo.getPublicSessionId()).append("'>");
            buf.append("\n    ").append("<state>").append(sessionInfo.getConnectionState()).append("</state>");
            ClientProperty[] props = sessionInfo.getRemotePropertyArr();
            for (int p=0; p<props.length; p++)
               buf.append(props[p].toXml("   ", "remoteProperty", true));
            I_Queue sessionQueue = sessionInfo.getSessionQueue();
            if (sessionQueue != null) {
               buf.append("\n    <queue relating='callback'");
               buf.append(" numOfEntries='").append(sessionQueue.getNumOfEntries()).append("'");
               buf.append(" numOfBytes='").append(sessionQueue.getNumOfBytes()).append("'");
               buf.append("/>");
               //buf.append(sessionQueue.toXml("\n    "));
            }
            buf.append(sessionInfo.getDispatchStatistic().toXml("   "));
            buf.append("\n   ").append("</session>");
         }
         buf.append("\n  ").append("</client>");
      }

      ClusterManager clusterManager = g.getClusterManagerNoEx();
      if (clusterManager != null && clusterManager.isReady()) {
         ClusterNode[] nodes = clusterManager.getClusterNodes();
         for (int ic = 0; ic < nodes.length; ic++) {
            ClusterNode node = nodes[ic];
            SessionName destination = node.getRemoteSessionName();
            if (destination == null)
               continue;
            buf.append("\n  ").append("<connection clusterId='").appendEscaped(destination.getNodeIdStr()).append(
                  "' id='").appendEscaped(destination.getLoginName()).append("'>");
            buf.append("\n   ").append("<session id='").append(destination.getPublicSessionId()).append("'>");
            buf.append("\n    ").append("<state>").append(node.getConnectionStateStr()).append("</state>");
            I_Queue clientQueue = node.getConnectionQueue();
            if (clientQueue != null) {
               buf.append("\n    <queue relating='" + Constants.RELATING_CLIENT + "'"); // "connection"
               buf.append(" numOfEntries='").append(clientQueue.getNumOfEntries()).append("'");
               buf.append(" maxNumOfEntries='").append(clientQueue.getMaxNumOfEntries()).append("'");
               buf.append(" numOfBytes='").append(clientQueue.getNumOfBytes()).append("'");
               buf.append(" maxNumOfBytes='").append(clientQueue.getMaxNumOfBytes()).append("'");
               buf.append("/>");
            }
            // buf.append(clientQueue.getDispatchStatistic().toXml("   "));
            buf.append("\n   ").append("</session>");
            buf.append("\n  ").append("</connection>");
View Full Code Here

      StorageId storageId = new StorageId(glob, this.glob.getDatabaseNodeStr(), Constants.RELATING_SUBJECT,
            this.subjectName);
      // old xb_entries:
      // StorageId storageId = new StorageId(glob, Constants.RELATING_SUBJECT,
      // this.subjectName.getAbsoluteName());
      I_Queue queue = glob.getQueuePluginManager().getPlugin(type, version, storageId, prop);
      queue.setNotifiedAboutAddOrRemove(true); // Entries are notified to support reference counting
      return queue;
   }
View Full Code Here

         }

         // TODO: Extend CACHE queue to handle reconfigurations hidden so we don't need to do anything here

         if (!this.subjectQueue.isTransient()) {
            I_Queue newQueue = createSubjectQueue(prop);
            if (newQueue.isTransient()) {
               log.info(ME+": Reconfiguring subject queue: Copying " + this.subjectQueue.getNumOfEntries() + " entries from old " + origProp.getType() + " queue to " + prop.getTypeVersion() + " queue");
               List<I_Entry> list = null;
               int lastSize = -99;
               while (this.subjectQueue.getNumOfEntries() > 0) {

                  try {
                     list = this.subjectQueue.peek(-1, -1);
                     if (this.subjectQueue.getNumOfEntries() == lastSize) {
                        log.severe(ME+": PANIC: " + this.subjectQueue.getNumOfEntries() + " entries from old queue " + this.subjectQueue.getStorageId() + " can't be copied, giving up!");
                        break;
                     }
                     lastSize = (int)this.subjectQueue.getNumOfEntries();
                  }
                  catch (XmlBlasterException e) {
                     log.severe(ME+": PANIC: Can't copy from subject queue '" + this.subjectQueue.getStorageId() + "' with " + this.subjectQueue.getNumOfEntries() + " entries: " + e.getMessage());
                     e.printStackTrace();
                     continue;
                  }

                  MsgQueueEntry[] queueEntries = (MsgQueueEntry[])list.toArray(new MsgQueueEntry[list.size()]);
                  // On error we send them as dead letters, as we don't know what to do with them in our holdback queue
                  try {
                     newQueue.put(queueEntries, false);
                  }
                  catch (XmlBlasterException e) {
                     log.warning(ME+": flushHoldbackQueue() failed: " + e.getMessage());
                     // errorCode == "ONOVERFLOW"
                     getMsgErrorHandler().handleError(new MsgErrorInfo(glob, queueEntries, null, e));
View Full Code Here

      // ... or send to ALL sessions
      SessionInfo[] sessions = getSessions();
      for (int i=0; i<sessions.length; i++) {
         SessionInfo sessionInfo = sessions[i];
         I_Queue sessionQueue = sessionInfo.getSessionQueue();
         if (sessionInfo.getConnectQos().isPtpAllowed() && sessionInfo.hasCallback() && sessionQueue != null) {
            if (log.isLoggable(Level.FINE)) log.fine(ME+": Forwarding msg " + entry.getLogId() + " from " +
                          this.subjectQueue.getStorageId() + " size=" + this.subjectQueue.getNumOfEntries() +
                          " to session queue " + sessionQueue.getStorageId() +
                          " size=" + sessionQueue.getNumOfEntries() + " ...");
            try {
               MsgQueueUpdateEntry entryCb = new MsgQueueUpdateEntry((MsgQueueUpdateEntry)entry, sessionQueue.getStorageId());
               sessionInfo.queueMessage(entryCb);
               countForwarded++;
            }
            catch (XmlBlasterException e) {
               if (log.isLoggable(Level.FINE)) log.fine(ME+": Can't forward message from subject queue '" + this.subjectQueue.getStorageId() + "' to session '" + sessionInfo.getId() + "', we keep it in the subject queue: " + e.getMessage());
View Full Code Here

                     final long currMsgUnitId = entry.getUniqueId();
                     final Long currMsgUnitIdL = new Long(currMsgUnitId);

                     // Process the history queue of this topic if the messagUnit is referenced
                     int before = foundInHistoryQueue.size() + notFoundInHistoryQueue.size();
                     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)
View Full Code Here

         this.lock.release();
      }
      this.glob.unregisterMBean(this.mbeanHandle);
      removeExpiryTimer();

      I_Queue sessionQueue = this.sessionQueue;
      if (sessionQueue != null) {
         sessionQueue.shutdown();
         //this.sessionQueue = null; Not set to null to support avoid synchronize(this.sessionQueue)
      }

      if (this.msgErrorHandler != null)
         this.msgErrorHandler.shutdown();
View Full Code Here

   /**
    * Is the given address the same as our?
    */
   public final boolean hasAddress(AddressBase addr) {
      if (addr == null) return false;
      I_Queue sessionQueue = getSessionQueue();
      if (sessionQueue == null) return false;
      CallbackAddress[] arr = ((CbQueueProperty)sessionQueue.getProperties()).getCallbackAddresses();
      for (int ii=0; arr!=null && ii<arr.length; ii++) {
         // if (arr[ii].isSameAddress(addr))
         if (arr[ii].equals(addr))
            return true;
      }
View Full Code Here

TOP

Related Classes of org.xmlBlaster.util.queue.I_Queue

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.