/** * @param wireType the wire type that is being used * @param mappedBytes used to mapped the data store file * @param recovery used to recover from concurrent modifications */ SingleTableStore(@NotNull final WireType wireType, @NotNull MappedBytes mappedBytes, @NotNull StoreRecovery recovery, @NotNull T metadata) { this.wireType = wireType; this.metadata = metadata; this.recovery = recovery; this.mappedBytes = mappedBytes; this.mappedFile = mappedBytes.mappedFile(); this.refCount = ReferenceCounter.onReleased(this::onCleanup); mappedWire = wireType.apply(mappedBytes); }
private void resetWires(@NotNull ChronicleQueue queue) { WireType wireType = queue.wireType(); { Wire oldw = this.wire; this.wire = wireType.apply(store.bytes()); closableResources.wireReference = this.wire.bytes(); assert wire != oldw; if (oldw != null) { releaseWireResources(oldw); } } { Wire old = this.wireForIndex; this.wireForIndex = wireType.apply(store.bytes()); closableResources.wireForIndexReference = wireForIndex.bytes(); assert wire != old; if (old != null) { releaseWireResources(old); } } }
@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 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); }
private void resetWires() { WireType wireType = queue.wireType(); final AbstractWire wire = (AbstractWire) readAnywhere(wireType.apply(store.bytes())); assert headerNumberCheck(wire); this.context.wire(wire); wire.parent(this); Wire wireForIndexOld = wireForIndex; wireForIndex = readAnywhere(wireType.apply(store().bytes())); closableResources.wireForIndexReference = wireForIndex.bytes(); closableResources.wireReference = wire.bytes(); assert headerNumberCheck((AbstractWire) wireForIndex); assert wire != wireForIndexOld; if (wireForIndexOld != null) { releaseWireResources(wireForIndexOld); } }
@NotNull private Wire toWire(int key) { final MyData myData = new MyData(); myData.key = key; myData.value = Integer.toString(key); Wire result = WireType.BINARY.apply(Bytes.elasticByteBuffer()); try (final DocumentContext dc = result.writingDocument()) { dc.wire().getValueOut().typedMarshallable(myData); } return result; }
AbstractWire wire = (AbstractWire) wireType.apply(mappedBytes); assert wire.startUse(); wire.pauser(pauserSupplier.get());
/** * 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(); } }
throw new NullPointerException("nothing in result"); final String actual = this.wireType.apply(bytes).read(() -> "key").text(); Assert.assertEquals(expected, actual); f.get(1, TimeUnit.SECONDS);
private void removeEOF(Path path) throws IOException { long blockSize = 64 << 10; long chunkSize = OS.pageAlign(blockSize); long overlapSize = OS.pageAlign(blockSize / 4); final MappedBytes mappedBytes = MappedBytes.mappedBytes(path.toFile(), chunkSize, overlapSize, false); mappedBytes.reserve(); try { final Wire wire = WireType.BINARY_LIGHT.apply(mappedBytes); final Bytes<?> bytes = wire.bytes(); bytes.readLimit(bytes.capacity()); bytes.readSkip(4); // move past header try (final SingleChronicleQueueStore qs = loadStore(wire)) { assertNotNull(qs); long l = qs.writePosition(); long len = Wires.lengthOf(bytes.readVolatileInt(l)); long eofOffset = l + len + 4L; bytes.writePosition(eofOffset); bytes.writeInt(0); } } finally { mappedBytes.release(); } }
Assert.assertEquals(1, count); Wire w = WireType.BINARY.apply(bytes);
/** * @param wireType the wire type that is being used * @param mappedBytes used to mapped the data store file * @param recovery used to recover from concurrent modifications */ SingleTableStore(@NotNull final WireType wireType, @NotNull MappedBytes mappedBytes, @NotNull StoreRecovery recovery, @NotNull T metadata) { this.wireType = wireType; this.metadata = metadata; this.recovery = recovery; this.mappedBytes = mappedBytes; this.mappedFile = mappedBytes.mappedFile(); this.refCount = ReferenceCounter.onReleased(this::onCleanup); mappedWire = wireType.apply(mappedBytes); }
@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(); } } }
private void resetWires(@NotNull ChronicleQueue queue) { WireType wireType = queue.wireType(); { Wire oldw = this.wire; this.wire = store == null ? null : wireType.apply(store.bytes()); closableResources.wireReference = this.wire == null ? null : this.wire.bytes(); assert wire != oldw || wire == null; if (oldw != null) { releaseWireResources(oldw); } } { Wire old = this.wireForIndex; this.wireForIndex = store == null ? null : wireType.apply(store.bytes()); closableResources.wireForIndexReference = this.wireForIndex == null ? null : wireForIndex.bytes(); assert wire != old || wire == null; if (old != null) { releaseWireResources(old); } } }
@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); }
private void resetWires() { WireType wireType = queue.wireType(); final AbstractWire wire = (AbstractWire) readAnywhere(wireType.apply(store.bytes())); assert headerNumberCheck(wire); this.context.wire(wire); wire.parent(this); Wire wireForIndexOld = wireForIndex; wireForIndex = readAnywhere(wireType.apply(store().bytes())); closableResources.wireForIndexReference = wireForIndex.bytes(); closableResources.wireReference = wire.bytes(); assert headerNumberCheck((AbstractWire) wireForIndex); assert wire != wireForIndexOld; if (wireForIndexOld != null) { releaseWireResources(wireForIndexOld); } }
AbstractWire wire = (AbstractWire) wireType.apply(mappedBytes); assert wire.startUse(); wire.pauser(pauserSupplier.get());
/** * 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(); } }
@Override public boolean writeEOF(@NotNull Wire wire, long timeoutMS) { String fileName = mappedFile.file().getAbsolutePath(); // just in case we are about to release this if (wire.bytes().tryReserve()) { try { wire.writeEndOfWire(timeoutMS, TimeUnit.MILLISECONDS, writePosition()); if (wire.bytes().writePosition() > 4 && Wires.isEndOfFile(wire.bytes().readVolatileInt(wire.bytes().writePosition() - 4))) { // only if we just written EOF QueueFileShrinkManager.scheduleShrinking(mappedFile.file(), wire.bytes().writePosition()); return true; } } finally { wire.bytes().release(); } } else { try (MappedBytes bytes = MappedBytes.mappedBytes(mappedFile.file(), mappedFile.chunkSize())) { Wire wire0 = WireType.valueOf(wire).apply(bytes); wire0.writeEndOfWire(timeoutMS, TimeUnit.MILLISECONDS, writePosition()); if (wire.bytes().writePosition() > 4 && Wires.isEndOfFile(wire.bytes().readVolatileInt(wire.bytes().writePosition() - 4))) { QueueFileShrinkManager.scheduleShrinking(mappedFile.file(), wire.bytes().writePosition()); return true; } } catch (Exception e) { Jvm.warn().on(getClass(), "unable to write the EOF file=" + fileName, e); } } return false; }