@NotNull private LongArrayValues array(@NotNull WireIn w, @NotNull LongArrayValues using, boolean index2index) { final StringBuilder sb = Wires.acquireStringBuilder(); @NotNull final ValueIn valueIn = w.readEventName(sb); String name = index2index ? "index2index" : "index"; if (!name.contentEquals(sb)) throw new IllegalStateException("expecting index, was " + sb); valueIn.int64array(using, this, (o1, o2) -> { }); return using; }
@Override public synchronized Integer call() throws Exception { try (final DocumentContext dc = tailer.readingDocument()) { System.out.println("index=" + Long.toHexString(dc.index())); if (!dc.isPresent()) return documentsRead; StringBuilder sb = Wires.acquireStringBuilder(); dc.wire().bytes().parse8bit(sb, StopCharTesters.ALL); String readText = sb.toString(); if (java.util.Objects.equals(readText, "")) { return documentsRead; } System.out.println("Read a document " + readText); documentsRead++; } return documentsRead; } }
wire.readFirstHeader(timeoutMS, TimeUnit.MILLISECONDS); StringBuilder name = Wires.acquireStringBuilder(); ValueIn valueIn = wire.readEventName(name); if (StringUtils.isEqual(name, MetaDataKeys.header.name())) {
void readForward(@NotNull ChronicleQueue chronicle, int entries) { ExcerptTailer forwardTailer = chronicle.createTailer() .direction(TailerDirection.FORWARD) .toStart(); for (int i = 0; i < entries; i++) { try (DocumentContext documentContext = forwardTailer.readingDocument()) { Assert.assertTrue(documentContext.isPresent()); Assert.assertEquals(i, RollCycles.DAILY.toSequenceNumber(documentContext.index())); StringBuilder sb = Wires.acquireStringBuilder(); ValueIn valueIn = documentContext.wire().readEventName(sb); Assert.assertTrue("hello".contentEquals(sb)); String actual = valueIn.text(); Assert.assertEquals("world" + i, actual); } } try (DocumentContext documentContext = forwardTailer.readingDocument()) { Assert.assertFalse(documentContext.isPresent()); } }
void readBackward(@NotNull ChronicleQueue chronicle, int entries) { ExcerptTailer backwardTailer = chronicle.createTailer() .direction(TailerDirection.BACKWARD) .toEnd(); for (int i = entries - 1; i >= 0; i--) { try (DocumentContext documentContext = backwardTailer.readingDocument()) { assertTrue(documentContext.isPresent()); final long index = documentContext.index(); assertEquals("index: " + index, i, (int) index); Assert.assertEquals(i, RollCycles.DAILY.toSequenceNumber(index)); Assert.assertTrue(documentContext.isPresent()); StringBuilder sb = Wires.acquireStringBuilder(); ValueIn valueIn = documentContext.wire().readEventName(sb); Assert.assertTrue("hello".contentEquals(sb)); String actual = valueIn.text(); Assert.assertEquals("world" + i, actual); } } try (DocumentContext documentContext = backwardTailer.readingDocument()) { assertFalse(documentContext.isPresent()); } }
StringBuilder sb = Wires.acquireStringBuilder(); mappedBytes.reserve(); try {
final StringBuilder sb = Wires.acquireStringBuilder();
assertTrue(tailer.moveToIndex(queue.rollCycle().toIndex(cycle, 2))); final StringBuilder sb = Wires.acquireStringBuilder();
assertTrue(tailer.moveToIndex(queue.rollCycle().toIndex(cycle, 2))); final StringBuilder sb = Wires.acquireStringBuilder();
StringBuilder sb = Wires.acquireStringBuilder(); try (DocumentContext documentContext = tailer1.readingDocument()) { documentContext.wire().readEventName(sb);
@NotNull private LongArrayValues array(@NotNull WireIn w, @NotNull LongArrayValues using, boolean index2index) { final StringBuilder sb = Wires.acquireStringBuilder(); @NotNull final ValueIn valueIn = w.readEventName(sb); String name = index2index ? "index2index" : "index"; if (!name.contentEquals(sb)) throw new IllegalStateException("expecting index, was " + sb); valueIn.int64array(using, this, (o1, o2) -> { }); return using; }
/** * @param consumer a consumer that provides that name of the event and value contained within * the except */ public void getExcerpt(@NotNull BiConsumer<CharSequence, M> consumer) { @NotNull final ExcerptTailer tailer = threadLocalTailer(); tailer.readDocument(w -> { final StringBuilder eventName = Wires.acquireStringBuilder(); @NotNull final ValueIn valueIn = w.readEventName(eventName); consumer.accept(eventName, valueIn.object(elementTypeClass)); }); }
@NotNull private static String toUri(@NotNull final RequestContext context) { StringBuilder sb = Wires.acquireStringBuilder(); sb.append(context.fullName()).append("?view=subscription"); if (context.messageType() != String.class) sb.append("&messageType=").append(CLASS_ALIASES.nameFor(context.messageType())); if (context.elementType() != String.class) sb.append("&elementType=").append(CLASS_ALIASES.nameFor(context.elementType())); return sb.toString(); }
@Override public void readMarshallable(@NotNull WireIn wire) throws IllegalStateException { StringBuilder clusterName = Wires.acquireStringBuilder(); while (!wire.isEmpty()) { wire.readEventName(clusterName).marshallable(host -> { EngineCluster engineCluster = clusterMap.computeIfAbsent(clusterName.toString(), EngineCluster::new); engineCluster.readMarshallable(host); }); } }
@NotNull public Set<K> keySet() { final StringBuilder csp = Wires.acquireStringBuilder(); long cid = proxyReturnWireConsumer(keySet, read -> { read.typePrefix(); return read.applyToMarshallable(w -> { stringEvent(CoreFields.csp, csp, w); final long cid0 = CoreFields.cid(w); cidToCsp.put(cid0, csp.toString()); return cid0; }); }); return new ClientWiredStatelessChronicleSet<>(hub, csp.toString(), cid, valueIn -> valueIn.object(kClass)); }
@Nullable public Collection<V> values() { final StringBuilder csp = Wires.acquireStringBuilder(); long cid = proxyReturnWireConsumer(values, read -> { read.typePrefix(); return read.applyToMarshallable(w -> { stringEvent(CoreFields.csp, csp, w); final long cid0 = CoreFields.cid(w); cidToCsp.put(cid0, csp.toString()); return cid0; }); }); @Nullable final Function<ValueIn, V> consumer = valueIn -> valueIn.object(vClass); return new ClientWiredStatelessChronicleCollection<>(hub, ArrayList::new, consumer, "/" + context.name() + "?view=" + "values", cid ); }
@Override public void onRead(@NotNull WireIn inWire, @NotNull WireOut outWire) { final StringBuilder eventName = Wires.acquireStringBuilder(); @NotNull final ValueIn valueIn = inWire.readEventName(eventName); if (lastUpdateTime.contentEquals(eventName)) { final long time = valueIn.int64(); final byte id = inWire.read(() -> "id").int8(); replication.setLastModificationTime(id, time); return; } // receives replication events if (replicationEvent.contentEquals(eventName)) { final VanillaReplicatedEntry entry = vre.get(); entry.clear(); valueIn.marshallable(entry); replication.applyReplication(entry); } }
@Override public void onConsumer(@NotNull final WireIn w) { w.readDocument(null, d -> { final StringBuilder eventname = Wires.acquireStringBuilder(); @NotNull final ValueIn valueIn = d.readEventName(eventname); if (EventId.onEndOfSubscription.contentEquals(eventname)) { subscriber.onEndOfSubscription(); subscribersToTid.remove(this); hub.unsubscribe(tid()); } else if (CoreFields.reply.contentEquals(eventname)) { valueIn.marshallable(m -> { @Nullable final E message = m.read(() -> "message").object(messageClass); RemoteReference.this.onEvent(message, subscriber); }); } }); }
@Override public void onConsumer(@NotNull final WireIn inWire) { inWire.readDocument(null, d -> { StringBuilder sb = Wires.acquireStringBuilder(); @NotNull ValueIn valueIn = d.readEventName(sb); if (reply.contentEquals(sb)) { valueIn.marshallable(m -> { @Nullable final K topic = m.read(() -> "topic").object(kClass); @Nullable final V message = m.read(() -> "message").object(vClass); RemoteKVSSubscription.this.onEvent(topic, message, subscriber); }); } else if (onEndOfSubscription.contentEquals(sb)) { RemoteKVSSubscription.this.onEndOfSubscription(); hub.unsubscribe(tid()); } }); } });
@Override public void onConsumer(@NotNull final WireIn w) { w.readDocument(null, d -> { final StringBuilder eventname = Wires.acquireStringBuilder(); @NotNull final ValueIn valueIn = d.readEventName(eventname); if (onEndOfSubscription.contentEquals(eventname)) { topicSubscriber.onEndOfSubscription(); hub.unsubscribe(tid()); } else if (CoreFields.reply.contentEquals(eventname)) { valueIn.marshallable(m -> { @Nullable final T topic = m.read(() -> "topic").object(topicClass); @Nullable final M message = m.read(() -> "message").object(messageClass); try { RemoteTopicPublisher.this.onEvent(topic, message, topicSubscriber); } catch (InvalidSubscriberException e) { throw Jvm.rethrow(e); } }); } }); } });