Remove ContextStore.Factory interface; use Supplier instead (#4157)
This commit is contained in:
parent
b2984ae731
commit
dc4ddf7932
|
@ -64,7 +64,7 @@ public class ChannelFutureListenerInstrumentation implements TypeInstrumentation
|
|||
InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
|
||||
|
||||
ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(future.getChannel(), ChannelTraceContext.Factory.INSTANCE);
|
||||
contextStore.putIfAbsent(future.getChannel(), ChannelTraceContext.FACTORY);
|
||||
Context parentContext = channelTraceContext.getConnectionContext();
|
||||
if (parentContext == null) {
|
||||
return null;
|
||||
|
|
|
@ -6,19 +6,12 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.netty.v3_8;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ChannelTraceContext {
|
||||
|
||||
public static class Factory implements ContextStore.Factory<ChannelTraceContext> {
|
||||
public static final Factory INSTANCE = new Factory();
|
||||
|
||||
@Override
|
||||
public ChannelTraceContext create() {
|
||||
return new ChannelTraceContext();
|
||||
}
|
||||
}
|
||||
public static final Supplier<ChannelTraceContext> FACTORY = ChannelTraceContext::new;
|
||||
|
||||
private Context connectionContext;
|
||||
private Context clientParentContext;
|
||||
|
|
|
@ -55,9 +55,7 @@ public class NettyChannelInstrumentation implements TypeInstrumentation {
|
|||
ContextStore<Channel, ChannelTraceContext> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
|
||||
|
||||
if (contextStore
|
||||
.putIfAbsent(channel, ChannelTraceContext.Factory.INSTANCE)
|
||||
.getConnectionContext()
|
||||
if (contextStore.putIfAbsent(channel, ChannelTraceContext.FACTORY).getConnectionContext()
|
||||
== null) {
|
||||
contextStore.get(channel).setConnectionContext(context);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class HttpClientRequestTracingHandler extends SimpleChannelDownstreamHand
|
|||
}
|
||||
|
||||
ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
|
||||
Context parentContext = channelTraceContext.getConnectionContext();
|
||||
if (parentContext != null) {
|
||||
|
|
|
@ -28,7 +28,7 @@ public class HttpClientResponseTracingHandler extends SimpleChannelUpstreamHandl
|
|||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent msg) {
|
||||
ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
|
||||
Context context = channelTraceContext.getContext();
|
||||
if (context == null) {
|
||||
|
|
|
@ -28,7 +28,7 @@ public class HttpServerRequestTracingHandler extends SimpleChannelUpstreamHandle
|
|||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) {
|
||||
ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
|
||||
Object message = event.getMessage();
|
||||
if (!(message instanceof HttpRequest)) {
|
||||
|
|
|
@ -28,7 +28,7 @@ public class HttpServerResponseTracingHandler extends SimpleChannelDownstreamHan
|
|||
@Override
|
||||
public void writeRequested(ChannelHandlerContext ctx, MessageEvent msg) {
|
||||
ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
|
||||
Context context = tracer().getServerContext(channelTraceContext);
|
||||
if (context == null || !(msg.getMessage() instanceof HttpResponse)) {
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.servlet.v3_0;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
|
||||
import io.opentelemetry.instrumentation.servlet.naming.ServletFilterMappingResolverFactory;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import java.util.Collection;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.FilterRegistration;
|
||||
|
@ -15,8 +13,7 @@ import javax.servlet.ServletContext;
|
|||
import javax.servlet.ServletRegistration;
|
||||
|
||||
public class Servlet3FilterMappingResolverFactory
|
||||
extends ServletFilterMappingResolverFactory<FilterRegistration>
|
||||
implements ContextStore.Factory<MappingResolver> {
|
||||
extends ServletFilterMappingResolverFactory<FilterRegistration> {
|
||||
private final FilterConfig filterConfig;
|
||||
|
||||
public Servlet3FilterMappingResolverFactory(FilterConfig filterConfig) {
|
||||
|
|
|
@ -5,16 +5,13 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.servlet.v3_0;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
|
||||
import io.opentelemetry.instrumentation.servlet.naming.ServletMappingResolverFactory;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import java.util.Collection;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletRegistration;
|
||||
|
||||
public class Servlet3MappingResolverFactory extends ServletMappingResolverFactory
|
||||
implements ContextStore.Factory<MappingResolver> {
|
||||
public class Servlet3MappingResolverFactory extends ServletMappingResolverFactory {
|
||||
private final ServletConfig servletConfig;
|
||||
|
||||
public Servlet3MappingResolverFactory(ServletConfig servletConfig) {
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.servlet.v5_0.service;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
|
||||
import io.opentelemetry.instrumentation.servlet.naming.ServletFilterMappingResolverFactory;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import jakarta.servlet.FilterConfig;
|
||||
import jakarta.servlet.FilterRegistration;
|
||||
import jakarta.servlet.ServletContext;
|
||||
|
@ -15,8 +13,7 @@ import jakarta.servlet.ServletRegistration;
|
|||
import java.util.Collection;
|
||||
|
||||
public class JakartaServletFilterMappingResolverFactory
|
||||
extends ServletFilterMappingResolverFactory<FilterRegistration>
|
||||
implements ContextStore.Factory<MappingResolver> {
|
||||
extends ServletFilterMappingResolverFactory<FilterRegistration> {
|
||||
private final FilterConfig filterConfig;
|
||||
|
||||
public JakartaServletFilterMappingResolverFactory(FilterConfig filterConfig) {
|
||||
|
|
|
@ -5,16 +5,13 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.servlet.v5_0.service;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
|
||||
import io.opentelemetry.instrumentation.servlet.naming.ServletMappingResolverFactory;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import jakarta.servlet.ServletConfig;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletRegistration;
|
||||
import java.util.Collection;
|
||||
|
||||
public class JakartaServletMappingResolverFactory extends ServletMappingResolverFactory
|
||||
implements ContextStore.Factory<MappingResolver> {
|
||||
public class JakartaServletMappingResolverFactory extends ServletMappingResolverFactory {
|
||||
private final ServletConfig servletConfig;
|
||||
|
||||
public JakartaServletMappingResolverFactory(ServletConfig servletConfig) {
|
||||
|
|
|
@ -11,8 +11,10 @@ import java.util.Collection;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class ServletFilterMappingResolverFactory<FILTERREGISTRATION> {
|
||||
public abstract class ServletFilterMappingResolverFactory<FILTERREGISTRATION>
|
||||
implements Supplier<MappingResolver> {
|
||||
|
||||
protected abstract FILTERREGISTRATION getFilterRegistration();
|
||||
|
||||
|
@ -58,7 +60,8 @@ public abstract class ServletFilterMappingResolverFactory<FILTERREGISTRATION> {
|
|||
return mappingsList;
|
||||
}
|
||||
|
||||
public final MappingResolver create() {
|
||||
@Override
|
||||
public final MappingResolver get() {
|
||||
Collection<String> mappings = getMappings();
|
||||
if (mappings == null) {
|
||||
return null;
|
||||
|
|
|
@ -7,12 +7,14 @@ package io.opentelemetry.instrumentation.servlet.naming;
|
|||
|
||||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class ServletMappingResolverFactory {
|
||||
public abstract class ServletMappingResolverFactory implements Supplier<MappingResolver> {
|
||||
|
||||
protected abstract Collection<String> getMappings();
|
||||
|
||||
public final MappingResolver create() {
|
||||
@Override
|
||||
public final MappingResolver get() {
|
||||
Collection<String> mappings = getMappings();
|
||||
if (mappings == null) {
|
||||
return null;
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.javaagent.instrumentation.api;
|
|||
|
||||
import io.opentelemetry.instrumentation.api.caching.Cache;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Interface to represent context storage for instrumentations.
|
||||
|
@ -19,18 +20,6 @@ import java.util.function.Function;
|
|||
*/
|
||||
public interface ContextStore<K, C> {
|
||||
|
||||
/**
|
||||
* Factory interface to create context instances.
|
||||
*
|
||||
* @param <C> context type
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface Factory<C> {
|
||||
|
||||
/** Returns a new context instance. */
|
||||
C create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get context given the key.
|
||||
*
|
||||
|
@ -64,7 +53,7 @@ public interface ContextStore<K, C> {
|
|||
* @param contextFactory factory instance to produce new context object
|
||||
* @return old instance if it was present, or new instance
|
||||
*/
|
||||
C putIfAbsent(K key, Factory<C> contextFactory);
|
||||
C putIfAbsent(K key, Supplier<C> contextFactory);
|
||||
|
||||
/**
|
||||
* Adapt this context store instance to {@link Cache} interface.
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.api.concurrent;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
||||
import java.util.function.Supplier;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -19,7 +19,7 @@ public final class PropagatedContext {
|
|||
private static final AtomicReferenceFieldUpdater<PropagatedContext, Context> contextUpdater =
|
||||
AtomicReferenceFieldUpdater.newUpdater(PropagatedContext.class, Context.class, "context");
|
||||
|
||||
static final ContextStore.Factory<PropagatedContext> FACTORY = PropagatedContext::new;
|
||||
static final Supplier<PropagatedContext> FACTORY = PropagatedContext::new;
|
||||
|
||||
// Used by AtomicReferenceFieldUpdater
|
||||
@SuppressWarnings("UnusedVariable")
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.util.HashSet;
|
|||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.ClassFileVersion;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
|
@ -898,7 +899,7 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object putIfAbsent(Object key, Factory<Object> contextFactory) {
|
||||
public Object putIfAbsent(Object key, Supplier<Object> contextFactory) {
|
||||
Object existingContext = realGet(key);
|
||||
if (null != existingContext) {
|
||||
return existingContext;
|
||||
|
@ -908,7 +909,7 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
|
|||
if (null != existingContext) {
|
||||
return existingContext;
|
||||
}
|
||||
Object context = contextFactory.create();
|
||||
Object context = contextFactory.get();
|
||||
realPut(key, context);
|
||||
return context;
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
package context;
|
||||
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Context {
|
||||
public static final ContextStore.Factory<Context> FACTORY = Context::new;
|
||||
public static final Supplier<Context> FACTORY = Context::new;
|
||||
|
||||
public int count = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue