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

How to use
ExcerptAppender
in
net.openhft.chronicle.queue

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

origin: OpenHFT/Chronicle-Queue

@Test
public void testLastIndexAppended() {
  try (ChronicleQueue chronicle = builder(getTmpDir(), this.wireType)
      .build()) {
    ExcerptAppender appender = chronicle.acquireAppender();
    appender.writeDocument(w -> w.writeEventName("hello").text("world0"));
    final long nextIndexToWrite = appender.lastIndexAppended() + 1;
    appender.writeDocument(w -> w.getValueOut().bytes(new byte[0]));
    //            System.out.println(chronicle.dump());
    Assert.assertEquals(nextIndexToWrite,
        appender.lastIndexAppended());
  }
}
origin: OpenHFT/Chronicle-Queue

public void appendMessage(@NotNull ChronicleQueue queue, long expectedIndex, String msg) {
  @NotNull ExcerptAppender appender = queue.acquireAppender();
  switch (appendMode) {
    case 1:
      appender.writeDocument(w -> w.write(() -> "msg").text(msg));
      break;
    case 2:
      Bytes bytes = Bytes.elasticByteBuffer();
      new BinaryWire(bytes).write(() -> "msg").text(msg);
      appender.writeBytes(bytes);
      bytes.release();
      break;
    default:
      try (DocumentContext dc = appender.writingDocument()) {
        Wire wire = dc.wire();
        wire.write(() -> "msg").text(msg);
      }
      break;
  }
  long index = appender.lastIndexAppended();
  assertHexEquals(expectedIndex, index);
}
origin: OpenHFT/Chronicle-Queue

  Thread thread = Thread.currentThread();
  while (!thread.isInterrupted()) {
    appender.pretouch();
    Jvm.pause(10);
while (end > System.nanoTime()) {
  long start = System.nanoTime();
  try (DocumentContext dc = appender.writingDocument(false)) {
    writeMessage(dc.wire(), messageSize);
origin: OpenHFT/Chronicle-Queue

  private void write(@NotNull ChronicleQueue aChronicle, int messages) {
    final ExcerptAppender myAppender = aChronicle.acquireAppender();
    for (int myCount = 0; myCount < messages; myCount++) {
      myAppender.writeDocument(aMarshallable -> aMarshallable.write().bytes(Long.toString(currentTimeMillis()).getBytes(StandardCharsets.UTF_8)));
//            System.out.println(Long.toHexString(myAppender.lastIndexAppended()));
    }
  }
}
origin: OpenHFT/Chronicle-Queue

private static void write(final ExcerptAppender appender, final Data data) throws Exception {
  try (final DocumentContext dc = appender.writingDocument()) {
    final ObjectOutput out = dc.wire().objectOutput();
    out.writeInt(data.id);
  }
}
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 testMultipleAppenders() {
  try (ChronicleQueue syncQ = builder(getTmpDir(), this.wireType)
      .rollCycle(TEST_DAILY)
      .build()) {
    ExcerptAppender syncA = syncQ.acquireAppender();
    assumeFalse(syncA.padToCacheAlignMode() == WORD);
    ExcerptAppender syncB = syncQ.acquireAppender();
    ExcerptAppender syncC = syncQ.acquireAppender();
    int count = 0;
    for (int i = 0; i < 3; i++) {
      syncA.writeText("hello A" + i);
      assertEquals(count++, (int) syncA.lastIndexAppended());
      syncB.writeText("hello B" + i);
      assertEquals(count++, (int) syncB.lastIndexAppended());
      try (DocumentContext dc = syncC.writingDocument(true)) {
        dc.wire().getValueOut().text("some meta " + i);
      }
    }
    String expected = expectedMultipleAppenders();
    assertEquals(expected, syncQ.dump());
  }
}
origin: OpenHFT/Chronicle-Queue

default void writeBytes(@NotNull Bytes bytes) throws UnrecoverableTimeoutException {
  writeBytes((BytesStore) bytes);
}
origin: OpenHFT/Chronicle-Queue

@Test
public void shouldIndicateNoProcessIdWhenDocumentIsComplete() throws IOException {
  try (final RollingChronicleQueue queue = ChronicleQueue.singleBuilder(getTmpDir()).
      testBlockSize().
      build()) {
    final QueueInspector inspector = new QueueInspector(queue);
    final ExcerptAppender appender = queue.acquireAppender();
    appender.writeDocument(37L, ValueOut::int64);
    try (final DocumentContext ctx = appender.writingDocument()) {
      ctx.wire().write("foo").int32(17L);
    }
    final int writingThreadId = inspector.getWritingThreadId();
    assertThat(writingThreadId, is(not(OS.getProcessId())));
    assertThat(QueueInspector.isValidThreadId(writingThreadId), is(false));
  }
}
origin: OpenHFT/Chronicle-Queue

@Test
public void testIndexWritingDocument() {
  try (final ChronicleQueue chronicle = builder(getTmpDir(), this.wireType)
      .build()) {
    final ExcerptAppender appender = chronicle.acquireAppender();
    long index;
    try (DocumentContext dc = appender.writingDocument()) {
      dc.wire().write(() -> "FirstName").text("Quartilla");
      index = dc.index();
    }
    try (DocumentContext dc = appender.writingDocument(true)) {
      dc.wire().write(() -> "FirstName").text("Quartilla");
    }
    Assert.assertEquals(index, appender.lastIndexAppended());
  }
}
origin: OpenHFT/Chronicle-Queue

Wire wire;
try (DocumentContext dc = appender.writingDocument()) {
  wire = dc.wire();
  wire.write().text("hello world");
File dir = new File(appender.queue().fileAbsolutePath());
files = dir.listFiles(pathname -> pathname.getAbsolutePath().endsWith(".cq4"));
appender.writeText("hello world  2");
ExcerptTailer excerptTailer = q.createTailer().toEnd();
q.acquireAppender()
    .writeText(EXPECTED);
Assert.assertEquals(EXPECTED, excerptTailer.readText());
origin: OpenHFT/Chronicle-Queue

/**
 * test that if we make EPOC the current time, then the cycle is == 0
 *
 * @
 */
@Test
public void testEPOC() {
  try (final ChronicleQueue chronicle = builder(getTmpDir(), this.wireType)
      .epoch(System.currentTimeMillis())
      .rollCycle(RollCycles.HOURLY)
      .build()) {
    final ExcerptAppender appender = chronicle.acquireAppender();
    appender.writeDocument(wire -> wire.write(() -> "key").text("value=v"));
    Assert.assertTrue(appender.cycle() == 0);
  }
}
origin: OpenHFT/Chronicle-Queue

@NotNull
public JDBCStatement createWriter() {
  return in.acquireAppender()
      .methodWriterBuilder(JDBCStatement.class)
      .recordHistory(true)
      .get();
}
origin: OpenHFT/Chronicle-Queue

@Before
public void setup() {
  chroniclePath = new File(OS.TARGET, "read_only");
  try (ChronicleQueue readWrite = ChronicleQueue.singleBuilder(chroniclePath)
      .readOnly(false)
      .testBlockSize()
      .build()) {
    final ExcerptAppender appender = readWrite.acquireAppender();
    appender.writeText(STR1);
    try (DocumentContext dc = appender.writingDocument()) {
      dc.wire().bytes().writeUtf8(STR2);
    }
  }
}
origin: OpenHFT/Chronicle-Queue

    .methodWriterBuilder(Msg.class)
    .recordHistory(true)
    .build();
      .methodWriterBuilder(Msg.class)
      .recordHistory(true)
      .build();
msg.msg("somedata-4");
try (DocumentContext dc = outQueue.acquireAppender().writingDocument(true)) {
  dc.wire().write("some metadata");
origin: OpenHFT/Chronicle-Queue

public static void main(String[] args) {
  SingleChronicleQueue outQueue = SingleChronicleQueueBuilder.binary("target/" + "monitor")
      .rollCycle(RollCycles.TEST_SECONDLY).build();
  ExcerptAppender outQueueAppender = outQueue.acquireAppender();
  HeartbeatListener heartbeatWriter = outQueueAppender.methodWriterBuilder(HeartbeatListener.class).methodWriterListener((m, a) -> validateAll(a)).recordHistory(true).build();
  Monitor.addPeriodicUpdateSource(10, () -> currentTimeMillis -> {
    outQueueAppender.pretouch();
  });
  long lastHB = 0;
  while (true) {
    if (System.currentTimeMillis() - lastHB > 1) {
      // write a hb to the queue
      MessageHistory.get().reset();
      Heartbeat heartBeat = new Heartbeat(UUID.randomUUID().toString());
      heartbeatWriter.heartbeat(heartBeat);
      lastHB = System.currentTimeMillis();
    }
  }
}
origin: OpenHFT/Chronicle-Queue

  @Override
  public Throwable call() throws Exception {
    ChronicleQueue queue0 = null;
    try (ChronicleQueue queue = queueBuilder(path).build()) {
      queue0 = queue;
      ExcerptAppender appender = queue.acquireAppender();
      System.out.println("Starting pretoucher");
      while (!Thread.currentThread().isInterrupted() && !queue.isClosed()) {
        Jvm.pause(50);
        appender.pretouch();
      }
    } catch (Throwable e) {
      if (queue0 != null && queue0.isClosed())
        return null;
      exception = e;
      return e;
    }
    return null;
  }
}
origin: OpenHFT/Chronicle-Queue

PingDTO pdtio = new PingDTO();
PingDTO.constructionExpected++;
Pinger pinger = cq.acquireAppender().methodWriter(Pinger.class);
for (int i = 0; i < 5; i++) {
  pinger.ping(pdtio);
origin: OpenHFT/Chronicle-Queue

@Test(expected = IllegalStateException.class) //: no messages written
public void testNoMessagesWritten() {
  try (final ChronicleQueue chronicle = builder(getTmpDir(), this.wireType)
      .build()) {
    final ExcerptAppender appender = chronicle.acquireAppender();
    appender.lastIndexAppended();
  }
}
origin: OpenHFT/Chronicle-Queue

@NotNull
default <T> T methodWriter(@NotNull Class<T> tClass, Class... additional) {
  return queue().methodWriter(tClass, additional);
}
net.openhft.chronicle.queueExcerptAppender

Javadoc

The component that facilitates sequentially writing data to a ChronicleQueue.

NOTE: Appenders are NOT thread-safe, sharing the Appender between threads will lead to errors and unpredictable behaviour.

Most used methods

  • writeDocument
  • writingDocument
  • lastIndexAppended
  • pretouch
    We suggest this code is called from a background thread [ not you main business thread ], it must be
  • writeBytes
  • methodWriter
  • methodWriterBuilder
  • queue
  • batchAppend
  • cycle
  • getCloserJob
    A task that will be run if a WeakReference referring this appender is registered with a clean-up tas
  • padToCacheAlignMode
  • getCloserJob,
  • padToCacheAlignMode,
  • wire,
  • writeMap,
  • writeMessage,
  • writeText

Popular in Java

  • Running tasks concurrently on multiple threads
  • onCreateOptionsMenu (Activity)
  • findViewById (Activity)
  • setScale (BigDecimal)
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • JTable (javax.swing)
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Best IntelliJ plugins
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