Queue V4: how to set up vanilla/indexed like in V3?

75 views
Skip to first unread message

arbitrage...@gmail.com

unread,
Jun 16, 2016, 10:10:07 AM6/16/16
to Chronicle
Hi,

i think every body is excited of waiting the new technical doc of the v4.
hope that this v4 will be as excellent as the v3.

also before we were used to do:

while(true){
   if(tailer.hasNext()){
   ...
   }
}

1- what the approach now.
2- how to set up the rolling period
3- how to handle the indexed style queue like in v3

Rob Austin

unread,
Jun 16, 2016, 11:14:51 AM6/16/16
to java-ch...@googlegroups.com
I hope these code snippets help, please look at the project git test cases for other examples

1. hasNext 


check for dc.isPresent() == true to see if there is a next entry.

see code in net.openhft.chronicle.queue.impl.single.SingleChronicleQueueTest#testReadingDocument
try (final DocumentContext dc = tailer.readingDocument()) {
assert dc.isPresent();
assert dc.isData();
dc.wire().read(() -> "key").text(sb);
Assert.assertEquals("value=0", sb.toString());
}

2 Rolling 
 

see net.openhft.chronicle.queue.RollCycles

for example see net.openhft.chronicle.queue.impl.single.SingleChronicleQueueTest#testReadingDocumentWithFirstAMove

    try (final RollingChronicleQueue queue = SingleChronicleQueueBuilder.binary(getTmpDir())
        .wireType(this.wireType)
.rollCycle(RollCycles.HOURLY)
.build()) {
….
}

3. indexes 

see net.openhft.chronicle.queue.LastIndexAppendedTest#testLastIndexAppendedAcrossRestarts
@Test
public void testLastIndexAppendedAcrossRestarts() throws Exception {
String path = OS.TARGET + "/deleteme.q-" + System.nanoTime();

long expectedIndex = 0;
for (int i = 0; i < 5; i++) {
try (SingleChronicleQueue queue = ChronicleQueueBuilder.single(path).build()) {
ExcerptAppender appender = queue.createAppender();

try (DocumentContext documentContext = appender.writingDocument()) {
long expectedIndex2 = documentContext.index();
assertTrue("expectedIndex: " + expectedIndex2, expectedIndex2 > 0);
if (expectedIndex == 0)
expectedIndex = expectedIndex2;
else
assertEquals(++expectedIndex, expectedIndex2);

documentContext.wire().write().text("hello world");
}
final long lastIndex = queue.nextIndexToWrite();
assertEquals(expectedIndex + 1, lastIndex);

assertEquals(expectedIndex, appender.lastIndexAppended());
}
}
try {
IOTools.deleteDirWithFiles(path, 2);
} catch (Exception index) {
}
}




--
You received this message because you are subscribed to the Google Groups "Chronicle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicl...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages