congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ChronicleQueue.rollCycle
Code IndexAdd Tabnine to your IDE (free)

How to use
rollCycle
method
in
net.openhft.chronicle.queue.ChronicleQueue

Best Java code snippets using net.openhft.chronicle.queue.ChronicleQueue.rollCycle (Showing top 20 results out of 315)

origin: OpenHFT/Chronicle-Queue

private boolean indexIsCloseToAndAheadOfLastIndexMove(
    final long index, final TailerState state, final TailerDirection direction,
    final ChronicleQueue queue) {
  return lastMovedToIndex != Long.MIN_VALUE &&
      index - lastMovedToIndex < INDEXING_LINEAR_SCAN_THRESHOLD &&
      state == FOUND_CYCLE &&
      direction == directionAtLastMoveTo &&
      queue.rollCycle().toCycle(index) == queue.rollCycle().toCycle(lastMovedToIndex) &&
      index > lastMovedToIndex;
}
origin: OpenHFT/Chronicle-Queue

private boolean canReuseLastIndexMove(
    final long index, final TailerState state, final TailerDirection direction,
    final ChronicleQueue queue, final Wire wire) {
  return ((wire == null) || wire.bytes().readPosition() == readPositionAtLastMove) &&
      index == this.lastMovedToIndex && index != 0 && state == FOUND_CYCLE &&
      direction == directionAtLastMoveTo &&
      queue.rollCycle().toCycle(index) == queue.rollCycle().toCycle(lastMovedToIndex);
}
origin: OpenHFT/Chronicle-Queue

private static long findCycleLinearSearch(@NotNull NavigableSet<Long> cycles, Wire key,
                     @NotNull Comparator<Wire> c,
                     @NotNull ExcerptTailer tailer,
                     @NotNull final ChronicleQueue queue) {
  final Iterator<Long> iterator = cycles.iterator();
  if (!iterator.hasNext())
    return -1;
  final RollCycle rollCycle = queue.rollCycle();
  long prevIndex = iterator.next();
  while (iterator.hasNext()) {
    final Long current = iterator.next();
    final boolean b = tailer.moveToIndex(rollCycle.toIndex((int) (long) current, 0));
    if (!b)
      return prevIndex;
    try (final DocumentContext dc = tailer.readingDocument()) {
      final int compare = c.compare(dc.wire(), key);
      if (compare == 0)
        return current;
      else if (compare > 0)
        return prevIndex;
      prevIndex = current;
    }
  }
  return prevIndex;
}
origin: OpenHFT/Chronicle-Queue

@NotNull
private String toTextIndex(ChronicleQueue q, long index) {
  return Long.toHexString(q.rollCycle().toCycle(index)) + "_" + Long.toHexString(q.rollCycle().toSequenceNumber(index));
}
origin: OpenHFT/Chronicle-Queue

private long toSeq(final ChronicleQueue q, final long index) {
  return q.rollCycle().toSequenceNumber(index);
}
origin: OpenHFT/Chronicle-Queue

@Ignore("long running test")
@Test
public void testReadAtIndex4MB() {
  try (final ChronicleQueue queue = SingleChronicleQueueBuilder.builder(getTmpDir(), this.wireType).rollCycle(SMALL_DAILY)
      .build()) {
    final ExcerptAppender appender = queue.acquireAppender();
    System.out.print("Percent written=");
    for (long i = 0; i < TIMES; i++) {
      final long j = i;
      appender.writeDocument(wire -> wire.write(() -> "key").text("value=" + j));
      if (i % (TIMES / 20) == 0) {
        System.out.println("" + (i * 100 / TIMES) + "%, ");
      }
    }
    long lastIndex = appender.lastIndexAppended();
    final int cycle = queue.rollCycle().toCycle(lastIndex);
    final ExcerptTailer tailer = queue.createTailer();
    //   QueueDumpMain.dump(file, new PrintWriter(System.out));
    StringBuilder sb = new StringBuilder();
    for (long i = 0; i < (4L << 20L); i++) {
      assertTrue(tailer.moveToIndex(queue.rollCycle().toIndex(cycle, i)));
      tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
      Assert.assertEquals("value=" + i, sb.toString());
      if (i % (TIMES / 20) == 0) {
        System.out.println("Percent read= " + (i * 100 / TIMES) + "%");
      }
    }
  }
}
origin: OpenHFT/Chronicle-Queue

@Test
public void testAppendAndReadAtIndex() {
  try (final ChronicleQueue queue = builder(getTmpDir(), this.wireType)
      .rollCycle(TEST2_DAILY)
      .build()) {
    final ExcerptAppender appender = queue.acquireAppender();
    appender.cycle();
    for (int i = 0; i < 5; i++) {
      final int n = i;
      appender.writeDocument(w -> w.write(TestKey.test).int32(n));
      assertEquals(i, queue.rollCycle().toSequenceNumber(appender.lastIndexAppended()));
    }
    final ExcerptTailer tailer = queue.createTailer();
    for (int i = 0; i < 5; i++) {
      final long index = queue.rollCycle().toIndex(appender.cycle(), i);
      assertTrue(tailer.moveToIndex(index));
      final int n = i;
      assertTrue(tailer.readDocument(r -> assertEquals(n, queue.rollCycle().toSequenceNumber(r.read(TestKey.test)
          .int32()))));
      long index2 = tailer.index();
      long sequenceNumber = queue.rollCycle().toSequenceNumber(index2);
      assertEquals(n + 1, sequenceNumber);
    }
  }
}
origin: OpenHFT/Chronicle-Queue

@Test
public void testAppend() {
  try (final ChronicleQueue queue =
         builder(getTmpDir(), wireType)
             .build()) {
    final ExcerptAppender appender = queue.acquireAppender();
    for (int i = 0; i < 10; i++) {
      final int n = i;
      appender.writeDocument(w -> w.write(TestKey.test).int32(n));
      assertEquals(n, queue.rollCycle().toSequenceNumber(appender.lastIndexAppended()));
    }
    assertThat(countEntries(queue), is(10L));
  }
}
origin: OpenHFT/Chronicle-Queue

Assert.assertEquals(0, chronicle.rollCycle().toSequenceNumber(index));
dc.wire().write(() -> "FirstName").text("Quartilla");
Assert.assertEquals(1, chronicle.rollCycle().toSequenceNumber(dc.index()));
dc.wire().write(() -> "FirstName").text("Rob");
Assert.assertEquals(2, chronicle.rollCycle().toSequenceNumber(dc.index()));
dc.wire().write(() -> "FirstName").text("Rob");
Assert.assertEquals(0, chronicle.rollCycle().toSequenceNumber(index));
Assert.assertEquals(1, chronicle.rollCycle().toSequenceNumber(dc.index()));
Assert.assertEquals(2, chronicle.rollCycle().toSequenceNumber(dc.index()));
origin: OpenHFT/Chronicle-Queue

@Test
public void testHeaderIndexReadAtIndex() {
  try (final ChronicleQueue queue = builder(getTmpDir(), this.wireType)
      .build()) {
    final ExcerptAppender appender = queue.acquireAppender();
    final int cycle = appender.cycle();
    // create 100 documents
    for (int i = 0; i < 100; i++) {
      final int j = i;
      appender.writeDocument(wire -> wire.write(() -> "key").text("value=" + j));
    }
    final ExcerptTailer tailer = queue.createTailer();
    assertTrue(tailer.moveToIndex(queue.rollCycle().toIndex(cycle, 0)));
    StringBuilder sb = new StringBuilder();
    tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
    Assert.assertEquals("value=0", sb.toString());
  }
}
origin: OpenHFT/Chronicle-Queue

@Test
public void testIndex() {
  try (final ChronicleQueue queue = builder(getTmpDir(), this.wireType)
      .rollCycle(RollCycles.HOURLY)
      .build()) {
    final ExcerptAppender appender = queue.acquireAppender();
    int cycle = appender.cycle();
    // create 100 documents
    for (int i = 0; i < 5; i++) {
      final int j = i;
      appender.writeDocument(wire -> wire.write(() -> "key").text("value=" + j));
      if (i == 2) {
        final long cycle1 = queue.rollCycle().toCycle(appender.lastIndexAppended());
        Assert.assertEquals(cycle1, cycle);
      }
    }
    final ExcerptTailer tailer = queue.createTailer();
    assertTrue(tailer.moveToIndex(queue.rollCycle().toIndex(cycle, 2)));
    StringBuilder sb = new StringBuilder();
    tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
    Assert.assertEquals("value=2", sb.toString());
    tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
    Assert.assertEquals("value=3", sb.toString());
    tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
    Assert.assertEquals("value=4", sb.toString());
  }
}
origin: OpenHFT/Chronicle-Queue

@Test
public void testLastWrittenIndexPerAppender() {
  try (final ChronicleQueue queue = builder(getTmpDir(), this.wireType)
      .build()) {
    final ExcerptAppender appender = queue.acquireAppender();
    appender.writeDocument(wire -> wire.write(() -> "key").text("test"));
    Assert.assertEquals(0, queue.rollCycle().toSequenceNumber(appender.lastIndexAppended()));
  }
}
origin: OpenHFT/Chronicle-Queue

@Test
public void testSomeMessages() {
  try (ChronicleQueue chronicle = builder(getTmpDir(), wireType)
      .rollCycle(TEST2_DAILY)
      .build()) {
    ExcerptAppender appender = chronicle.acquireAppender();
    ExcerptTailer tailer = chronicle.createTailer();
    int entries = chronicle.rollCycle().defaultIndexSpacing() * 2 + 2;
    for (long i = 0; i < entries; i++) {
      long finalI = i;
      appender.writeDocument(w -> w.writeEventName("hello").int64(finalI));
      long seq = chronicle.rollCycle().toSequenceNumber(appender.lastIndexAppended());
      assertEquals(i, seq);
      //      System.out.println(chronicle.dump());
      tailer.readDocument(w -> w.read().int64(finalI, (a, b) -> Assert.assertEquals((long) a, b)));
    }
  }
}
origin: OpenHFT/Chronicle-Queue

@Test
public void testAppendAndRead() {
  try (final ChronicleQueue queue = builder(getTmpDir(), this.wireType)
      .build()) {
    final ExcerptAppender appender = queue.acquireAppender();
    final int cycle = appender.cycle();
    for (int i = 0; i < 10; i++) {
      final int n = i;
      appender.writeDocument(w -> w.write(TestKey.test).int32(n));
      assertEquals(n, queue.rollCycle().toSequenceNumber(appender.lastIndexAppended()));
    }
    final ExcerptTailer tailer = queue.createTailer();
    // Sequential read
    for (int i = 0; i < 10; i++) {
      final int n = i;
      assertTrue(tailer.readDocument(r -> assertEquals(n, r.read(TestKey.test).int32())));
      assertEquals(n + 1, queue.rollCycle().toSequenceNumber(tailer.index()));
    }
    // Random read
    for (int i = 0; i < 10; i++) {
      final int n = i;
      assertTrue("n: " + n, tailer.moveToIndex(queue.rollCycle().toIndex(cycle, n)));
      assertTrue("n: " + n, tailer.readDocument(r -> assertEquals(n, r.read(TestKey.test).int32())));
      assertEquals(n + 1, queue.rollCycle().toSequenceNumber(tailer.index()));
    }
  }
}
origin: OpenHFT/Chronicle-Queue

/**
 * if one appender if much further ahead than the other, then the new append should jump
 * straight to the end rather than attempting to write a positions that are already occupied
 */
@Test
public void testAppendedSkipToEnd() {
  try (ChronicleQueue q = builder(getTmpDir(), this.wireType)
      .build()) {
    ExcerptAppender appender = q.acquireAppender();
    ExcerptAppender appender2 = q.acquireAppender();
    int indexCount = 100;
    for (int i = 0; i < indexCount; i++) {
      try (DocumentContext dc = appender.writingDocument()) {
        dc.wire().write("key").text("some more " + 1);
        Assert.assertEquals(i, q.rollCycle().toSequenceNumber(dc.index()));
      }
    }
    try (DocumentContext dc = appender2.writingDocument()) {
      dc.wire().write("key").text("some data " + indexCount);
      Assert.assertEquals(indexCount, q.rollCycle().toSequenceNumber(dc.index()));
    }
  }
}
origin: OpenHFT/Chronicle-Queue

@Test
public void testForwardFollowedBackBackwardTailer() {
  try (ChronicleQueue chronicle = builder(getTmpDir(), this.wireType)
      .rollCycle(TEST2_DAILY)
      .build()) {
    ExcerptAppender appender = chronicle.acquireAppender();
    int entries = chronicle.rollCycle().defaultIndexSpacing() + 2;
    for (int i = 0; i < entries; i++) {
      int finalI = i;
      appender.writeDocument(w -> w.writeEventName("hello").text("world" + finalI));
    }
    for (int i = 0; i < 3; i++) {
      readForward(chronicle, entries);
      readBackward(chronicle, entries);
    }
  }
}
origin: OpenHFT/Chronicle-Queue

assertEquals(10, queue.rollCycle().toSequenceNumber(atEnd.index()));
checkOneFile(baseDir);
fillResults(atEnd, results);
origin: OpenHFT/Chronicle-Queue

@Test
public void shouldNotBlowUpIfTryingToCreateQueueWithIncorrectRollCycle() {
  File tmpDir = getTmpDir();
  try (final ChronicleQueue queue = builder(tmpDir, wireType).rollCycle(DAILY).build()) {
    try (DocumentContext documentContext = queue.acquireAppender().writingDocument()) {
      documentContext.wire().write("somekey").text("somevalue");
    }
  }
  // we don't store which RollCycles enum was used and we try and match by format string, we
  // match the first RollCycles with the same format string, which may not
  // be the RollCycles it was written with
  try (final ChronicleQueue ignored = builder(tmpDir, wireType).rollCycle(HOURLY).build()) {
    assertEquals(TEST_DAILY, ignored.rollCycle());
  }
}
origin: OpenHFT/Chronicle-Queue

@Test
public void testToEndBeforeWrite() {
  try (ChronicleQueue chronicle = builder(getTmpDir(), wireType)
      .rollCycle(TEST2_DAILY)
      .build()) {
    ExcerptAppender appender = chronicle.acquireAppender();
    ExcerptTailer tailer = chronicle.createTailer();
    int entries = chronicle.rollCycle().defaultIndexSpacing() * 2 + 2;
    for (int i = 0; i < entries; i++) {
      tailer.toEnd();
      int finalI = i;
      appender.writeDocument(w -> w.writeEventName("hello").text("world" + finalI));
      tailer.readDocument(w -> w.read().text("world" + finalI, Assert::assertEquals));
    }
  }
}
origin: OpenHFT/Chronicle-Queue

try (DocumentContext dc = appender.writingDocument()) {
  dc.wire().getValueOut().text("hi-" + i);
  lastCycle = wqueue.rollCycle().toCycle(dc.index());
net.openhft.chronicle.queueChronicleQueuerollCycle

Popular methods of ChronicleQueue

  • createTailer
    Tailers are NOT thread-safe, sharing the Tailer between threads will lead to errors and unpredictab
  • acquireAppender
    An Appender can be used to writeBytes new excerpts sequentially to the upper. Appenders are NOT t
  • close
  • dump
  • firstIndex
  • createAppender
  • file
  • fileAbsolutePath
    Cache this value as getAbsolutePath is expensive
  • single
  • singleBuilder
  • isClosed
  • lastAcknowledgedIndexReplicated
  • isClosed,
  • lastAcknowledgedIndexReplicated,
  • methodWriter,
  • methodWriterBuilder,
  • refreshDirectlyListing,
  • wireType

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSystemService (Context)
  • setScale (BigDecimal)
  • getResourceAsStream (ClassLoader)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now