Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package io.opentelemetry.javaagent.instrumentation.cassandra.v4_0;

import com.datastax.oss.driver.api.core.CqlSession;
import java.util.function.Function;
import java.util.function.UnaryOperator;

public class CompletionStageFunction implements Function<Object, Object> {
public class CompletionStageFunction implements UnaryOperator<Object> {

@Override
public Object apply(Object session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package io.opentelemetry.javaagent.instrumentation.cassandra.v4_4;

import com.datastax.oss.driver.api.core.CqlSession;
import java.util.function.Function;
import java.util.function.UnaryOperator;

public class CompletionStageFunction implements Function<Object, Object> {
public class CompletionStageFunction implements UnaryOperator<Object> {

@Override
public Object apply(Object session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.description.modifier.Visibility;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
Expand All @@ -32,7 +32,7 @@ class RestClientWrapper {
private static final Class<?> proxyClass = createProxyClass();
private static final Field targetField = getTargetField(proxyClass);
private static final Field instrumenterSupplierField = getInstrumenterSupplierField(proxyClass);
private static final Function<RestClient, RestClient> proxyFactory = getProxyFactory(proxyClass);
private static final UnaryOperator<RestClient> proxyFactory = getProxyFactory(proxyClass);

private static Class<?> createProxyClass() {
return new ByteBuddy()
Expand Down Expand Up @@ -139,7 +139,7 @@ private static Instrumenter<ElasticsearchRestRequest, Response> getInstrumenter(
return supplier != null ? supplier.get() : null;
}

private static Function<RestClient, RestClient> getProxyFactory(Class<?> clazz) {
private static UnaryOperator<RestClient> getProxyFactory(Class<?> clazz) {
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
Class<?>[] parameterTypes = constructor.getParameterTypes();
if (parameterTypes.length >= 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import javax.annotation.Nullable;

/**
Expand All @@ -24,7 +24,7 @@ class UnitConverter {
registerConversion("ns", "s", value -> value.doubleValue() / TimeUnit.SECONDS.toNanos(1));
}

private final Function<Number, Number> convertingFunction;
private final UnaryOperator<Number> convertingFunction;

/**
* Get an instance of converter that is able to convert a value from a given source to a target
Expand Down Expand Up @@ -66,7 +66,7 @@ public static UnitConverter getInstance(@Nullable String sourceUnit, String targ
*/
// visible for testing
static void registerConversion(
String sourceUnit, String targetUnit, Function<Number, Number> convertingFunction) {
String sourceUnit, String targetUnit, UnaryOperator<Number> convertingFunction) {
if (sourceUnit.isEmpty()) {
throw new IllegalArgumentException("Non empty sourceUnit must be provided");
}
Expand All @@ -92,7 +92,7 @@ private static String buildConverterKey(String sourceUnit, String targetUnit) {
*
* @param convertingFunction an algorithm applied when converting value
*/
UnitConverter(Function<Number, Number> convertingFunction) {
UnitConverter(UnaryOperator<Number> convertingFunction) {
this.convertingFunction = convertingFunction;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import javax.annotation.Nullable;

final class InstrumentationApiContextBridging {
Expand Down Expand Up @@ -199,13 +199,13 @@ final class InstrumentationApiContextBridging {
}
}

private static Function<Object, Object> httpRouteStateConvert(
private static UnaryOperator<Object> httpRouteStateConvert(
MethodHandle create,
MethodHandle getMethod,
MethodHandle getRoute,
MethodHandle getUpdatedBySourceOrder,
MethodHandle getSpan,
Function<Object, Object> convertSpan) {
UnaryOperator<Object> convertSpan) {
return httpRouteHolder -> {
try {
String method = (String) getMethod.invoke(httpRouteHolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.invoke.MethodHandles;
import java.time.Duration;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -194,7 +195,7 @@ void storeContextForcesItToBecomeCurrent() {
}

private static class StoreOpenTelemetryContext
implements Function<reactor.util.context.Context, reactor.util.context.Context> {
implements UnaryOperator<reactor.util.context.Context> {

private final Span span;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.lang.invoke.MethodHandles;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -175,7 +176,7 @@ public void registerOnEachOperator() {
}
}

private static void registerScheduleHook(String key, Function<Runnable, Runnable> function) {
private static void registerScheduleHook(String key, UnaryOperator<Runnable> function) {
if (SCHEDULERS_HOOK_METHOD == null) {
return;
}
Expand Down Expand Up @@ -252,7 +253,7 @@ private static <T extends Throwable> T sneakyThrow(Throwable t) throws T {
}

private static class StoreOpenTelemetryContext
implements Function<reactor.util.context.Context, reactor.util.context.Context> {
implements UnaryOperator<reactor.util.context.Context> {

private final Context tracingContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.time.Duration;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -131,7 +132,7 @@ void fluxInNonBlockingPublisherAssembly() {
(Flux<Integer>)
FLUX_CONTEXT_WRITE_METHOD.invoke(
interim,
(Function<reactor.util.context.Context, reactor.util.context.Context>)
(UnaryOperator<reactor.util.context.Context>)
ctx -> {
Context parent =
ContextPropagationOperator.getOpenTelemetryContext(
Expand Down Expand Up @@ -389,7 +390,7 @@ void doesNotOverrideInnerCurrentSpansWithThereIsOuterCurrent() {
(Flux<Object>)
FLUX_CONTEXT_WRITE_METHOD.invoke(
interim,
(Function<reactor.util.context.Context, reactor.util.context.Context>)
(UnaryOperator<reactor.util.context.Context>)
context -> {
// subscribers that know that their subscription can happen
// ahead of time and in the 'wrong' context, has to clean up 'wrong'
Expand Down Expand Up @@ -565,7 +566,7 @@ private <T> Mono<T> monoSpan(Mono<T> mono, String spanName) {
return (Mono<T>)
MONO_CONTEXT_WRITE_METHOD.invoke(
interim,
(Function<reactor.util.context.Context, reactor.util.context.Context>)
(UnaryOperator<reactor.util.context.Context>)
ctx -> {
Context parent =
ContextPropagationOperator.getOpenTelemetryContext(ctx, Context.current());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import javax.annotation.Nullable;

class MainJarPathFinder {
private final Supplier<String[]> getProcessHandleArguments;
private final Function<String, String> getSystemProperty;
private final UnaryOperator<String> getSystemProperty;
private final Predicate<Path> fileExists;

public MainJarPathFinder() {
Expand All @@ -26,7 +26,7 @@ public MainJarPathFinder() {
// visible for tests
MainJarPathFinder(
Supplier<String[]> getProcessHandleArguments,
Function<String, String> getSystemProperty,
UnaryOperator<String> getSystemProperty,
Predicate<Path> fileExists) {
this.getProcessHandleArguments = getProcessHandleArguments;
this.getSystemProperty = getSystemProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import io.opentelemetry.sdk.resources.Resource;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -29,7 +29,7 @@ class JarServiceNameResourceExtractorTest {
@Test
void extractResource_empty() {
String[] processArgs = new String[0];
Function<String, String> getProperty = prop -> null;
UnaryOperator<String> getProperty = prop -> null;
Predicate<Path> fileExists = JarServiceNameResourceExtractorTest::failPath;
JarServiceNameResourceExtractor serviceNameProvider =
getExtractor(processArgs, getProperty, fileExists);
Expand All @@ -40,7 +40,7 @@ void extractResource_empty() {
}

private static JarServiceNameResourceExtractor getExtractor(
String[] processArgs, Function<String, String> getProperty, Predicate<Path> fileExists) {
String[] processArgs, UnaryOperator<String> getProperty, Predicate<Path> fileExists) {
return new JarServiceNameResourceExtractor(
new MainJarPathFinder(() -> processArgs, getProperty, fileExists));
}
Expand Down Expand Up @@ -100,7 +100,7 @@ static String[] getArgs(String jarName) {
@ParameterizedTest
@MethodSource("sunCommandLineArguments")
void extractResource_sunCommandLine(String commandLine, Path jarPath) {
Function<String, String> getProperty =
UnaryOperator<String> getProperty =
key -> "sun.java.command".equals(key) ? commandLine : null;
Predicate<Path> fileExists = jarPath::equals;

Expand All @@ -116,7 +116,7 @@ void extractResource_sunCommandLine(String commandLine, Path jarPath) {
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/7567
@Test
void extractResource_sunCommandLineProblematicArgs() {
Function<String, String> getProperty =
UnaryOperator<String> getProperty =
key -> key.equals("sun.java.command") ? "one C:/two" : null;
Predicate<Path> fileExists = path -> false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package io.opentelemetry.javaagent.extension.instrumentation;

import java.util.function.Function;
import java.util.function.UnaryOperator;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
Expand All @@ -25,7 +25,7 @@ public interface TypeTransformer {
*/
default void applyAdviceToMethod(
ElementMatcher<? super MethodDescription> methodMatcher, String adviceClassName) {
applyAdviceToMethod(methodMatcher, Function.identity(), adviceClassName);
applyAdviceToMethod(methodMatcher, UnaryOperator.identity(), adviceClassName);
}

/**
Expand All @@ -34,7 +34,7 @@ default void applyAdviceToMethod(
*/
void applyAdviceToMethod(
ElementMatcher<? super MethodDescription> methodMatcher,
Function<Advice.WithCustomMapping, Advice.WithCustomMapping> mappingCustomizer,
UnaryOperator<Advice.WithCustomMapping> mappingCustomizer,
String adviceClassName);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.opentelemetry.javaagent.tooling.Utils;
import io.opentelemetry.javaagent.tooling.bytebuddy.ExceptionHandlers;
import io.opentelemetry.javaagent.tooling.instrumentation.indy.ForceDynamicallyTypedAssignReturnedFactory;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
Expand All @@ -31,7 +31,7 @@ final class TypeTransformerImpl implements TypeTransformer {
@Override
public void applyAdviceToMethod(
ElementMatcher<? super MethodDescription> methodMatcher,
Function<Advice.WithCustomMapping, Advice.WithCustomMapping> mappingCustomizer,
UnaryOperator<Advice.WithCustomMapping> mappingCustomizer,
String adviceClassName) {
agentBuilder =
agentBuilder.transform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
Expand Down Expand Up @@ -51,7 +51,7 @@ public IndyTypeTransformerImpl(
@Override
public void applyAdviceToMethod(
ElementMatcher<? super MethodDescription> methodMatcher,
Function<Advice.WithCustomMapping, Advice.WithCustomMapping> mappingCustomizer,
UnaryOperator<Advice.WithCustomMapping> mappingCustomizer,
String adviceClassName) {
// default strategy used by AgentBuilder.Transformer.ForAdvice
AgentBuilder.PoolStrategy poolStrategy = AgentBuilder.PoolStrategy.Default.FAST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import net.bytebuddy.agent.builder.AgentBuilder;
Expand Down Expand Up @@ -184,7 +184,7 @@ private static Set<String> getModuleAdviceNames(InstrumentationModule module) {
@Override
public void applyAdviceToMethod(
ElementMatcher<? super MethodDescription> methodMatcher,
Function<Advice.WithCustomMapping, Advice.WithCustomMapping> mappingCustomizer,
UnaryOperator<Advice.WithCustomMapping> mappingCustomizer,
String adviceClassName) {
adviceNames.add(adviceClassName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
Expand All @@ -20,7 +20,7 @@ final class AdviceClassNameCollector implements TypeTransformer {
@Override
public void applyAdviceToMethod(
ElementMatcher<? super MethodDescription> methodMatcher,
Function<Advice.WithCustomMapping, Advice.WithCustomMapping> mappingCustomizer,
UnaryOperator<Advice.WithCustomMapping> mappingCustomizer,
String adviceClassName) {
adviceClassNames.add(adviceClassName);
}
Expand Down
Loading