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); } }
private void doRollback(boolean interrupted) { if (interrupted) LOG.warn("Thread is interrupted. Can't guarantee complete message, so not committing"); // zero out all contents... for (long i = position; i <= wire.bytes().writePosition(); i++) wire.bytes().writeByte(i, (byte) 0); position = lastPosition; wire.bytes().writePosition(position); ((AbstractWire) wire).forceNotInsideHeader(); }
private boolean headerNumberCheck(@NotNull AbstractWire wire) { wire.headNumberCheck((actual, position) -> { try { long expecting = store.sequenceForPosition(this, position, false); if (actual == expecting) return true; LOG.error("", new AssertionError("header number check failed " + "expecting=" + expecting + " != actual=" + actual)); return false; } catch (Exception e) { LOG.error("", e); return false; } }); return true; }
assert wire.startUse(); wire.pauser(pauserSupplier.get()); wire.headerNumber(rollCycle.toIndex(cycle, 0) - 1); if ((!readOnly) && wire.writeFirstHeader()) { wireStore = storeFactory.apply(that, wire); wire.updateFirstHeader(); wire.readFirstHeader(timeoutMS, TimeUnit.MILLISECONDS); ValueIn valueIn = wire.readEventName(name); if (StringUtils.isEqual(name, MetaDataKeys.header.name())) { wireStore = valueIn.typedMarshallable();
@Override public long index() throws IORuntimeException { if (this.wire.headerNumber() == Long.MIN_VALUE) { try { wire.headerNumber(queue.rollCycle().toIndex(cycle, store.lastSequenceNumber(StoreAppender.this))); long headerNumber0 = wire.headerNumber(); assert (((AbstractWire) this.wire).isInsideHeader()); return isMetaData() ? headerNumber0 : headerNumber0 + 1; } catch (IOException e) { throw new IORuntimeException(e); } } return isMetaData() ? Long.MIN_VALUE : this.wire.headerNumber() + 1; }
@Override public void close() { try { if (rollbackOnClose) { present = false; if (start != -1) wire.bytes().readPosition(start).readLimit(readLimit); start = -1; return; } if (isPresent() && !isMetaData()) incrementIndex(); super.close(); // assert wire == null || wire.endUse(); } finally { rollbackOnClose = false; } }
assert wire.startUse(); wire.pauser(pauserSupplier.get()); wire.headerNumber(rollCycle.toIndex(cycle, 0) - 1); if ((!readOnly) && wire.writeFirstHeader()) { wireStore = storeFactory.apply(that, wire); wire.updateFirstHeader(); wire.readFirstHeader(timeoutMS, TimeUnit.MILLISECONDS); ValueIn valueIn = wire.readEventName(name); if (StringUtils.isEqual(name, MetaDataKeys.header.name())) { wireStore = valueIn.typedMarshallable();
@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(); } }
@Override public void close() { try { if (rollbackOnClose) { present = false; if (start != -1) wire.bytes().readPosition(start).readLimit(readLimit); start = -1; return; } if (isPresent() && !isMetaData()) incrementIndex(); super.close(); // assert wire == null || wire.endUse(); } finally { rollbackOnClose = false; } }
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); } }
@Override public long index() throws IORuntimeException { if (this.wire.headerNumber() == Long.MIN_VALUE) { try { wire.headerNumber(queue.rollCycle().toIndex(cycle, store.lastSequenceNumber(StoreAppender.this))); long headerNumber0 = wire.headerNumber(); assert (((AbstractWire) this.wire).isInsideHeader()); return isMetaData() ? headerNumber0 : headerNumber0 + 1; } catch (IOException e) { throw new IORuntimeException(e); } } return isMetaData() ? Long.MIN_VALUE : this.wire.headerNumber() + 1; }
private void doRollback(boolean interrupted) { if (interrupted) LOG.warn("Thread is interrupted. Can't guarantee complete message, so not committing"); // zero out all contents... for (long i = position; i <= wire.bytes().writePosition(); i++) wire.bytes().writeByte(i, (byte) 0); position = lastPosition; wire.bytes().writePosition(position); ((AbstractWire) wire).forceNotInsideHeader(); }
private boolean headerNumberCheck(@NotNull AbstractWire wire) { wire.headNumberCheck((actual, position) -> { try { long expecting = store.sequenceForPosition(this, position, false); if (actual == expecting) return true; LOG.error("", new AssertionError("header number check failed " + "expecting=" + expecting + " != actual=" + actual)); return false; } catch (Exception e) { LOG.error("", e); return false; } }); return true; }
@Override public void writeBytes(@NotNull BytesStore bytes) throws UnrecoverableTimeoutException { writeLock.lock(); try { int cycle = queue.cycle(); if (wire == null) setWireIfNull(cycle); if (this.cycle != cycle) 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(); } }