private SCQIndexing(int indexCount, int indexSpacing, LongValue index2Index, LongValue nextEntryToBeIndexed, Supplier<LongArrayValues> longArraySupplier) { this.indexCount = indexCount; this.indexCountBits = Maths.intLog2(indexCount); this.indexSpacing = indexSpacing; this.indexSpacingBits = Maths.intLog2(indexSpacing); this.index2Index = index2Index; this.nextEntryToBeIndexed = nextEntryToBeIndexed; this.longArraySupplier = longArraySupplier; this.index2indexArray = new ThreadLocal<>(); this.indexArray = new ThreadLocal<>(); this.index2IndexTemplate = w -> w.writeEventName(() -> "index2index").int64array(indexCount); this.indexTemplate = w -> w.writeEventName(() -> "index").int64array(indexCount); }
@Test public void shouldReadBackwardFromEndOfQueueWhenDirectionIsSetAfterMoveToEnd() { try (final ChronicleQueue queue = builder(getTmpDir(), this.wireType) .rollCycle(TEST2_DAILY) .build()) { final ExcerptAppender appender = queue.acquireAppender(); appender.writeDocument(w -> w.writeEventName("hello").text("world")); final ExcerptTailer tailer = queue.createTailer(); tailer.toEnd(); tailer.direction(TailerDirection.BACKWARD); assertThat(tailer.readingDocument().isPresent(), is(true)); } }
appender.writeDocument(w -> w.writeEventName("hello").text("world"));
@Test public void testMoveToWithAppender() { try (ChronicleQueue syncQ = builder(getTmpDir(), this.wireType) .build()) { InternalAppender sync = (InternalAppender) syncQ.acquireAppender(); File name2 = DirectoryUtils.tempDir(testName.getMethodName()); try (ChronicleQueue chronicle = builder(name2, this.wireType) .build()) { ExcerptAppender appender = chronicle.acquireAppender(); appender.writeDocument(w -> w.writeEventName("hello").text("world0")); appender.writeDocument(w -> w.writeEventName("hello").text("world1")); appender.writeDocument(w -> w.writeEventName("hello").text("world2")); ExcerptTailer tailer = chronicle.createTailer(); try (DocumentContext documentContext = tailer.readingDocument()) { sync.writeBytes(documentContext.index(), documentContext.wire().bytes()); } try (DocumentContext documentContext = tailer.readingDocument()) { String text = documentContext.wire().read().text(); Assert.assertEquals("world1", text); } } } }
@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()); } }
@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); } } }
@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)); } } }
@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))); } } }
@Override public void writeMarshallable(@NotNull WireOut wire) { for (@NotNull Entry<String, EngineCluster> entry : clusterMap.entrySet()) wire.writeEventName(entry::getKey).marshallable(entry.getValue()); }
@Override public void writeMarshallable(@NotNull WireOut wire) { for (@NotNull Entry<String, MountPoint> entry : mounts.entrySet()) wire.writeEventName(entry::getKey).typedMarshallable(entry.getValue()); }
@NotNull public static WriteMarshallable newMapReplicationHandler(long lastUpdateTime, @NotNull Class keyType, @NotNull Class valueType, String csp, long cid) { @NotNull final MapReplicationHandler h = new MapReplicationHandler (lastUpdateTime, keyType, valueType); return w -> w.writeDocument(true, d -> d.writeEventName(CoreFields.csp).text(csp) .writeEventName(CoreFields.cid).int64(cid) .writeEventName(CoreFields.handler).typedMarshallable(h)); }
@Override public void onSubscribe(@NotNull final WireOut wireOut) { subscribersToTid.put(subscriber, tid()); wireOut.writeEventName(registerSubscriber).text(""); }
@Override public void onSubscribe(@NotNull final WireOut wireOut) { subscribersToTid.put(subscriber, tid()); wireOut.writeEventName(registerSubscriber).text(""); }
private static WriteMarshallable heartbeatHandler(final long heartbeatTimeoutMs, final long heartbeatIntervalMs, final long cid) { return w -> w.writeDocument(true, d -> d.writeEventName(CoreFields.csp).text("/") .writeEventName(CoreFields.cid).int64(cid) .writeEventName(CoreFields.handler).typedMarshallable(new HeartbeatHandler(heartbeatTimeoutMs, heartbeatIntervalMs))); }
public long set(@NotNull M event) { if (isReplicating && !isSource) throw new IllegalStateException("You can not publish to a sink used in replication, " + "you have to publish to the source"); @NotNull final ExcerptAppender excerptAppender = threadLocalAppender(); excerptAppender.writeDocument(w -> w.writeEventName(() -> "").object(event)); return excerptAppender.lastIndexAppended(); }
@Override public void onSubscribe(@NotNull final WireOut wireOut) { wireOut.writeEventName(registerSubscriber). typeLiteral(CLASS_ALIASES.nameFor(rc.elementType())); if (!filter.isEmpty()) wireOut.writeEventName(() -> "filter").object(filter); }
@Override public long createProxy(String type, long token) { createProxy0(type, cspBuff); cspBuff.append("&token=" + token); final long cid = acquireCid(cspBuff); outWire.writeEventName(reply).typePrefix("set-proxy") .marshallable(w -> { w.writeEventName(CoreFields.csp).text(cspBuff); w.writeEventName(CoreFields.cid).int64(cid); }); return cid; }
@Override public void onSubscribe(@NotNull WireOut wireOut) { if (LOG.isDebugEnabled()) Jvm.debug().on(getClass(), "onSubscribe - localIdentifier=" + localIdentifier + "," + "remoteIdentifier=" + remoteIdentifier); wireOut.writeEventName(identifier) .marshallable(WriteMarshallable.EMPTY) .writeComment(toString() + ", tcpChannelHub={" + hub.toString() + "}"); }
@Override public long createProxy(final String type) { createProxy0(type, cspBuff); final long cid = acquireCid(cspBuff); outWire.writeEventName(reply).typePrefix("set-proxy") .marshallable(w -> { w.writeEventName(CoreFields.csp).text(cspBuff); w.writeEventName(CoreFields.cid).int64(cid); }); return cid; }
@Override public void onSubscribe(@NotNull final WireOut wireOut) { subscribersToTid.put(subscriber, tid()); wireOut.writeEventName(registerTopicSubscriber).marshallable(m -> { m.write(() -> "keyType").typeLiteral(kClass); m.write(() -> "valueType").typeLiteral(vClass); if (rc.bootstrap() != null) m.writeEventName(() -> "bootstrap").bool(rc.bootstrap()); }); }