Cleaner way to skip netty executor's tasks

This commit is contained in:
Laplie Anderson 2020-01-23 12:04:56 -05:00
parent 68e52497d6
commit 8ff985afdb
1 changed files with 22 additions and 16 deletions

View File

@ -26,11 +26,24 @@ public class ExecutorInstrumentationUtils {
* @return true iff given task object should be wrapped
*/
public static boolean shouldAttachStateToTask(final Object task, final Executor executor) {
if (task == null) {
return false;
}
final TraceScope scope = activeScope();
return (scope != null
final Class enclosingClass = task.getClass().getEnclosingClass();
return scope != null
&& scope.isAsyncPropagating()
&& task != null
&& !ExecutorInstrumentationUtils.isExecutorDisabledForThisTask(executor, task));
&& !ExecutorInstrumentationUtils.isExecutorDisabledForThisTask(executor, task)
// Don't instrument the executor's own runnables. These runnables may never return until
// netty shuts down. Any created continuations will be open until that time preventing
// traces from being reported
&& (enclosingClass == null
|| !enclosingClass
.getName()
.equals("io.netty.util.concurrent.SingleThreadEventExecutor"));
}
/**
@ -47,20 +60,13 @@ public class ExecutorInstrumentationUtils {
final State state = contextStore.putIfAbsent(task, State.FACTORY);
// Don't instrument the executor's own runnables. These runnables may never return until
// netty shuts down. Any created continuations will be open until that time preventing traces
// from being reported
if (!task.getClass()
.getName()
.startsWith("io.netty.util.concurrent.SingleThreadEventExecutor$")) {
final TraceScope.Continuation continuation = scope.capture();
if (state.setContinuation(continuation)) {
log.debug("created continuation {} from scope {}, state: {}", continuation, scope, state);
} else {
continuation.close(false);
}
final TraceScope.Continuation continuation = scope.capture();
if (state.setContinuation(continuation)) {
log.debug("created continuation {} from scope {}, state: {}", continuation, scope, state);
} else {
continuation.close(false);
}
return state;
}