/** * used by {@link Demarshallable} * * @param wire a wire */ @UsedViaReflection private SCQRoll(@NotNull WireIn wire) { length = wire.read(RollFields.length).int32(); format = wire.read(RollFields.format).text(); epoch = wire.read(RollFields.epoch).int64(); ValueIn rollTimeVIN = wire.read(RollFields.rollTime); if (rollTimeVIN.hasNext()) rollTime = rollTimeVIN.time(); String zoneId = wire.read(RollFields.rollTimeZone).text(); if (zoneId != null) rollTimeZone = ZoneId.of(zoneId); else rollTimeZone = null; }
@Override public void readMarshallable(@NotNull WireIn wire) throws IORuntimeException { ValueIn valueIn = wire.getValueIn(); for (int i = 0; i < NUMBER_OF_LONGS; i++) assertEquals(i, valueIn.int64()); //Jvm.pause(PAUSE_READ_MS); }
/** * used by {@link Demarshallable} * * @param wire a wire */ @SuppressWarnings("unused") @UsedViaReflection private SingleTableStore(@NotNull WireIn wire) { assert wire.startUse(); try { this.wireType = Objects.requireNonNull(wire.read(MetaDataField.wireType).object(WireType.class)); this.mappedBytes = (MappedBytes) (wire.bytes()); this.mappedFile = mappedBytes.mappedFile(); this.refCount = ReferenceCounter.onReleased(this::onCleanup); if (wire.bytes().readRemaining() > 0) { this.recovery = Objects.requireNonNull(wire.read(MetaDataField.recovery).typedMarshallable()); } else { this.recovery = new SimpleStoreRecovery(); // disabled. } if (wire.bytes().readRemaining() > 0) { this.metadata = Objects.requireNonNull(wire.read(MetaDataField.metadata).typedMarshallable()); } else { this.metadata = (T) Metadata.NoMeta.INSTANCE; } mappedWire = wireType.apply(mappedBytes); } finally { assert wire.endUse(); } }
/** * used by {@link Demarshallable} * * @param wire a wire */ @UsedViaReflection private SCQIndexing(@NotNull WireIn wire) { this(wire.read(IndexingFields.indexCount).int32(), wire.read(IndexingFields.indexSpacing).int32(), wire.read(IndexingFields.index2Index).int64ForBinding(wire.newLongReference()), wire.read(IndexingFields.lastIndex).int64ForBinding(wire.newLongReference()), wire::newLongArrayReference); }
@SuppressWarnings("unused") @UsedViaReflection SCQMeta(@NotNull WireIn wire) { this.roll = Objects.requireNonNull(wire.read(MetaDataField.roll).typedMarshallable()); this.deltaCheckpointInterval = wire.bytes().readRemaining() > 0 ? wire.read(MetaDataField.deltaCheckpointInterval).int32() : -1; // disabled. this.sourceId = wire.bytes().readRemaining() > 0 ? wire.read(MetaDataField.sourceId).int32() : 0; }
private LongValue loadWritePosition(@NotNull WireIn wire) { final ValueIn read = wire.read(MetaDataField.writePosition); final int code; final long start = wire.bytes().readPosition(); try { wire.consumePadding(); code = wire.bytes().uncheckedReadUnsignedByte(); } finally { wire.bytes().readPosition(start); } if (code == BinaryWireCode.I64_ARRAY) { TwoLongValue result = wire.newTwoLongReference(); // when the write position is and array it also encodes the sequence number in the write position as the second long value read.int128(result); return result; } final LongValue result = wire.newLongReference(); read.int64(result); return result; }
@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 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()); } }); } });
private void readMarshallable(String path, @NotNull WireIn wire) { @NotNull StringBuilder name = new StringBuilder(); while (!wire.isEmpty()) { @NotNull ValueIn in = wire.read(name); long pos = wire.bytes().readPosition(); @NotNull String path2 = path + "/" + name; if (wire.getValueIn().isTyped()) { wire.bytes().readPosition(pos); @Nullable Object o = in.typedMarshallable(); installableMap.put(path2, (Installable) o); } else { in.marshallable(w -> this.readMarshallable(path2, w)); } } }
@NotNull final ValueIn valueIn = inWire.readEventName(eventName); assert startEnforceInValueReadCheck(inWire); try { LOG.info("server : received lastUpdateTime"); final long time = valueIn.int64(); final byte id = inWire.read(() -> "id").int8(); replication.setLastModificationTime(id, time); return; writeData(true, inWire.bytes(), out -> { if (LOG.isDebugEnabled()) Jvm.debug().on(getClass(), "server : received bootstrap request");
@Override public void readMarshallable(@NotNull WireIn wire) throws IllegalStateException { wire.read(() -> "keyType").typeLiteral(this, (o, c) -> o.keyType = c) .read(() -> "valueType").typeLiteral(this, (o, c) -> o.valueType = c) .read(() -> "compression").text(this, (o, c) -> o.compression = c) .read(() -> "putReturnsNull").bool(this, (o, e) -> o.putReturnsNull = e) .read(() -> "removeReturnsNull").bool(this, (o, e) -> o.removeReturnsNull = e); while (!wire.isEmpty()) wire.read(() -> "import").text(this, (o, s) -> o.importFile = s); }
@Override public void onConsumer(@NotNull WireIn inWire) { if (Jvm.isDebug()) LOG.info("client : bootstrap"); inWire.readDocument(null, d -> { byte remoteIdentifier = d.read(identifierReply).int8(); onConnected(localIdentifier, remoteIdentifier, replication); }); }
@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 void accept(final WireIn wireIn, final Consumer<String> messageHandler) { final Bytes<?> serialisedMessage = wireIn.bytes(); final byte dataFormatIndicator = serialisedMessage.readByte(serialisedMessage.readPosition()); String text; if (isBinaryFormat(dataFormatIndicator)) { textConversionTarget.clear(); final BinaryWire binaryWire = new BinaryWire(serialisedMessage); binaryWire.copyTo(wireType.apply(textConversionTarget)); text = textConversionTarget.toString(); } else { text = serialisedMessage.toString(); } messageHandler.accept(text); }
@SuppressWarnings("unchecked") public void process(@NotNull WireIn in, @NotNull WireOut out, @NotNull C collection, @NotNull BiConsumer toWire, @NotNull Function fromWire, @NotNull Supplier factory, long tid) { this.fromWire = fromWire; this.toWire = toWire; this.underlyingCollection = collection; this.factory = factory; try { this.inWire = in; this.outWire = out; this.tid = tid; assert in.startUse(); dataConsumer.readMarshallable(in); } catch (RuntimeException e) { Jvm.warn().on(getClass(), e); }finally { assert in.endUse(); } }
@Override public void accept(final WireIn wireIn, final Consumer<String> messageHandler) { long elementCount = 0; while (wireIn.hasMore()) { new BinaryWire(wireIn.bytes()).copyOne(wireType.apply(textConversionTarget)); elementCount++; if ((elementCount & 1) == 0) { messageHandler.accept(textConversionTarget.toString()); textConversionTarget.clear(); } } }
@Override public void readMarshallable(@NotNull WireIn wire) throws IllegalStateException { @NotNull StringBuilder mountDesc = new StringBuilder(); while (!wire.isEmpty()) { @Nullable MountPoint mp = wire.readEventName(mountDesc).typedMarshallable(); mounts.put(mountDesc.toString(), mp); } }
/** * write and exceptions and rolls back if no data was written */ void writeData(@NotNull WireIn wireIn, @NotNull WriteMarshallable c) { @NotNull Bytes inBytes = wireIn.bytes(); outWire.writeDocument(false, out -> { final long readPosition = inBytes.readPosition(); final long position = outWire.bytes().writePosition(); try { c.writeMarshallable(outWire); } catch (Throwable t) { final String readingYaml = wireIn.readingPeekYaml(); inBytes.readPosition(readPosition); if (LOG.isInfoEnabled()) LOG.info("While readingBytes=" + inBytes.toDebugString() + "\nreadingYaml=" + readingYaml, "\nprocessing wire " + c, t); outWire.bytes().writePosition(position); outWire.writeEventName(() -> "readingYaml").text(readingYaml); outWire.writeEventName(() -> "exception").throwable(t); } // write 'reply : {} ' if no data was sent if (position == outWire.bytes().writePosition()) { outWire.writeEventName(reply).marshallable(EMPTY); } }); logYaml(); }
@Override public void onConsumer(@NotNull final WireIn inWire) { inWire.readDocument(null, d -> { final StringBuilder eventName = Wires.acquireStringBuilder(); @NotNull final ValueIn valueIn = d.readEventName(eventName); if (PublisherHandler.EventId.onEndOfSubscription.contentEquals(eventName)) { subscriber.onEndOfSubscription(); subscribersToTid.remove(this); hub.unsubscribe(tid()); } else if (CoreFields.reply.contentEquals(eventName)) { @NotNull final Class aClass = rc.elementType(); @Nullable final Object object = (MapEvent.class.isAssignableFrom(aClass) || (TopologicalEvent.class.isAssignableFrom(aClass))) ? valueIn.typedMarshallable() : valueIn.object(rc.elementType()); AbstractRemoteSubscription.this.onEvent(object, subscriber); } }); } });
@NotNull final ValueIn valueIn = inWire.readEventName(eventName); assert startEnforceInValueReadCheck(inWire); try { final T topic = wireToT.apply(wire.read(params[0])); final M message = wireToM.apply(wire.read(params[1])); nullCheck(topic); nullCheck(message);