public static TraceContextOrSamplingFlags create(SamplingFlags flags) { // reuses constants to avoid excess allocation if (flags == SamplingFlags.SAMPLED) return SAMPLED; if (flags == SamplingFlags.EMPTY) return EMPTY; if (flags == SamplingFlags.NOT_SAMPLED) return NOT_SAMPLED; if (flags == SamplingFlags.DEBUG) return DEBUG; return new TraceContextOrSamplingFlags(3, flags, emptyList()); }
public static TraceContextOrSamplingFlags create(TraceContext context) { return new TraceContextOrSamplingFlags(1, context, emptyList()); }
public static TraceContextOrSamplingFlags create(TraceIdContext traceIdContext) { return new TraceContextOrSamplingFlags(2, traceIdContext, emptyList()); }
TraceContextOrSamplingFlags withFlags(int flags) { switch (type) { case 1: TraceContext context = InternalPropagation.instance.withFlags((TraceContext) value, flags); return new TraceContextOrSamplingFlags(type, context, extra); case 2: TraceIdContext traceIdContext = idContextWithFlags(flags); return new TraceContextOrSamplingFlags(type, traceIdContext, extra); case 3: SamplingFlags samplingFlags = SamplingFlags.toSamplingFlags(flags); if (extra.isEmpty()) return create(samplingFlags); return new TraceContextOrSamplingFlags(type, samplingFlags, extra); } throw new AssertionError("programming error"); }
/** 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 TraceContextOrSamplingFlags create(SamplingFlags flags) { // reuses constants to avoid excess allocation if (flags == SamplingFlags.SAMPLED) return SAMPLED; if (flags == SamplingFlags.EMPTY) return EMPTY; if (flags == SamplingFlags.NOT_SAMPLED) return NOT_SAMPLED; if (flags == SamplingFlags.DEBUG) return DEBUG; return new TraceContextOrSamplingFlags(3, flags, emptyList()); }
public static TraceContextOrSamplingFlags create(TraceContext context) { return new TraceContextOrSamplingFlags(1, context, emptyList()); }
public static TraceContextOrSamplingFlags create(TraceIdContext traceIdContext) { return new TraceContextOrSamplingFlags(2, traceIdContext, emptyList()); }
TraceContextOrSamplingFlags withFlags(int flags) { switch (type) { case 1: TraceContext context = InternalPropagation.instance.withFlags((TraceContext) value, flags); return new TraceContextOrSamplingFlags(type, context, extra); case 2: TraceIdContext traceIdContext = idContextWithFlags(flags); return new TraceContextOrSamplingFlags(type, traceIdContext, extra); case 3: SamplingFlags samplingFlags = SamplingFlags.toSamplingFlags(flags); if (extra.isEmpty()) return create(samplingFlags); return new TraceContextOrSamplingFlags(type, samplingFlags, extra); } throw new AssertionError("programming error"); }
/** 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); }