Skip to content

Commit

Permalink
avoid using ExecutionContextImpl on executor advice
Browse files Browse the repository at this point in the history
  • Loading branch information
ivantopo committed Jun 27, 2023
1 parent fc7a137 commit 5a488d8
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
import scala.concurrent.ExecutionContext;
import scala.concurrent.impl.ExecutionContextImpl;

import java.lang.reflect.Method;
import java.util.concurrent.ExecutorService;

import static kanela.agent.libs.net.bytebuddy.implementation.bytecode.assign.Assigner.Typing.DYNAMIC;

final class ScalaGlobalExecutionContextAdvice {

@Advice.OnMethodExit
public static void onExit(@Advice.Return(readOnly = false, typing = DYNAMIC) ExecutionContextImpl returnValue) {
ExecutorService instrumented = ExecutorInstrumentation.instrument((ExecutorService) returnValue.executor(), "scala-global-execution-context");
public static void onExit(@Advice.Return(readOnly = false, typing = DYNAMIC) Object returnValue) throws Exception {
// Not ideal to go through reflection but this code will only be executed once in the lifetime of the JVM
Method executorMethod = returnValue.getClass().getDeclaredMethod("executor");
ExecutorService executor = (ExecutorService) executorMethod.invoke(returnValue);

ExecutorService instrumented = ExecutorInstrumentation.instrument(executor, "scala-global-execution-context");
returnValue = new ExecutionContextImpl(instrumented, ExecutionContext.defaultReporter());
}
}

0 comments on commit 5a488d8

Please sign in to comment.