@NotNull private LongArrayValues array(@NotNull WireIn w, @NotNull LongArrayValues using, boolean index2index) { final StringBuilder sb = Wires.acquireStringBuilder(); @NotNull final ValueIn valueIn = w.readEventName(sb); String name = index2index ? "index2index" : "index"; if (!name.contentEquals(sb)) throw new IllegalStateException("expecting index, was " + sb); valueIn.int64array(using, this, (o1, o2) -> { }); return using; }
@NotNull @Override public String dump() { MappedBytes bytes = MappedBytes.mappedBytes(mappedFile); try { bytes.readLimit(bytes.realCapacity()); return Wires.fromSizePrefixedBlobs(bytes); } finally { bytes.release(); } }
Bytes bytes = Wires.acquireBytes(); TextWire text = new TextWire(bytes); while (true) {
public int getWritingThreadId() { final WireStore wireStore = queue.storeForCycle(queue.cycle(), queue.epoch(), false); if (wireStore != null) { final long position = wireStore.writePosition(); final int header = wireStore.bytes().readVolatileInt(position); if (Wires.isReady(header)) { final long nextHeaderPosition = position + Wires.lengthOf(header) + Wires.SPB_HEADER_SIZE; final int unfinishedHeader = wireStore.bytes(). readVolatileInt(nextHeaderPosition); if (Wires.isNotComplete(unfinishedHeader) && unfinishedHeader != 0) { return Wires.extractTidFromHeader(unfinishedHeader); } } } return NO_CURRENT_WRITER; } }
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; }
if (Wires.isNotComplete(header)) { // or isEndOfFile return ScanResult.NOT_REACHED; bytes.readSkip(Wires.lengthOf(header)); continue;
return true; final StringBuilder sb = acquireStringBuilder(); @NotNull final ValueIn read = dc.wire().read(sb); final Bytes bytes = Wires.acquireBytes(); ((KeyedMarshallable) v).writeKey(bytes); k = bytesToKey.computeIfAbsent(bytes, Bytes::copy); .compute(k, (k1, vOld) -> { if (vOld == null) return new IndexedValue<>(deepCopy(v), dc.index()); else { copyTo(v, vOld.v()); vOld.index(dc.index()); return vOld; Jvm.warn().on(getClass(), fromSizePrefixedBlobs(dc.wire().bytes(), start - 4), e);
StringBuilder sb = Wires.acquireStringBuilder(); mappedBytes.reserve(); try { while (mappedWire.readDataHeader()) { int header = mappedBytes.readVolatileInt(); if (Wires.isNotComplete(header)) break; long readPosition = mappedBytes.readPosition(); int length = Wires.lengthOf(header); ValueIn valueIn = mappedWire.readEventName(sb); if (StringUtils.equalsCaseIgnore(key, sb)) {
final StringBuilder eventName = Wires.acquireStringBuilder(); @NotNull @SuppressWarnings("ConstantConditions") final ValueIn valueIn = inWire.readEventName(eventName); long len = outBytes.writePosition(); if (len >= SIZE_OF_SIZE) { String s = Wires.fromSizePrefixedBlobs((Wire) outWire);
/** * updates all the fields in {@code this} that are null, from the {@param parentBuilder} * * @param parentBuilder the parentBuilder Chronicle Queue Builder * @return that */ public SingleChronicleQueueBuilder setAllNullFields(@Nullable SingleChronicleQueueBuilder parentBuilder) { if (parentBuilder == null) return this; if (!(this.getClass().isAssignableFrom(parentBuilder.getClass()) || parentBuilder.getClass().isAssignableFrom(this.getClass()))) throw new IllegalArgumentException("Classes are not in same implementation hierarchy"); List<FieldInfo> sourceFieldInfo = Wires.fieldInfos(parentBuilder.getClass()); for (final FieldInfo fieldInfo : Wires.fieldInfos(this.getClass())) { if (!sourceFieldInfo.contains(fieldInfo)) continue; Object resultV = fieldInfo.get(this); Object parentV = fieldInfo.get(parentBuilder); if (resultV == null && parentV != null) fieldInfo.set(this, parentV); } return this; }
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); }
private void updateMap(@NotNull NetworkStats ns, final long index) { final String key = ns.userId(); @Nullable final Stats stats = latestStatsPerClientId.getUsing(key, stats0); if (stats == null) { Stats value = project(Stats.class, ns); value.writeEma = value.writeBps(); value.readEma = value.readBps(); value.index = index; latestStatsPerClientId.put(key, value); return; } double lastWriteEma = stats.writeEma; double lastReadEma = stats.readEma; if (equalsSecond(stats.timestamp(), ns.timestamp())) { long lastWriteBps = stats.writeBps(); long lastReadBps = stats.readBps(); Wires.copyTo(ns, stats); stats.writeBps(stats.writeBps() + lastWriteBps); stats.readBps(stats.readBps() + lastReadBps); } else Wires.copyTo(ns, stats); stats.writeEma((stats.writeBps() * (1 - alpha)) + (lastWriteEma * alpha)); stats.readEma((stats.readBps() * (1 - alpha)) + (lastReadEma * alpha)); latestStatsPerClientId.put(key, stats); }
if ("key".equals(e.getKey())) continue; FieldInfo fi = Wires.fieldInfo(valueType, e.getKey()); fi.set(v, e.getValue());
@NotNull public <R> R copyTo(@NotNull R using) { Wires.copyTo(data,using); return using; }
StringBuilder sb = Wires.acquireStringBuilder(); mappedBytes.reserve(); try { while (mappedWire.readDataHeader()) { int header = mappedBytes.readVolatileInt(); if (Wires.isNotComplete(header)) break; long readPosition = mappedBytes.readPosition(); int length = Wires.lengthOf(header); ValueIn valueIn = mappedWire.readEventName(sb); if (StringUtils.equalsCaseIgnore(key, sb)) {
public int getWritingThreadId() { final WireStore wireStore = queue.storeForCycle(queue.cycle(), queue.epoch(), false); if (wireStore != null) { final long position = wireStore.writePosition(); final int header = wireStore.bytes().readVolatileInt(position); if (Wires.isReady(header)) { final long nextHeaderPosition = position + Wires.lengthOf(header) + Wires.SPB_HEADER_SIZE; final int unfinishedHeader = wireStore.bytes(). readVolatileInt(nextHeaderPosition); if (Wires.isNotComplete(unfinishedHeader) && unfinishedHeader != 0) { return Wires.extractTidFromHeader(unfinishedHeader); } } } return NO_CURRENT_WRITER; } }
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; }
@Nullable private List<String> columnNames() { if (columnNames != null) return columnNames; @NotNull LinkedHashSet<String> result = new LinkedHashSet<>(); result.add("index"); // if (Marshallable.class.isAssignableFrom(messageClass)) { for (@NotNull final FieldInfo fi : fieldInfos(messageClass)) { result.add(fi.name()); } // } columnNames = new ArrayList<>(result); return columnNames; }
if (Wires.isNotComplete(header)) { // or isEndOfFile return ScanResult.NOT_REACHED; bytes.readSkip(Wires.lengthOf(header)); continue;