protected synchronized void flushToDisk() {
if (!memoryList.isEmpty()) {
while (!memoryList.isEmpty()) {
MessageReference node = memoryList.removeFirst();
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);
}