@Nullable public static MessageHistory readHistory(final DocumentContext dc, MessageHistory history) { final Wire wire = dc.wire(); if (wire == null) return null; Object parent = wire.parent(); wire.parent(null); try { final Bytes<?> bytes = wire.bytes(); final byte code = bytes.readByte(bytes.readPosition()); history.reset(); return code == (byte) FIELD_NUMBER ? readHistoryFromBytes(wire, history) : readHistoryFromWire(wire, history); } finally { wire.parent(parent); } }
private void setCycle2(int cycle, boolean createIfAbsent) { if (cycle < 0) throw new IllegalArgumentException("You can not have a cycle that starts " + "before Epoch. cycle=" + cycle); SingleChronicleQueue queue = this.queue; WireStore store = this.store; if (store != null) { storePool.release(store); } this.store = storePool.acquire(cycle, queue.epoch(), createIfAbsent); closableResources.storeReference = this.store; resetWires(queue); // only set the cycle after the wire is set. this.cycle = cycle; assert wire.startUse(); wire.parent(this); wire.pauser(queue.pauserSupplier.get()); resetPosition(); queue.onRoll(cycle); }
private boolean cycle(final int cycle) { if (this.cycle == cycle && state == FOUND_CYCLE) return true; WireStore nextStore = this.queue.storeForCycle(cycle, queue.epoch(), false); if (nextStore == null && this.store == null) return false; if (nextStore == null) { if (direction == BACKWARD) state = BEYOND_START_OF_CYCLE; else state = CYCLE_NOT_FOUND; return false; } if (store != null) queue.release(store); if (nextStore == this.store) return true; context.wire(null); this.store = nextStore; closableResources.storeReference = nextStore; this.state = FOUND_CYCLE; this.setCycle(cycle); resetWires(); final Wire wire = wire(); wire.parent(this); wire.pauser(queue.pauserSupplier.get()); return true; }
/** * Read next message, forward or backward, depending on the settings of the Tailer * * @param tailer ExcerptTailer * @return entry or null, if no entry available */ private String readNextEntry(@NotNull final ExcerptTailer tailer) { DocumentContext dc = tailer.readingDocument(); try { if (dc.isPresent()) { Object parent = dc.wire().parent(); assert parent == tailer; return dc.wire().read().text(); } return null; } finally { dc.close(); } }
@Nullable public static MessageHistory readHistory(final DocumentContext dc, MessageHistory history) { final Wire wire = dc.wire(); if (wire == null) return null; Object parent = wire.parent(); wire.parent(null); try { final Bytes<?> bytes = wire.bytes(); final byte code = bytes.readByte(bytes.readPosition()); history.reset(); return code == (byte) FIELD_NUMBER ? readHistoryFromBytes(wire, history) : readHistoryFromWire(wire, history); } finally { wire.parent(parent); } }
private void setCycle2(int cycle, boolean createIfAbsent) { if (cycle < 0) throw new IllegalArgumentException("You can not have a cycle that starts " + "before Epoch. cycle=" + cycle); SingleChronicleQueue queue = this.queue; WireStore store = this.store; if (store != null) { storePool.release(store); } this.store = storePool.acquire(cycle, queue.epoch(), createIfAbsent); closableResources.storeReference = this.store; resetWires(queue); // only set the cycle after the wire is set. this.cycle = cycle; if (this.store == null) return; assert wire.startUse(); wire.parent(this); wire.pauser(queue.pauserSupplier.get()); resetPosition(); queue.onRoll(cycle); }
private boolean cycle(final int cycle) { if (this.cycle == cycle && state == FOUND_CYCLE) return true; WireStore nextStore = this.queue.storeForCycle(cycle, queue.epoch(), false); if (nextStore == null && this.store == null) return false; if (nextStore == null) { if (direction == BACKWARD) state = BEYOND_START_OF_CYCLE; else state = CYCLE_NOT_FOUND; return false; } if (store != null) queue.release(store); if (nextStore == this.store) return true; context.wire(null); this.store = nextStore; closableResources.storeReference = nextStore; this.state = FOUND_CYCLE; this.setCycle(cycle); resetWires(); final Wire wire = wire(); wire.parent(this); wire.pauser(queue.pauserSupplier.get()); return true; }