Skip to content

Commit

Permalink
Refactor InstanceMethodHandler in agent (apache#2905)
Browse files Browse the repository at this point in the history
  • Loading branch information
JooKS-me authored Feb 20, 2022
1 parent 95b70f1 commit 8f53662
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ default void before(final TargetObject target, final Method method, final Object
* @param method the method
* @param args the args
* @param methodResult {@linkplain MethodResult}
* @param result the result
* @return result
*/
default Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult, final Object result) {
return result;
default Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult) {
return methodResult.getResult();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public Object intercept(@This final Object target, @Origin final Method method,
LOG.error("Failed to execute the before method of method {} in class {}", method.getName(), target.getClass(), ex);
}
try {
result = callable.call();
if (!methodResult.isReset()) {
methodResult.reset(callable.call());
}
// CHECKSTYLE:OFF
} catch (final Throwable ex) {
// CHECKSTYLE:ON
Expand All @@ -89,7 +91,7 @@ public Object intercept(@This final Object target, @Origin final Method method,
}
} finally {
try {
result = handler.after(instance, method, args, methodResult, result);
result = handler.after(instance, method, args, methodResult);
// CHECKSTYLE:OFF
} catch (final Throwable ex) {
// CHECKSTYLE:ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public class RocketMQGlobalPluginHandler implements InstanceMethodHandler {

@Override
public Object after(final TargetObject target, final Method method, final Object[] args,
final MethodResult methodResult, final Object result) {
final MethodResult methodResult) {
Object result = methodResult.getResult();
ServerWebExchange exchange = (ServerWebExchange) result;
ServerHttpRequest request = exchange.getRequest();
ServerHttpResponse response = exchange.getResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public void before(final TargetObject target, final Method method, final Object[
}

@Override
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult, final Object result) {
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult) {
Object result = methodResult.getResult();
Span span = (Span) target.getContext();
ServerWebExchange exchange = (ServerWebExchange) args[0];
JaegerSpanManager manager = (JaegerSpanManager) exchange.getAttributes().get(JaegerConstants.ROOT_SPAN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void before(final TargetObject target, final Method method, final Object[
}

@Override
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult, final Object result) {
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult) {
Object result = methodResult.getResult();
Span span = (Span) target.getContext();
ServerWebExchange exchange = (ServerWebExchange) args[0];
JaegerSpanManager manager = (JaegerSpanManager) exchange.getAttributes().get(JaegerConstants.ROOT_SPAN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public void before(final TargetObject target, final Method method, final Object[
}

@Override
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult, final Object result) {
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult) {
Object result = methodResult.getResult();
Span span = (Span) target.getContext();
ServerWebExchange exchange = (ServerWebExchange) args[0];
OpenTelemetrySpanManager manager = (OpenTelemetrySpanManager) exchange.getAttributes().get(TracingConstants.SHENYU_AGENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void before(final TargetObject target, final Method method, final Object[
}

@Override
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult, final Object result) {
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult) {
Object result = methodResult.getResult();
Span span = (Span) target.getContext();
ServerWebExchange exchange = (ServerWebExchange) args[0];
OpenTelemetrySpanManager manager = (OpenTelemetrySpanManager) exchange.getAttributes().get(TracingConstants.SHENYU_AGENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void before(final TargetObject target, final Method method, final Object[
}

@Override
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult, final Object result) {
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult) {
Object result = methodResult.getResult();
Span span = (Span) target.getContext();
ServerWebExchange exchange = (ServerWebExchange) args[0];
ZipkinSpanManager manager = (ZipkinSpanManager) exchange.getAttributes().get(TracingConstants.SHENYU_AGENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public void before(final TargetObject target, final Method method, final Object[
}

@Override
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult, final Object result) {
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult) {
Object result = methodResult.getResult();
Span span = (Span) target.getContext();
ServerWebExchange exchange = (ServerWebExchange) args[0];
ZipkinSpanManager manager = (ZipkinSpanManager) exchange.getAttributes().get(TracingConstants.SHENYU_AGENT);
Expand Down

0 comments on commit 8f53662

Please sign in to comment.