Refine search
/** * @param marshallable to write to excerpt. */ @Override public void writeBytes(@NotNull WriteBytesMarshallable marshallable) throws UnrecoverableTimeoutException { try (DocumentContext dc = writingDocument()) { Bytes<?> bytes = dc.wire().bytes(); long wp = bytes.writePosition(); marshallable.writeMarshallable(bytes); if (wp == bytes.writePosition()) dc.rollbackOnClose(); else if (padToCacheAlignMode() == Padding.WORD) ((StoreAppenderContext) dc).padToWordAlign = true; else if (padToCacheAlignMode() != Padding.CACHE_LINE) ((StoreAppenderContext) dc).padToCacheAlign = false; } }
/** * Creates a new Excerpt containing and index which will be 1L << 17L bytes long, This method is * used for creating both the primary and secondary indexes. Chronicle Queue uses a root primary * index ( each entry in the primary index points to a unique a secondary index. The secondary * index only records the addressForRead of every 64th except, the except are linearly scanned from * there on. ) * * @param wire the current wire * @return the addressForRead of the Excerpt containing the usable index, just after the header */ long newIndex(@NotNull WireOut wire, boolean index2index) throws StreamCorruptedException { long writePosition = this.writePosition.getVolatileValue(); Bytes<?> bytes = wire.bytes(); bytes.writePosition(writePosition); long position = wire.enterHeader(indexCount * 8 + 128); WriteMarshallable writer = index2index ? index2IndexTemplate : indexTemplate; writer.writeMarshallable(wire); wire.updateHeader(position, true, 0); return position; }
@Override public long recoverAndWriteHeader(@NotNull Wire wire, long timeoutMS, final LongValue lastPosition, Sequence sequence) throws UnrecoverableTimeoutException { Bytes<?> bytes = wire.bytes(); long offset = bytes.writePosition(); int num = bytes.readVolatileInt(offset); long pos = bytes.writePosition(); try { bytes.writeSkip(4); wire.getValueOut().text(stackTrace); wire.addPadding(Math.toIntExact(sizeToSkip + (pos + 4) - bytes.writePosition())); } finally { bytes.writePosition(pos);
private long writeHeader(@NotNull Wire wire, int safeLength) { Bytes<?> bytes = wire.bytes(); // writePosition points at the last record in the queue, so we can just skip it and we're ready for write long pos = position; long lastPos = store.writePosition(); if (pos < lastPos) { // queue moved since we last touched it - recalculate header number try { wire.headerNumber(queue.rollCycle().toIndex(cycle, store.lastSequenceNumber(this))); } catch (StreamCorruptedException ex) { Jvm.warn().on(getClass(), "Couldn't find last sequence", ex); } } int header = bytes.readVolatileInt(lastPos); assert header != NOT_INITIALIZED; lastPos += lengthOf(bytes.readVolatileInt(lastPos)) + SPB_HEADER_SIZE; bytes.writePosition(lastPos); return wire.enterHeader(safeLength); }
@Override public void writeBytes(@NotNull BytesStore bytes) throws UnrecoverableTimeoutException { writeLock.lock(); try { int cycle = queue.cycle(); if (this.cycle != cycle || wire == null) rollCycleTo(cycle); position(writeHeader(wire, (int) queue.overlapSize())); assert ((AbstractWire) wire).isInsideHeader(); beforeAppend(wire, wire.headerNumber() + 1); Bytes<?> wireBytes = wire.bytes(); wireBytes.write(bytes); if (padToCacheLines == Padding.WORD) wireBytes.writeSkip((-wireBytes.writePosition()) & 0x3); wire.updateHeader(position, false, 0); lastIndex(wire.headerNumber()); lastPosition = position; lastCycle = cycle; store.writePosition(position); writeIndexForPosition(lastIndex, position); } catch (StreamCorruptedException e) { throw new AssertionError(e); } finally { writeLock.unlock(); } }
public static void write(@NotNull Bytes bytes, int value) throws BufferOverflowException { long position = bytes.writePosition(); bytes.write(template); try { bytes.append(position + VALUE, value, DIGITS); } catch (IllegalArgumentException e) { throw new AssertionError(e); } }
public static void write(@NotNull Bytes bytes, long value) throws BufferOverflowException, IllegalArgumentException { long position = bytes.writePosition(); bytes.write(template); bytes.append(position + VALUE, value, DIGITS); }
public static void write(@NotNull Bytes bytes, long capacity) throws BufferOverflowException, IllegalArgumentException { assert (bytes.writePosition() & 0x7) == 0; bytes.writeLong(capacity); bytes.writeLong(0L); // used long start = bytes.writePosition(); bytes.zeroOut(start, start + (capacity << 3)); bytes.writeSkip(capacity << 3); }
@NotNull public Bytes acquireBytesForWrite(long position) throws IOException, IllegalStateException, IllegalArgumentException { @Nullable MappedBytesStore mbs = acquireByteStore(position); @NotNull Bytes bytes = mbs.bytesForWrite(); bytes.writePosition(position); mbs.release(); return bytes; }
public static void lazyWrite(@NotNull Bytes bytes, long capacity) throws BufferOverflowException { assert (bytes.writePosition() & 0x7) == 0; bytes.writeLong(capacity); bytes.writeLong(0L); // used bytes.writeSkip(capacity << 3); }
public UncheckedBytes(@NotNull Bytes underlyingBytes) throws IllegalStateException { super(underlyingBytes.bytesStore(), underlyingBytes.writePosition(), underlyingBytes.writeLimit()); this.underlyingBytes = underlyingBytes; readPosition(underlyingBytes.readPosition()); }
default void cipher(@NotNull Cipher cipher, @NotNull Bytes outBytes, @NotNull ByteBuffer using1, @NotNull ByteBuffer using2) throws IllegalStateException { long readPos = outBytes.readPosition(); try { long writePos = outBytes.writePosition(); BytesStore inBytes; long size = readRemaining(); len += cipher.doFinal(using1, using2); assert len == using2.position(); outBytes.writePosition(writePos + using2.position()); } catch (@NotNull Exception e) {
public UncheckedNativeBytes(@NotNull Bytes<Underlying> underlyingBytes) throws IllegalStateException { this.underlyingBytes = underlyingBytes; this.bytesStore = (NativeBytesStore<Underlying>) underlyingBytes.bytesStore(); assert bytesStore.start() == 0; writePosition = underlyingBytes.writePosition(); writeLimit = underlyingBytes.writeLimit(); readPosition = underlyingBytes.readPosition(); capacity = bytesStore.capacity(); }
/** * @param marshallable to write to excerpt. */ @Override public void writeBytes(@NotNull WriteBytesMarshallable marshallable) throws UnrecoverableTimeoutException { try (DocumentContext dc = writingDocument()) { Bytes<?> bytes = dc.wire().bytes(); long wp = bytes.writePosition(); marshallable.writeMarshallable(bytes); if (wp == bytes.writePosition()) dc.rollbackOnClose(); else if (padToCacheAlignMode() == Padding.WORD) ((StoreAppenderContext) dc).padToWordAlign = true; else if (padToCacheAlignMode() != Padding.CACHE_LINE) ((StoreAppenderContext) dc).padToCacheAlign = false; } }
static Bytes<ByteBuffer> wrapForWrite(@NotNull ByteBuffer byteBuffer) { BytesStore<?, ByteBuffer> bs = BytesStore.wrap(byteBuffer); try { Bytes<ByteBuffer> bbb = bs.bytesForWrite(); bbb.writePosition(byteBuffer.position()); bbb.writeLimit(byteBuffer.limit()); return bbb;
public static void write(@NotNull Bytes bytes, long capacity) { long start = bytes.writePosition(); bytes.write(SECTION1); bytes.append(capacity); while (bytes.writePosition() - start < CAPACITY + DIGITS) { bytes.writeUnsignedByte(' '); } bytes.write(SECTION2); bytes.write(ZERO); bytes.write(SECTION3); for (long i = 0; i < capacity; i++) { if (i > 0) bytes.appendUtf8(", "); bytes.write(ZERO); } bytes.write(SECTION4); }
/** * write and exceptions and rolls back if no data was written */ void writeData(boolean isNotComplete, @NotNull Bytes inBytes, @NotNull WriteMarshallable c) { @NotNull final WriteMarshallable marshallable = out -> { final long readPosition = inBytes.readPosition(); final long position = outWire.bytes().writePosition(); try { c.writeMarshallable(outWire); } catch (Throwable t) { inBytes.readPosition(readPosition); if (LOG.isInfoEnabled()) LOG.info("While reading " + inBytes.toDebugString(), " processing wire " + c, t); outWire.bytes().writePosition(position); outWire.writeEventName(() -> "exception").throwable(t); } // write 'reply : {} ' if no data was sent if (position == outWire.bytes().writePosition()) { outWire.writeEventName(reply).marshallable(EMPTY); } }; if (isNotComplete) outWire.writeNotCompleteDocument(false, marshallable); else outWire.writeDocument(false, marshallable); logYaml(); }
/** * Creates a new Excerpt containing and index which will be 1L << 17L bytes long, This method is * used for creating both the primary and secondary indexes. Chronicle Queue uses a root primary * index ( each entry in the primary index points to a unique a secondary index. The secondary * index only records the addressForRead of every 64th except, the except are linearly scanned from * there on. ) * * @param wire the current wire * @return the addressForRead of the Excerpt containing the usable index, just after the header */ long newIndex(@NotNull WireOut wire, boolean index2index) throws StreamCorruptedException { long writePosition = this.writePosition.getVolatileValue(); Bytes<?> bytes = wire.bytes(); bytes.writePosition(writePosition); long position = wire.enterHeader(indexCount * 8 + 128); WriteMarshallable writer = index2index ? index2IndexTemplate : indexTemplate; writer.writeMarshallable(wire); wire.updateHeader(position, true, 0); return position; }
/** * 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(); }
@SuppressWarnings("resource") @Override public long recoverAndWriteHeader(@NotNull Wire wire, long timeoutMS, final LongValue lastPosition, Sequence sequence) throws UnrecoverableTimeoutException { Bytes<?> bytes = wire.bytes(); long offset = bytes.writePosition(); int num = bytes.readVolatileInt(offset); long pos = bytes.writePosition(); try { bytes.writeSkip(4); wire.getValueOut().text(stackTrace); wire.addPadding(Math.toIntExact(sizeToSkip + (pos + 4) - bytes.writePosition())); } finally { bytes.writePosition(pos);