Skip to content

Commit

Permalink
Merge pull request #796 from zalando/spi-synchronization
Browse files Browse the repository at this point in the history
Synchronize SPI decorator loading
  • Loading branch information
lukasniemeier-zalando authored Aug 14, 2023
2 parents 4350726 + b9eb66a commit 81be1de
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import org.apiguardian.api.API;

import java.util.List;
import java.util.ServiceLoader;

import static java.util.ServiceLoader.load;
import static java.util.stream.Collectors.toList;
import static java.util.stream.StreamSupport.stream;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
import static org.zalando.opentracing.jdbc.span.SpanDecorator.composite;

Expand All @@ -15,7 +18,11 @@
public final class ServiceLoaderSpanDecorator extends ForwardingSpanDecorator {

public ServiceLoaderSpanDecorator() {
super(composite(load(SpanDecorator.class)));
super(composite(loadDecorators()));
}

private static synchronized List<SpanDecorator> loadDecorators() {
return stream(load(SpanDecorator.class).spliterator(), false).collect(toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import io.opentracing.contrib.web.servlet.filter.ServletFilterSpanDecorator;
import org.apiguardian.api.API;

import java.util.List;
import java.util.ServiceLoader;

import static java.util.ServiceLoader.load;
import static java.util.stream.Collectors.toList;
import static java.util.stream.StreamSupport.stream;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;

/**
Expand All @@ -15,7 +18,11 @@
public final class ServiceLoaderSpanDecorator extends ForwardingSpanDecorator {

public ServiceLoaderSpanDecorator() {
super(CompositeSpanDecorator.composite(load(ServletFilterSpanDecorator.class)));
super(CompositeSpanDecorator.composite(loadDecorators()));
}

private static synchronized List<ServletFilterSpanDecorator> loadDecorators() {
return stream(load(ServletFilterSpanDecorator.class).spliterator(), false).collect(toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import io.opentracing.contrib.spring.web.interceptor.HandlerInterceptorSpanDecorator;
import org.apiguardian.api.API;

import java.util.List;
import java.util.ServiceLoader;

import static java.util.ServiceLoader.load;
import static java.util.stream.Collectors.toList;
import static java.util.stream.StreamSupport.stream;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
import static org.zalando.opentracing.spring.web.extension.CompositeSpanDecorator.composite;

Expand All @@ -17,6 +20,11 @@ public final class ServiceLoaderSpanDecorator
extends ForwardingSpanDecorator {

public ServiceLoaderSpanDecorator() {
super(composite(load(HandlerInterceptorSpanDecorator.class)));
super(composite(loadDecorators()));
}

private static synchronized List<HandlerInterceptorSpanDecorator> loadDecorators() {
return stream(load(HandlerInterceptorSpanDecorator.class).spliterator(), false).collect(toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import io.opentracing.contrib.spring.web.webfilter.WebFluxSpanDecorator;
import org.apiguardian.api.API;

import java.util.List;
import java.util.ServiceLoader;

import static java.util.ServiceLoader.load;
import static java.util.stream.Collectors.toList;
import static java.util.stream.StreamSupport.stream;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
import static org.zalando.opentracing.spring.webflux.extension.CompositeSpanDecorator.composite;

Expand All @@ -17,6 +20,11 @@ public final class ServiceLoaderSpanDecorator
extends ForwardingSpanDecorator {

public ServiceLoaderSpanDecorator() {
super(composite(load(WebFluxSpanDecorator.class)));
super(composite(loadDecorators()));
}

private static synchronized List<WebFluxSpanDecorator> loadDecorators() {
return stream(load(WebFluxSpanDecorator.class).spliterator(), false).collect(toList());
}

}

0 comments on commit 81be1de

Please sign in to comment.