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() : "") }); } }
/** @return the number of pending messages */ @Override public synchronized int size() { return memoryList.size() + (isDiskListEmpty() ? 0 : (int) getDiskList().size()); }