/** * 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; }
/** * ready to accept wire * * @param outWire the wire that you wish to write */ @Override protected void onWrite(@NotNull WireOut outWire) { SubHandler handler = handler(); if (handler != null) handler.onWrite(outWire); for (int i = 0; i < writers.size(); i++) { if (isClosing.get()) return; WriteMarshallable w = next(); if (w != null) w.writeMarshallable(outWire); } }
/** * 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(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(); }
/** * 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(); }
@Override public void onInitialize(@NotNull WireOut outWire) { if (nc().isAcceptor()) heartbeatHandler(heartbeatTimeoutMs, heartbeatIntervalMs, cid()).writeMarshallable (outWire); @NotNull final WriteMarshallable heartbeatMessage = w -> { w.writeDocument(true, d -> d.write(CoreFields.cid).int64(cid())); w.writeDocument(false, d -> d.write(() -> "heartbeat").text("")); }; connectionMonitor = nc().acquireConnectionListener(); timer = new Timer(nc().rootAsset().findOrCreateView(EventLoop.class)); startPeriodicHeartbeatCheck(); startPeriodicallySendingHeartbeats(heartbeatMessage); }