/** Returns an immutable result from the values currently in the builder */ public final TraceContextOrSamplingFlags build() { final TraceContextOrSamplingFlags result; if (!extra.isEmpty() && type == 1) { // move extra to the trace context TraceContext context = (TraceContext) value; if (context.extra().isEmpty()) { context = InternalPropagation.instance.withExtra(context, ensureImmutable(extra)); } else { context = InternalPropagation.instance.withExtra(context, concatImmutableLists(context.extra(), extra)); } result = new TraceContextOrSamplingFlags(type, context, emptyList()); } else { // make sure the extra data is immutable and unmodifiable result = new TraceContextOrSamplingFlags(type, value, ensureImmutable(extra)); } if (!sampledLocal) return result; // save effort if no change return result.withFlags(value.flags | FLAG_SAMPLED_LOCAL); }
extra = ensureMutable(extra); extra.set(i, consolidated); } else { consolidate(existing, consolidated); extra = ensureMutable(extra); extra = ensureMutable(extra); extra.add(consolidated);
public static List<Object> ensureImmutable(List<Object> extra) { if (isImmutable(extra)) return extra; // Faster to make a copy than check the type to see if it is already a singleton list if (extra.size() == 1) return Collections.singletonList(extra.get(0)); return Collections.unmodifiableList(new ArrayList<>(extra)); }
public final TraceContext build() { String missing = ""; if (traceId == 0L) missing += " traceId"; if (spanId == 0L) missing += " spanId"; if (!"".equals(missing)) throw new IllegalStateException("Missing: " + missing); return new TraceContext( flags, traceIdHigh, traceId, localRootId, parentId, spanId, ensureImmutable(extra) ); }
localRootId = implicitParent.localRootId(); spanId = implicitParent.spanId(); extra = concatImmutableLists(extra, implicitParent.extra()); } else { flags = InternalPropagation.instance.flags(samplingFlags);
public final TraceContext build() { String missing = ""; if (traceId == 0L) missing += " traceId"; if (spanId == 0L) missing += " spanId"; if (!"".equals(missing)) throw new IllegalStateException("Missing: " + missing); return new TraceContext( flags, traceIdHigh, traceId, localRootId, parentId, spanId, ensureImmutable(extra) ); }
localRootId = implicitParent.localRootId(); spanId = implicitParent.spanId(); extra = concatImmutableLists(extra, implicitParent.extra()); } else { flags = InternalPropagation.instance.flags(samplingFlags);
/** Returns an immutable result from the values currently in the builder */ public final TraceContextOrSamplingFlags build() { final TraceContextOrSamplingFlags result; if (!extra.isEmpty() && type == 1) { // move extra to the trace context TraceContext context = (TraceContext) value; if (context.extra().isEmpty()) { context = InternalPropagation.instance.withExtra(context, ensureImmutable(extra)); } else { context = InternalPropagation.instance.withExtra(context, concatImmutableLists(context.extra(), extra)); } result = new TraceContextOrSamplingFlags(type, context, emptyList()); } else { // make sure the extra data is immutable and unmodifiable result = new TraceContextOrSamplingFlags(type, value, ensureImmutable(extra)); } if (!sampledLocal) return result; // save effort if no change return result.withFlags(value.flags | FLAG_SAMPLED_LOCAL); }
public static List<Object> ensureImmutable(List<Object> extra) { if (isImmutable(extra)) return extra; // Faster to make a copy than check the type to see if it is already a singleton list if (extra.size() == 1) return Collections.singletonList(extra.get(0)); return Collections.unmodifiableList(new ArrayList<>(extra)); }
extra = ensureMutable(extra); extra.set(i, consolidated); } else { consolidate(existing, consolidated); extra = ensureMutable(extra); extra = ensureMutable(extra); extra.add(consolidated);