package run.chronicle.queue;

import net.openhft.chronicle.bytes.MethodReader;
import net.openhft.chronicle.core.io.IOTools;
import net.openhft.chronicle.queue.ChronicleQueue;

// run with -Xmx128m -XX:NewSize=96m -verbose:gc
public class MessageMain {
    private static final int COUNT = Integer.getInteger("count", 10_000_000);

    public static void main(String[] args) {
        for (int t = 0; t < 100; t++) {
            String test = "test-" + System.nanoTime();
            try (ChronicleQueue queue = ChronicleQueue.single(test)) {
                Messages messages = queue.methodWriter(Messages.class);
                Message message = new Message();
                for (int i = 0; i < COUNT; i++) {
                    message.getText().clear().append("Hello ").append(i);
                    message.setTimeStamp(System.currentTimeMillis());
                    messages.mesg(message);
                }

                int[] count = {0};
                Messages messagesCounter = message1 -> count[0]++;
                MethodReader reader = queue.createTailer().methodReader(messagesCounter);
                while (reader.readOne()) {
                }
                System.out.println("Read " + count[0] + " of " + COUNT + " messages");
            }
            IOTools.deleteDirWithFiles(test);
        }
    }
}

@@ -402,11 +402,9 @@
 t %3C 
-100
+5
 ; t+
@@ -404,24 +404,68 @@
 %3C 5; t++) %7B%0A
+            long start = System.nanoTime();%0A
             
@@ -488,33 +488,21 @@
 est-%22 + 
-System.nanoTime()
+start
 ;%0A      
@@ -1189,32 +1189,87 @@
               %7D%0A
+                long time = System.nanoTime() - start;%0A
                 
@@ -1288,60 +1288,83 @@
 rint
-ln
+f
 (%22Read 
-%22 + count%5B0%5D + %22 of %22 + COUNT + %22 messages%22
+%25,d of %25,d messages in %25.3f seconds%25n%22, count%5B0%5D, COUNT, time / 1e9
 );%0A 

Add a demo for writing and reading messages containing text. #5