Package org.xmlBlaster.util.queue

Examples of org.xmlBlaster.util.queue.I_Queue


         }
         else
            maxEntriesToRetrieve = getMaxNumOfEntries(slave);
      }
      // take messages from queue (none blocking) ...
      I_Queue cbQueue = dispatchManager.getQueue();
      // ArrayList entryList = cbQueue.peekSamePriority(-1, this.maxSize);
      List<I_Entry> entryList = cbQueue.peekSamePriority(maxEntriesToRetrieve, this.maxSize);
      log.info("handleNextMessages invoked with '" + entryList.size() + "' entries (max was '" + maxEntriesToRetrieve + "'");

      // filter expired entries etc. ...
      // you should always call this method after taking messages from queue
      entryList = dispatchManager.prepareMsgsFromQueue(entryList);
View Full Code Here


      if (! (source instanceof I_Queue) )
         throw new XmlBlasterException(this.global, ErrorCode.INTERNAL_ILLEGALARGUMENT, ME, "Wrong type of source for query. Expected an 'I_Queue' implementation but was '" + source.getClass().getName() + "'");
      if (query == null)
         throw new XmlBlasterException(this.global, ErrorCode.INTERNAL_ILLEGALARGUMENT, ME, "The query string is null");
        
      I_Queue queue = (I_Queue)source;        


      int maxEntries = 1;
      long maxSize = -1L;
      boolean consumable = false;
      long waitingDelay = 0L; // no wait is default
     
      // get the query properties
      //if (querySpec.getQuery() != null) query = querySpec.getQuery().getQuery();
      // "maxEntries=3&maxSize=1000&consumable=true&waitingDelay=1000"     
      Map props = StringPairTokenizer.parseToStringClientPropertyPairs(query, "&", "=");
      ClientProperty prop = (ClientProperty)props.get("maxEntries");
      if (prop != null) maxEntries = prop.getIntValue();
      prop = (ClientProperty)props.get("maxSize");
      if (prop != null) maxSize = prop.getLongValue();
      if (maxSize > -1L) {
         log.warning(" Query specification of maxSize is not implemented, please use the default value -1 or leave it untouched: '" + query + "'");
         throw new XmlBlasterException(this.global, ErrorCode.USER_ILLEGALARGUMENT, ME, "Query specification of maxSize is not implemented, please use the default value -1 or leave it untouched");
      }
      prop = (ClientProperty)props.get("consumable");
      if (prop != null) consumable = prop.getBooleanValue();
      prop = (ClientProperty)props.get("waitingDelay");
      if (prop != null) waitingDelay = prop.getLongValue();

      if (log.isLoggable(Level.FINE))
      log.fine("query: waitingDelay='" + waitingDelay + "' consumable='" + consumable + "' maxEntries='" + maxEntries + "' maxSize='" + maxSize + "'");
     
      if (waitingDelay != 0L) {
         if (log.isLoggable(Level.FINE)) log.fine("query: waiting delay is " + waitingDelay);
         if (maxEntries < 1 && maxSize < 1L && waitingDelay < 0L) {
            log.warning("If you specify a blocking get you must also specify a maximum size or maximum number of entries to retreive, otherwise specify non-blocking by setting 'waitingDelay' to zero, query is illegal: '" + query + "'");
            throw new XmlBlasterException(this.global, ErrorCode.USER_ILLEGALARGUMENT, ME, "If you specify a blocking get you must also specify a maximum size or maximum number of entries to retreive, otherwise specify non-blocking by setting 'waitingDelay' to zero");
         }
        
         WaitingQuery wq = new WaitingQuery(maxEntries, maxSize);
        
         if (checkIfNeedsWaiting((int)queue.getNumOfEntries(), queue.getNumOfBytes(), wq)) {
            if (log.isLoggable(Level.FINE)) log.fine("query: going to wait due to first check");
            try {
               synchronized (this.waitingThreads) {
                  this.waitingThreads.add(wq);
               }
               queue.addStorageSizeListener(this);
               boolean timedOut = false;
               try {
                  if (waitingDelay < 0L)
                     wq.startSignal.await();
                  else
                     timedOut = !wq.startSignal.await(waitingDelay, TimeUnit.MILLISECONDS);
                  if (log.isLoggable(Level.FINE)) log.fine("just waked up after waiting for incoming entries, timedOut=" + timedOut);
               }
               catch (InterruptedException ex) {
                  if (log.isLoggable(Level.FINE)) log.fine("just waked up because of interrupt: " + ex.toString());
               }
            }
            catch (Throwable e) {
               log.severe("Can't handle query: " + e.toString());
            }
            finally {
               try {
                  synchronized (this.waitingThreads) {
                     this.waitingThreads.remove(wq);
                  }
                  queue.removeStorageSizeListener(this);
                  if (log.isLoggable(Level.FINE)) log.fine("query: removed myself as a QueueSizeListener");
               }
               catch (Throwable ex) {
                  ex.printStackTrace();
                  log.severe("query: exception occurred when removing the QueueSizeListener from the queue:" + ex.toString());
               }
            }
         }
      }
     
      List<I_Entry> list = queue.peek(maxEntries, maxSize);
      ArrayList entryListChecked = DispatchManager.prepareMsgsFromQueue(ME, log, queue, list);
     
      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) {
            MsgQueueUpdateEntry updateEntry = (MsgQueueUpdateEntry)entry;
            msgQosData.setState(updateEntry.getState());
            msgQosData.setSubscriptionId(updateEntry.getSubscriptionId());
         }
         msgQosData.setQueueIndex(i);
         msgQosData.setQueueSize(entries.length);
         if (msgQosData.getNumRouteNodes() == 1) {
            msgQosData.clearRoutes();
         }
        
         ret.add(new MsgUnit(mu, null, null, msgQosData));
         // ret[i] = new MsgUnitRaw(mu, mu.getKeyData().toXml(), mu.getContent(), mu.getQosData().toXml());
      }
      if (consumable) queue.removeRandom(entries);
      return (MsgUnit[])ret.toArray(new MsgUnit[ret.size()]);
   }
View Full Code Here

   /**
    * @see I_Queue#embeddedObjectsToXml(OutputStream, Properties)
    */
   public long embeddedObjectsToXml(OutputStream out, Properties props) throws Exception {
      I_Queue queue = this.persistentQueue;
      if (queue != null) {
         return queue.embeddedObjectsToXml(out, null);
      }
      log.warning(ME+"Sorry, dumping transient entries to '" + out + "' is not implemented");
      return 0;
   }
View Full Code Here

         return (DispatchManagerEntry)this.dispatchManagerEntryMap.get(dispatchManager);
      }
   }

   private void putToHoldbackQueue(DispatchManagerEntry managerEntry, MsgQueueEntry entry) throws XmlBlasterException {
      I_Queue queue = managerEntry.getHoldbackQueue();
      if (queue == null) {
         synchronized (this) {
            if (queue == null) {
               // Create a queue for this plugin, inherit the settings from the original queue of DispatchManager
               I_Queue origQueue = managerEntry.getDispatchManager().getQueue();
               QueuePropertyBase queueProperties = (QueuePropertyBase) origQueue.getProperties();
               String type = queueProperties.getType();
               String version = queueProperties.getVersion();
               String typeVersion = glob.getProperty().get("PriorizedDispatchPlugin.queue.plugin", type+","+version);
               StorageId storageId = new StorageId(glob, origQueue.getStorageId().getXBStore().getNode(),
                     "PriorizedDispatchPlugin", origQueue.getStorageId().getXBStore().getPostfix());
               queue = glob.getQueuePluginManager().getPlugin(typeVersion, storageId, queueProperties);
               queue.setNotifiedAboutAddOrRemove(true); // Entries are notified to support reference counting (otherwise we have memory leaks)
               managerEntry.setHoldbackQueue(queue);
               log.info("Created holdback queue '" + queue.getStorageId() + "' with " + queue.getNumOfEntries() + " entries");
            }
View Full Code Here

    * of the DispatchManager
    */
   private void flushHoldbackQueue(DispatchManagerEntry managerEntry) {
      synchronized (this)  {
         DispatchManager dispatchManager = managerEntry.getDispatchManager();
         I_Queue holdbackQueue = managerEntry.getHoldbackQueue();
         if (holdbackQueue != null && holdbackQueue.getNumOfEntries() > 0) {
            log.info("Flushing " + holdbackQueue.getNumOfEntries() + " entries from holdback queue " + holdbackQueue.getStorageId());
            List<I_Entry> list = null;
            int lastSize = -99;
            while (holdbackQueue.getNumOfEntries() > 0) {

               try {
                  list = holdbackQueue.peek(-1, -1);
                  if (holdbackQueue.getNumOfEntries() == lastSize) {
                     log.severe("PANIC: " + holdbackQueue.getNumOfEntries() + " entries from holdback queue " + holdbackQueue.getStorageId() + " can't be flushed, giving up!");
                     break;
                  }
                  lastSize = (int)holdbackQueue.getNumOfEntries();
               }
               catch (XmlBlasterException e) {
                  log.severe("PANIC: Can't flush holdbackQueue '" + holdbackQueue.getStorageId() + "' with " + holdbackQueue.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 {
                  dispatchManager.getQueue().put(queueEntries, false);
               }
               catch (XmlBlasterException e) {
                  log.warning("flushHoldbackQueue() failed: " + e.getMessage());
                  // errorCode == "ONOVERFLOW"
                  dispatchManager.getMsgErrorHandler().handleError(new MsgErrorInfo(glob, queueEntries, dispatchManager, e));
               }

               try {
                  long num = holdbackQueue.removeNum(list.size());
                  if (num != list.size()) {
                     log.severe("PANIC: Expected to remove from holdbackQueue '" + holdbackQueue.getStorageId() + "' with " + holdbackQueue.getNumOfEntries() + " entries " + list.size() + " entries, but only " + num + " where removed");
                  }
               }
               catch (XmlBlasterException e) {
                  log.severe("PANIC: Expected to remove from holdbackQueue '" + holdbackQueue.getStorageId() + "' with " + holdbackQueue.getNumOfEntries() + " entries " + list.size() + " entries: " + e.getMessage());
               }
            }

            holdbackQueue.clear();
            dispatchManager.notifyAboutNewEntry();
         }
         else {
            if (log.isLoggable(Level.FINE)) log.fine("No holdback queue for " + dispatchManager.getId() + ", nothing to flush");
         }
View Full Code Here

         List<I_Entry> lst = null;
         while (true) {
            //synchronized(this) {
               TopicHandler topicHandler = this.serverScope.getTopicAccessor().access(this.topicId);
               try {
                  I_Queue historyQueue = topicHandler.getHistoryQueue();
                  if (historyQueue == null) {
                     this.isRunning = false;
                     break;
                  }
                  lst = historyQueue.peek(-1, -1L);
                  if (log.isLoggable(Level.FINE)) log.fine("processQueue: processing '" + lst.size() + "' entries from queue");
                  if (lst == null || lst.size() < 1) {
                     this.isRunning = false;
                     break;
                  }
View Full Code Here

            if (TopicHandler.isDirtyRead(sub, msgUnitWrapper)) {
               log.severe("ConsumableQueuePlugin used together with 'dirtyRead' is not supported");
               TopicHandler topicHandler = this.serverScope.getTopicAccessor().access(this.topicId);
               if (topicHandler == null) return true;
               try {
                  I_Queue srcQueue = topicHandler.getHistoryQueue();
                  if (srcQueue != null) srcQueue.removeRandom(entry);
               }
               finally {
                  this.serverScope.getTopicAccessor().release(topicHandler);
               }
               return true; // even if it has not been sent
            }
         }  

         for (int ii=0; ii<subInfoArr.length; ii++) {
            SubscriptionInfo sub = subInfoArr[ii];
           
            if (!TopicHandler.subscriberMayReceiveIt(sub, msgUnitWrapper)) continue;
            //Has no effect:
            //if (!this.topicHandler.checkIfAllowedToSend(null, sub)) continue;

            // this is specific for this plugin
            if (sub.getSessionInfo().getDispatchManager() == null) continue;
            if (!sub.getSessionInfo().getDispatchManager().getDispatchConnectionsHandler().isAlive()) continue;

            try {

               try {
                  TopicHandler topicHandler = this.serverScope.getTopicAccessor().access(this.topicId);
                  if (topicHandler == null) return true;
                  try {
                     // the 'false' here is to tell the filter not to send a dead letter in case of an ex
                     if (!topicHandler.checkFilter(null, sub, msgUnitWrapper, false)) continue;
                  }
                  finally {
                     this.serverScope.getTopicAccessor().release(topicHandler);
                  }
               }
               catch (XmlBlasterException ex) {
                  // continue;
                  givingUpDistribution(sub, msgUnitWrapper, entry, ex);
                  return true; // because the entry has been removed from the history queue
               }

               // put the current dispatcher at the end of the list for next invocation (round robin)
               subInfoList.remove(sub);
               subInfoList.add(sub);
              
               MsgQueueUpdateEntry updateEntry = TopicHandler.createEntryFromWrapper(msgUnitWrapper,sub);

               UpdateReturnQosServer retQos = doDistribute(sub, updateEntry);

               if (log.isLoggable(Level.FINE)) {
                  if (retQos == null) log.fine("distributeOneEntry: the return object was null: callback has not sent the message (dirty reads ?)");
               }
               if (retQos == null || retQos.getException() == null) {
                  TopicHandler topicHandler = this.serverScope.getTopicAccessor().access(this.topicId);
                  if (topicHandler == null) return true;
                  try {
                     I_Queue srcQueue = topicHandler.getHistoryQueue();
                     if (srcQueue != null) srcQueue.removeRandom(entry); // success
                  }
                  finally {
                     this.serverScope.getTopicAccessor().release(topicHandler);
                  }
                  if (log.isLoggable(Level.FINE)) log.fine("distributeOneEntry: successfully removed entry from queue");
View Full Code Here

            this.serverScope.getRequestBroker().deadMessage(new MsgQueueEntry[] { entry }, null, ME + ".givingUpDistribution: " + exTxt);
         }
         // remove the entry from the history queue now that a dead letter has been sent.
         TopicHandler topicHandler = this.serverScope.getTopicAccessor().access(this.topicId);
         try {
            I_Queue historyQueue = topicHandler.getHistoryQueue();
            if (historyQueue != null)
               historyQueue.removeRandom(entry);
         }
         finally {
            this.serverScope.getTopicAccessor().release(topicHandler);
         }
      }
View Full Code Here

   /**
    * Get the number of history message references we contain.
    */
   public long getNumOfHistoryEntries() {
      I_Queue historyQueue = this.historyQueue;
      if (historyQueue == null) {
         return 0L;
      }
      long num = historyQueue.getNumOfEntries();
      if (num > 0L && !this.dyingInProgress && !isAlive() && !isUnconfigured()) { // assert
         // isUnconfigured is possible on administrative startup with persistent messages
         log.severe(ME+": Internal problem: we have messages but are not alive: " + toXml());
         Thread.dumpStack();
      }
View Full Code Here

      I_Map msgUnitCache = this.msgUnitCache;
      if (msgUnitCache != null) {
         sb.append(msgUnitCache.toXml(extraOffset+Constants.INDENT));
      }

      I_Queue historyQueue = this.historyQueue;
      if (historyQueue != null) {
         sb.append(historyQueue.toXml(extraOffset+Constants.INDENT));
      }

      try {
         MsgUnitWrapper[] msgUnitWrapperArr = getMsgUnitWrapperArr(-1, false);
         for (int ii=0; ii<msgUnitWrapperArr.length; ii++) {
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.