@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(); } } }
@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 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); }
/** * 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 net.openhft.chronicle.wire.Demarshallable} * * @param wire a wire */ @UsedViaReflection private SingleChronicleQueueStore(@NotNull WireIn wire) { assert wire.startUse(); try { writePosition = loadWritePosition(wire); this.mappedBytes = (MappedBytes) (wire.bytes()); this.mappedFile = mappedBytes.mappedFile(); this.refCount = ReferenceCounter.onReleased(this::onCleanup); this.indexing = Objects.requireNonNull(wire.read(MetaDataField.indexing).typedMarshallable()); assert indexing != null; this.indexing.writePosition = writePosition; this.sequence = new RollCycleEncodeSequence(writePosition, rollIndexCount(), rollIndexSpacing()); this.indexing.sequence = sequence; } finally { assert wire.endUse(); } }
boolean startEnforceInValueReadCheck(WireIn w) { assert readPosAfterValueIn == -1; readPosAfterValueIn = w.bytes().readPosition(); hasSkipped = false; return true; }
boolean endEnforceInValueReadCheck(WireIn w) { try { assert readPosAfterValueIn != -1; if (hasSkipped) return true; return w.bytes().readPosition() > readPosAfterValueIn; } finally { readPosAfterValueIn = -1; } }
/** * if not successful, in other-words when the function returns try, will return the wire back to * the read location */ private void tryReadEvent(@NotNull final WireIn wire, @NotNull final BiFunction<EngineWireHandler, WireIn, Boolean> f) { final long readPosition = wire.bytes().readPosition(); boolean success = false; try { success = f.apply(this, wire); } finally { if (!success) wire.bytes().readPosition(readPosition); } }
private void logToBuffer(@NotNull WireIn in, @NotNull StringBuilder logBuffer, long start) { if (YamlLogging.showServerReads()) { logBuffer.setLength(0); try { logBuffer.append("\nServer Receives:\n") .append(Wires.fromSizePrefixedBlobs(in.bytes(), start)); } catch (Exception e) { logBuffer.append("\n\n").append(Bytes.toString(in.bytes(), start, in.bytes().readLimit() - start)); } } }
private void logYamlToStandardOut(@NotNull WireIn in) { if (YamlLogging.showServerReads()) { try { LOG.info("\nServer Receives:\n" + Wires.fromSizePrefixedBlobs(in)); } catch (Exception e) { LOG.info("\n\n" + Bytes.toString(in.bytes())); } } }
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)); } } }
@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(); } } }
@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 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); }
/** * 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 net.openhft.chronicle.wire.Demarshallable} * * @param wire a wire */ @UsedViaReflection private SingleChronicleQueueStore(@NotNull WireIn wire) { assert wire.startUse(); try { writePosition = loadWritePosition(wire); this.mappedBytes = (MappedBytes) (wire.bytes()); this.mappedFile = mappedBytes.mappedFile(); this.refCount = ReferenceCounter.onReleased(this::onCleanup); this.indexing = Objects.requireNonNull(wire.read(MetaDataField.indexing).typedMarshallable()); this.indexing.writePosition = writePosition; this.sequence = new RollCycleEncodeSequence(writePosition, rollIndexCount(), rollIndexSpacing()); this.indexing.sequence = sequence; } finally { assert wire.endUse(); } }
/** * 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(); }
writeData(true, inWire.bytes(), out -> { if (LOG.isDebugEnabled()) Jvm.debug().on(getClass(), "server : received bootstrap request");