Package org.xmlBlaster.util.queue

Examples of org.xmlBlaster.util.queue.I_QueueEntry


      long numOfPersistents = 0;
      long numOfTransients = 0;
      long sizeOfPersistents = 0L;

      for (int i=0; i < queueEntries.length; i++) {
         I_QueueEntry entry = queueEntries[i];
         if (entry.isPersistent()) {
            sizeOfPersistents += entry.getSizeInBytes();
            numOfPersistents++;
         }
         else {
            sizeOfTransients += entry.getSizeInBytes();
            numOfTransients++;
         }
      }

      long queueNumOfPersistents = queue.getNumOfPersistentEntries();
View Full Code Here


                         new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
                         new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true)
                                        };
            queue.put(queueEntries, false);
            for (int ii=0; ii<10; ii++) {
               I_QueueEntry result = queue.peek();
               assertTrue("Missing entry", result != null);
               assertEquals(ME+": Wrong result", queueEntries[0].getUniqueId(), result.getUniqueId());
            }
            queue.remove(); // Remove one
            for (int ii=0; ii<10; ii++) {
               I_QueueEntry result = queue.peek();
               assertTrue("Missing entry", result != null);
               assertEquals(ME+": Wrong result", queueEntries[1].getUniqueId(), result.getUniqueId());
            }
            queue.remove(); // Remove one
            for (int ii=0; ii<10; ii++) {
               I_QueueEntry result = queue.peek();
               assertTrue("Missing entry", result != null);
               assertEquals(ME+": Wrong result", queueEntries[2].getUniqueId(), result.getUniqueId());
            }
            queue.remove(); // Remove one
            for (int ii=0; ii<10; ii++) {
               I_QueueEntry result = queue.peek();
               assertTrue("Unexpected entry", result == null);
            }
            log.info("#1 Success, peek()");
         }
View Full Code Here

            assertEquals("number of entries incremented on last invocation", -2, this.queueSizeListener.getLastIncrementEntries());
            assertEquals("number of bytes incremented on last invocation", -2*queueEntries[0].getSizeInBytes(), this.queueSizeListener.getLastIncrementBytes());

            assertEquals(ME+": Wrong number removed", 2, numRemoved);
            assertEquals(ME+": Wrong size", 1, queue.getNumOfEntries());
            I_QueueEntry result = queue.peek();
            assertEquals(ME+": Wrong timestamp", queueEntries[1].getUniqueId(), result.getUniqueId());
            queue.clear();
            log.info("#2 Success, fill and random remove");
         }

         //========== Test 3: removeRandom 5 from 3
         {
            DummyEntry[] queueEntries = {
                         new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
                         new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
                         new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true)
                                        };
            queue.put(queueEntries, false);

            I_QueueEntry[] dataIdArr = {
                         new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
                         queueEntries[0],
                         new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
                         new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
                         queueEntries[2],
                                        };
            long numRemoved = 0L;
            boolean[] tmpArr = queue.removeRandom(dataIdArr);
            for (int i=0; i < tmpArr.length; i++) if(tmpArr[i]) numRemoved++;

            assertEquals("number of entries incremented on last invocation", -2, this.queueSizeListener.getLastIncrementEntries());
            assertEquals("number of bytes incremented on last invocation", -2*queueEntries[0].getSizeInBytes(), this.queueSizeListener.getLastIncrementBytes());

            assertEquals(ME+": Wrong number removed", 2, numRemoved);
            assertEquals(ME+": Wrong size", 1, queue.getNumOfEntries());

            I_QueueEntry entry = queue.peek();
            assertTrue("Missing entry", (I_QueueEntry)null != entry);
            assertEquals(ME+": Wrong entry removed", queueEntries[1].getUniqueId(), entry.getUniqueId());

            queue.clear();
            log.info("#3 Success, fill and random remove");
         }

View Full Code Here

            ReturnDataHolder ret = this.genericPeek((int)numOfEntries, -1L, 0, 9);
            elementsToDelete = ret.list;

            // count the persistent entries (and the persistent sizes)
            for (int i=0; i < elementsToDelete.size(); i++) {
               I_QueueEntry entry = (I_QueueEntry)elementsToDelete.get(i);
               if (entry.isPersistent()) {
                  this.numOfPersistentEntries--;
                  this.persistentSizeInBytes -= entry.getSizeInBytes();
               }
               entry.setStored(false); // tell the entry it has been removed from the storage ...
            }

            this.storage.removeAll(elementsToDelete);
            this.sizeInBytes -= ret.countBytes;
            size = elementsToDelete.size();
View Full Code Here

      synchronized (this) {
         Iterator iter = this.storage.iterator();
         // find all elements to delete ...
         while (iter.hasNext() && (ret.countEntries<numOfEntries||numOfEntries<0)) {
            I_QueueEntry entry = (I_QueueEntry)iter.next();
            currentSizeInBytes = entry.getSizeInBytes();

            if ((ret.countBytes+currentSizeInBytes>=numOfBytes) && ret.countEntries>0L && numOfBytes>-1) break;
            // further specific breaks ...
            int prio = entry.getPriority();
            if (minPrio < 0) {
               minPrio = prio;
               maxPrio = minPrio;
            }
            if (prio < minPrio) break;
View Full Code Here

      ArrayList entriesToRemove = new ArrayList();
      try {
         synchronized (this) {
            ret = genericPeek(numOfEntries, numOfBytes, minPriority, maxPriority).list;
            for (int i=0; i < ret.size(); i++) {
               I_QueueEntry entry = (I_QueueEntry)ret.get(i);
               if (this.notifiedAboutAddOrRemove) {
                  entriesToRemove.add(entry);
               }
               entry.setStored(false); // tell the entry it has been removed from the storage ...
               if (this.storage.remove(entry)) {
                  this.sizeInBytes -= entry.getSizeInBytes();
                  if (entry.isPersistent()) {
                     this.numOfPersistentEntries--;
                     this.persistentSizeInBytes -= entry.getSizeInBytes();
                  }
               }
            }
         }
      }
View Full Code Here

            long totalSizeInBytes = 0L;
            ret = new ArrayList();

            // it leaves at least one entry in the list
            while (iter.hasPrevious()) {
               I_QueueEntry entry = (I_QueueEntry)iter.previous();
               currentSizeInBytes = entry.getSizeInBytes();
               if (!isInsideRange(count, numOfEntries, totalSizeInBytes, numOfBytes)) break;
               totalSizeInBytes += currentSizeInBytes;

               if (limitEntry != null && this.comparator.compare(limitEntry, entry) >= 0) break;
               ret.add(entry);
               count++;
            }
            if (leaveOne && this.storage.size() == ret.size()) ret.remove(ret.size()-1);

            if (doDelete) {
               for (int i=0; i < ret.size(); i++) {
                  // this.storage.removeAll(ret);
                  I_QueueEntry entry =  (I_QueueEntry)ret.get(i);
                  if (this.notifiedAboutAddOrRemove) {
                     entriesToRemove.add(entry);
                  }
                  entry.setStored(false); // tell the entry it has been removed from the storage ...
                  if (this.storage.remove(entry)) {
                     this.sizeInBytes -= entry.getSizeInBytes();
                     if (entry.isPersistent()) {
                        this.numOfPersistentEntries--;
                        this.persistentSizeInBytes -= entry.getSizeInBytes();
                     }
                  }
               }
            }
            // this.sizeInBytes -= totalSizeInBytes;
View Full Code Here

      }

      synchronized(this) {
//         this.storage.addAll(java.util.Arrays.asList(msgArr));
         for (int i=0; i < msgArr.length; i++) {
            I_QueueEntry entry = msgArr[i];
            if (!this.storage.contains(entry)) {
               if (this.storage.add(entry)) {
                  entry.setStored(true);
                  this.sizeInBytes += entry.getSizeInBytes();
                  if (entry.isPersistent()) {
                     this.numOfPersistentEntries++;
                     this.persistentSizeInBytes += entry.getSizeInBytes();
                  }
                  if (this.notifiedAboutAddOrRemove) {
                     entry.added(this.storageId);
                  }
               }
            }
         }
      }
View Full Code Here

   /**
    * Comparing the longs directly is 20% faster than having a
    * String compound key
    */
   public int compare(Object o1, Object o2) {
      I_QueueEntry d1 = (I_QueueEntry)o1;
      I_QueueEntry d2 = (I_QueueEntry)o2;
      return d1.compare(d2);
   }
View Full Code Here

TOP

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

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.