コード例 #1
0
 protected synchronized void flushToDisk() {
   if (!memoryList.isEmpty() && store != null) {
     long start = 0;
     if (LOG.isTraceEnabled()) {
       start = System.currentTimeMillis();
       LOG.trace(
           "{}, flushToDisk() mem list size: {} {}",
           new Object[] {
             name, memoryList.size(), (systemUsage != null ? systemUsage.getMemoryUsage() : "")
           });
     }
     for (Iterator<MessageReference> iterator = memoryList.iterator(); iterator.hasNext(); ) {
       MessageReference node = iterator.next();
       node.decrementReferenceCount();
       ByteSequence bs;
       try {
         bs = getByteSequence(node.getMessage());
         getDiskList().addLast(node.getMessageId().toString(), bs);
       } catch (IOException e) {
         LOG.error("Failed to write to disk list", e);
         throw new RuntimeException(e);
       }
     }
     memoryList.clear();
     setCacheEnabled(false);
     LOG.trace(
         "{}, flushToDisk() done - {} ms {}",
         new Object[] {
           name,
           (System.currentTimeMillis() - start),
           (systemUsage != null ? systemUsage.getMemoryUsage() : "")
         });
   }
 }
コード例 #2
0
 @Override
 public synchronized void destroy() throws Exception {
   stop();
   for (Iterator<MessageReference> i = memoryList.iterator(); i.hasNext(); ) {
     MessageReference node = i.next();
     node.decrementReferenceCount();
   }
   memoryList.clear();
   destroyDiskList();
 }
コード例 #3
0
 protected synchronized void expireOldMessages() {
   if (!memoryList.isEmpty()) {
     for (Iterator<MessageReference> iterator = memoryList.iterator(); iterator.hasNext(); ) {
       MessageReference node = iterator.next();
       if (node.isExpired()) {
         node.decrementReferenceCount();
         discardExpiredMessage(node);
         iterator.remove();
       }
     }
   }
 }
コード例 #4
0
 /** @return true if there are no pending messages */
 @Override
 public synchronized boolean isEmpty() {
   if (memoryList.isEmpty() && isDiskListEmpty()) {
     return true;
   }
   for (Iterator<MessageReference> iterator = memoryList.iterator(); iterator.hasNext(); ) {
     MessageReference node = iterator.next();
     if (node == QueueMessageReference.NULL_MESSAGE) {
       continue;
     }
     if (!node.isDropped()) {
       return false;
     }
     // We can remove dropped references.
     iterator.remove();
   }
   return isDiskListEmpty();
 }
コード例 #5
0
 @Override
 public synchronized LinkedList<MessageReference> pageInList(int maxItems) {
   LinkedList<MessageReference> result = new LinkedList<MessageReference>();
   int count = 0;
   for (Iterator<MessageReference> i = memoryList.iterator(); i.hasNext() && count < maxItems; ) {
     MessageReference ref = i.next();
     ref.incrementReferenceCount();
     result.add(ref);
     count++;
   }
   if (count < maxItems && !isDiskListEmpty()) {
     for (Iterator<MessageReference> i = new DiskIterator(); i.hasNext() && count < maxItems; ) {
       Message message = (Message) i.next();
       message.setRegionDestination(regionDestination);
       message.setMemoryUsage(this.getSystemUsage().getMemoryUsage());
       message.incrementReferenceCount();
       result.add(message);
       count++;
     }
   }
   return result;
 }