Skip to content

Commit 18602c8

Browse files
committed
[#9595] Refactor AsyncState
1 parent affc700 commit 18602c8

File tree

7 files changed

+56
-67
lines changed

7 files changed

+56
-67
lines changed

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/AsyncContextUtils.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ private AsyncContextUtils() {
77
public static boolean asyncStateFinish(final AsyncContext asyncContext) {
88
if (asyncContext instanceof AsyncStateSupport) {
99
final AsyncStateSupport asyncStateSupport = (AsyncStateSupport) asyncContext;
10-
AsyncState asyncState = asyncStateSupport.getAsyncState();
11-
asyncState.finish();
10+
asyncStateSupport.finish();
1211
return true;
1312
}
1413
return false;

bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/AsyncStateSupport.java

+4
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@
2323
*/
2424
@InterfaceAudience.LimitedPrivate("vert.x")
2525
public interface AsyncStateSupport {
26+
@Deprecated
2627
AsyncState getAsyncState();
28+
29+
void finish();
30+
2731
}

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/StatefulAsyncContext.java

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public AsyncState getAsyncState() {
4444
return asyncState;
4545
}
4646

47+
@Override
48+
public void finish() {
49+
this.asyncState.finish();
50+
}
51+
4752
@Override
4853
public String toString() {
4954
return "StatefulAsyncContext{" +

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/StatefulDisableAsyncContext.java

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public AsyncState getAsyncState() {
2222
return asyncState;
2323
}
2424

25+
@Override
26+
public void finish() {
27+
this.asyncState.finish();
28+
}
29+
2530
@Override
2631
public String toString() {
2732
return "StatefulDisableAsyncContext{" +

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultRecorderFactory.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,39 @@ public DefaultRecorderFactory(Provider<AsyncContextFactory> asyncContextFactoryP
5151

5252
@Override
5353
public SpanRecorder newSpanRecorder(Span span) {
54+
Objects.requireNonNull(span, "span");
55+
5456
return new DefaultSpanRecorder(span, stringMetaDataService, sqlMetaDataService, errorHandler);
5557
}
5658

5759
@Override
5860
public SpanRecorder newTraceRootSpanRecorder(TraceRoot traceRoot) {
61+
Objects.requireNonNull(traceRoot, "traceRoot");
62+
5963
return new TraceRootSpanRecorder(traceRoot);
6064
}
6165

6266
@Override
6367
public SpanRecorder newDisableSpanRecorder(LocalTraceRoot traceRoot) {
68+
Objects.requireNonNull(traceRoot, "traceRoot");
69+
6470
return new DisableSpanRecorder(traceRoot, errorHandler);
6571
}
6672

6773
@Override
6874
public WrappedSpanEventRecorder newWrappedSpanEventRecorder(TraceRoot traceRoot) {
75+
Objects.requireNonNull(traceRoot, "traceRoot");
76+
6977
final AsyncContextFactory asyncContextFactory = asyncContextFactoryProvider.get();
7078
return new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler);
7179
}
7280

7381
@Override
7482
public WrappedSpanEventRecorder newWrappedSpanEventRecorder(TraceRoot traceRoot, AsyncState asyncState) {
83+
Objects.requireNonNull(traceRoot, "traceRoot");
7584
Objects.requireNonNull(asyncState, "asyncState");
7685

7786
final AsyncContextFactory asyncContextFactory = asyncContextFactoryProvider.get();
78-
return new WrappedAsyncSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler, asyncState);
87+
return new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, asyncState, stringMetaDataService, sqlMetaDataService, errorHandler);
7988
}
8089
}

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/WrappedAsyncSpanEventRecorder.java

-60
This file was deleted.

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/WrappedSpanEventRecorder.java

+31-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818

1919
import com.navercorp.pinpoint.bootstrap.context.AsyncContext;
20+
import com.navercorp.pinpoint.bootstrap.context.AsyncState;
2021
import com.navercorp.pinpoint.bootstrap.context.ParsingResult;
2122
import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder;
2223
import com.navercorp.pinpoint.common.trace.AnnotationKey;
@@ -38,6 +39,7 @@
3839
import org.apache.logging.log4j.LogManager;
3940
import org.apache.logging.log4j.Logger;
4041

42+
import javax.annotation.Nullable;
4143
import java.util.Objects;
4244

4345
/**
@@ -49,18 +51,34 @@ public class WrappedSpanEventRecorder extends AbstractRecorder implements SpanEv
4951
private static final Logger logger = LogManager.getLogger(DefaultTrace.class.getName());
5052
private static final boolean isDebug = logger.isDebugEnabled();
5153

52-
protected final TraceRoot traceRoot;
53-
protected final AsyncContextFactory asyncContextFactory;
54+
private final TraceRoot traceRoot;
55+
private final AsyncContextFactory asyncContextFactory;
56+
@Nullable
57+
private final AsyncState asyncState;
5458

5559
private SpanEvent spanEvent;
5660

57-
public WrappedSpanEventRecorder(TraceRoot traceRoot, AsyncContextFactory asyncContextFactory,
58-
final StringMetaDataService stringMetaDataService, final SqlMetaDataService sqlMetaCacheService,
61+
public WrappedSpanEventRecorder(TraceRoot traceRoot,
62+
AsyncContextFactory asyncContextFactory,
63+
StringMetaDataService stringMetaDataService,
64+
SqlMetaDataService sqlMetaDataService,
65+
IgnoreErrorHandler ignoreErrorHandler) {
66+
67+
this(traceRoot, asyncContextFactory, null, stringMetaDataService, sqlMetaDataService, ignoreErrorHandler);
68+
}
69+
70+
public WrappedSpanEventRecorder(TraceRoot traceRoot,
71+
AsyncContextFactory asyncContextFactory,
72+
@Nullable
73+
final AsyncState asyncState,
74+
final StringMetaDataService stringMetaDataService,
75+
final SqlMetaDataService sqlMetaCacheService,
5976
final IgnoreErrorHandler errorHandler) {
6077
super(stringMetaDataService, sqlMetaCacheService, errorHandler);
6178
this.traceRoot = Objects.requireNonNull(traceRoot, "traceRoot");
6279

6380
this.asyncContextFactory = Objects.requireNonNull(asyncContextFactory, "asyncContextFactory");
81+
this.asyncState = asyncState;
6482
}
6583

6684
public void setWrapped(final SpanEvent spanEvent) {
@@ -137,6 +155,15 @@ protected boolean isOverflowState() {
137155

138156
@Override
139157
public AsyncContext recordNextAsyncContext(boolean asyncStateSupport) {
158+
if (asyncStateSupport && asyncState != null) {
159+
final TraceRoot traceRoot = this.traceRoot;
160+
final AsyncId asyncIdObject = getNextAsyncId();
161+
final boolean isDisabled = isOverflowState();
162+
163+
final AsyncState asyncState = this.asyncState;
164+
asyncState.setup();
165+
return asyncContextFactory.newAsyncContext(traceRoot, asyncIdObject, isDisabled, asyncState);
166+
}
140167
return recordNextAsyncContext();
141168
}
142169

0 commit comments

Comments
 (0)