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); }
return ScanResult.FOUND; int header = bytes.readVolatileInt(); if (Wires.isNotComplete(header)) { // or isEndOfFile return ScanResult.NOT_REACHED;
int num = bytes.readVolatileInt(offset); bytes.writeSkip(sizeToSkip + 4); } else { int num2 = bytes.readVolatileInt(offset); warn().on(getClass(), msgStart + " already set to " + Integer.toHexString(num2));
private void resetPosition() throws UnrecoverableTimeoutException { try { if (store == null || wire == null) return; position(store.writePosition()); assert position == 0 || Wires.isReadyData(wire.bytes().readVolatileInt(position)); final long headerNumber = store.lastSequenceNumber(this); wire.headerNumber(queue.rollCycle().toIndex(cycle, headerNumber + 1) - 1); assert wire.headerNumber() != -1 || checkIndex(wire.headerNumber(), position); } catch (@NotNull BufferOverflowException | StreamCorruptedException e) { throw new AssertionError(e); } assert checkWritePositionHeaderNumber(); }
int header = bytes.readVolatileInt(bytes.readPosition()); throw new IllegalArgumentException( "You can't know the index for an entry which hasn't been written. " + return i; int header = bytes.readVolatileInt(); int len = Wires.lengthOf(header); assert Wires.isReady(header);
if (Wires.isEndOfFile(wire().bytes().readVolatileInt(wire().bytes().readPosition()))) { state = END_OF_CYCLE; } else
long moveToEnd(final Wire wire) { Sequence sequence1 = this.sequence; if (sequence1 != null) { for (int i = 0; i < 128; i++) { long endAddress = writePosition.getVolatileValue(); if (endAddress == 0) return -1; long sequence = sequence1.getSequence(endAddress); if (sequence == Sequence.NOT_FOUND_RETRY) continue; if (sequence == Sequence.NOT_FOUND) return -1; Bytes<?> bytes = wire.bytes(); bytes.readPosition(endAddress); for (; ; ) { int header = bytes.readVolatileInt(endAddress); if (header == 0 || Wires.isNotComplete(header)) return sequence; int len = Wires.lengthOf(header) + 4; bytes.readSkip(len); endAddress += len; if (Wires.isData(header)) sequence += 1; } } } return -1; }
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(); } }
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); }
return ScanResult.FOUND; int header = bytes.readVolatileInt(); if (Wires.isNotComplete(header)) { // or isEndOfFile return ScanResult.NOT_REACHED;
int num = bytes.readVolatileInt(offset); bytes.writeSkip(sizeToSkip + 4); } else { int num2 = bytes.readVolatileInt(offset); warn().on(getClass(), msgStart + " already set to " + Integer.toHexString(num2));
private void resetPosition() throws UnrecoverableTimeoutException { try { if (store == null || wire == null) return; position(store.writePosition()); assert position == 0 || Wires.isReadyData(wire.bytes().readVolatileInt(position)); final long headerNumber = store.lastSequenceNumber(this); wire.headerNumber(queue.rollCycle().toIndex(cycle, headerNumber + 1) - 1); assert wire.headerNumber() != -1 || checkIndex(wire.headerNumber(), position); } catch (@NotNull BufferOverflowException | StreamCorruptedException e) { throw new AssertionError(e); } assert checkWritePositionHeaderNumber(); }
int header = bytes.readVolatileInt(bytes.readPosition()); throw new IllegalArgumentException( "You can't know the index for an entry which hasn't been written. " + return i; int header = bytes.readVolatileInt(); int len = Wires.lengthOf(header); assert Wires.isReady(header);
if (Wires.isEndOfFile(wire().bytes().readVolatileInt(wire().bytes().readPosition()))) { state = END_OF_CYCLE; } else
long moveToEnd(final Wire wire) { Sequence sequence1 = this.sequence; if (sequence1 != null) { for (int i = 0; i < 128; i++) { long endAddress = writePosition.getVolatileValue(); if (endAddress == 0) return -1; long sequence = sequence1.getSequence(endAddress); if (sequence == Sequence.NOT_FOUND_RETRY) continue; if (sequence == Sequence.NOT_FOUND) return -1; Bytes<?> bytes = wire.bytes(); bytes.readPosition(endAddress); for (; ; ) { int header = bytes.readVolatileInt(endAddress); if (header == 0 || Wires.isNotComplete(header)) return sequence; int len = Wires.lengthOf(header) + 4; bytes.readSkip(len); endAddress += len; if (Wires.isData(header)) sequence += 1; } } } return -1; }
@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; }