Tabnine Logo
RollCycle.toSequenceNumber
Code IndexAdd Tabnine to your IDE (free)

How to use
toSequenceNumber
method
in
net.openhft.chronicle.queue.RollCycle

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

origin: OpenHFT/Chronicle-Queue

@Override
public long toSequenceNumber(long index) {
  return delegate.toSequenceNumber(index);
}
origin: OpenHFT/Chronicle-Queue

void writeIndexForPosition(long index, long position)
    throws UnrecoverableTimeoutException, StreamCorruptedException {
  long sequenceNumber = queue.rollCycle().toSequenceNumber(index);
  store.setPositionForSequenceNumber(this, sequenceNumber, position);
}
origin: OpenHFT/Chronicle-Queue

boolean checkIndex(long index, long position) {
  try {
    final long seq1 = queue.rollCycle().toSequenceNumber(index + 1) - 1;
    final long seq2 = store.sequenceForPosition(this, position, true);
    if (seq1 != seq2) {
      final long seq3 = ((SingleChronicleQueueStore) store).indexing
          .linearScanByPosition(wireForIndex(), position, 0, 0, true);
      System.out.println("Thread=" + Thread.currentThread().getName() +
          " pos: " + position +
          " seq1: " + Long.toHexString(seq1) +
          " seq2: " + Long.toHexString(seq2) +
          " seq3: " + Long.toHexString(seq3));
      System.out.println(store.dump());
      assert seq1 == seq3 : "seq1=" + seq1 + ", seq3=" + seq3;
      assert seq1 == seq2 : "seq1=" + seq1 + ", seq2=" + seq2;
    }
  } catch (@NotNull EOFException | UnrecoverableTimeoutException | StreamCorruptedException e) {
    throw new AssertionError(e);
  }
  return true;
}
origin: OpenHFT/Chronicle-Queue

@NotNull
@Override
public String toString() {
  long index = index();
  return "StoreTailer{" +
      "index sequence=" + queue.rollCycle().toSequenceNumber(index) +
      ", index cycle=" + queue.rollCycle().toCycle(index) +
      ", store=" + store + ", queue=" + queue + '}';
}
origin: OpenHFT/Chronicle-Queue

private boolean inACycleCheckRep() {
  long lastSequenceAck = queue.lastAcknowledgedIndexReplicated();
  long seq = queue.rollCycle().toSequenceNumber(index());
  return seq > lastSequenceAck;
}
origin: OpenHFT/Chronicle-Queue

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

    boolean checkWritePositionHeaderNumber() {
      if (wire == null || wire.headerNumber() == Long.MIN_VALUE) return true;
      try {
        long pos = position;

        long seq1 = queue.rollCycle().toSequenceNumber(wire.headerNumber() + 1) - 1;
        long seq2 = store.sequenceForPosition(this, pos, true);

        if (seq1 != seq2) {
//                    System.out.println(queue.dump());
          String message = "~~~~~~~~~~~~~~ " +
              "thread: " + Thread.currentThread().getName() +
              " pos: " + pos +
              " header: " + wire.headerNumber() +
              " seq1: " + seq1 +
              " seq2: " + seq2;
          //System.err.println(message);
          new AssertionError(message).printStackTrace();
          throw new AssertionError(message);
        }

      } catch (Exception e) {
        Jvm.fatal().on(getClass(), e);
        throw Jvm.rethrow(e);
      }
      return true;
    }

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

@PackageLocal
void incrementIndex() {
  RollCycle rollCycle = queue.rollCycle();
  long index = this.index();
  long seq = rollCycle.toSequenceNumber(index);
  int cycle = rollCycle.toCycle(index);
  seq += direction.add();
  switch (direction) {
    case NONE:
      break;
    case FORWARD:
      // if it runs out of seq number it will flow over to tomorrows cycle file
      if (rollCycle.toSequenceNumber(seq) < seq) {
        cycle(cycle + 1);
        LOG.warn("we have run out of sequence numbers, so will start to write to " +
            "the next .cq4 file, the new cycle=" + cycle);
        seq = 0;
      }
      break;
    case BACKWARD:
      if (seq < 0) {
        windBackCycle(cycle);
        return;
      }
      break;
  }
  index0(rollCycle.toIndex(cycle, seq));
}
origin: OpenHFT/Chronicle-Queue

ScanResult moveToIndexResult(long index) {
  final int cycle = queue.rollCycle().toCycle(index);
  final long sequenceNumber = queue.rollCycle().toSequenceNumber(index);
  if (LOG.isTraceEnabled()) {
    Jvm.debug().on(getClass(), "moveToIndex: " + Long.toHexString(cycle) + " " + Long.toHexString(sequenceNumber));
  }
  if (cycle != this.cycle || state != FOUND_CYCLE) {
    // moves to the expected cycle
    if (!cycle(cycle))
      return ScanResult.NOT_REACHED;
  }
  index(index);
  ScanResult scanResult = this.store().moveToIndexForRead(this, sequenceNumber);
  Bytes<?> bytes = wire().bytes();
  if (scanResult == FOUND) {
    state = FOUND_CYCLE;
    moveToState.onSuccessfulLookup(index, direction, bytes.readPosition());
    return scanResult;
  } else if (scanResult == END_OF_FILE) {
    state = END_OF_CYCLE;
    return scanResult;
  } else if (scanResult == NOT_FOUND && this.cycle < this.queue.lastCycle) {
    state = END_OF_CYCLE;
    return END_OF_FILE;
  }
  return scanResult;
}
origin: OpenHFT/Chronicle-Queue

private long action(@NotNull final ExcerptTailer tailer1, @NotNull final RollCycle rollCycle) {
  //  tailer1.direction(direction);
  long readvalue = 0;
  long seqNumRead = 0;
  try (final DocumentContext dc = tailer1.readingDocument()) {
    readvalue = dc.wire().read("value").int64();
    seqNumRead = dc.index();
  }
  final long nextSeq = rollCycle.toSequenceNumber(tailer1.index());
  /*System.out.println("Return-value=" + readvalue +
      ", seq=" + rollCycle.toSequenceNumber(seqNumRead) +
      ", next-seq=" + nextSeq + "(" + Long.toHexString(nextSeq) + "x0)" + ",direction="
      + tailer1.direction());*/
  return readvalue;
}
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 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

private boolean inACycleNotForward() {
  Jvm.optionalSafepoint();
  if (!moveToIndexInternal(index())) {
    try {
      Jvm.optionalSafepoint();
      // after toEnd() call, index is past the end of the queue
      // so try to go back one (to the last record in the queue)
      if ((int) queue.rollCycle().toSequenceNumber(index()) < 0) {
        long lastSeqNum = store.lastSequenceNumber(this);
        if (lastSeqNum == -1) {
          windBackCycle(cycle);
          return moveToIndexInternal(index());
        }
        return moveToIndexInternal(queue.rollCycle().toIndex(cycle, lastSeqNum));
      }
      if (!moveToIndexInternal(index() - 1)) {
        Jvm.optionalSafepoint();
        return false;
      }
    } catch (Exception e) {
      // can happen if index goes negative
      Jvm.optionalSafepoint();
      return false;
    }
  }
  Jvm.optionalSafepoint();
  return true;
}
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

/**
 * 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 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

Assert.assertEquals(queue.rollCycle().toSequenceNumber(indexs[6]), 0);
Assert.assertEquals(5, queue.countExcerpts(indexs[0],
    indexs[6] - 1));
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)));
    }
  }
}
net.openhft.chronicle.queueRollCycletoSequenceNumber

Popular methods of RollCycle

  • current
  • length
  • toCycle
  • toIndex
  • defaultIndexCount
  • defaultIndexSpacing
  • format

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSystemService (Context)
  • getSupportFragmentManager (FragmentActivity)
  • addToBackStack (FragmentTransaction)
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • JList (javax.swing)
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • CodeWhisperer alternatives
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