提交 1ae04cf2 编写于 作者: Q qxo 提交者: wu-sheng

improve AsyncSpan API: make #asyncFinish and #prepareForAsync can not invoke more than once (#3201)

* improve AsyncSpan API: make #asyncFinish and #prepareForAsync can not invoke more than once
make the API more strong: make the plugin code bug fail-fast
上级 c139316b
......@@ -40,7 +40,14 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
protected String operationName;
protected int operationId;
protected SpanLayer layer;
protected boolean isInAsyncMode = false;
/**
* The span has been tagged in async mode, required async stop to finish.
*/
protected volatile boolean isInAsyncMode = false;
/**
* The flag represents whether the span has been async stopped
*/
private volatile boolean isAsyncStopped = false;
protected volatile AbstractTracerContext context;
/**
......@@ -322,6 +329,9 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
}
@Override public AbstractSpan prepareForAsync() {
if (isInAsyncMode) {
throw new RuntimeException("Prepare for async repeatedly. Span is already in async mode.");
}
context = ContextManager.awaitFinishAsync(this);
isInAsyncMode = true;
return this;
......@@ -331,9 +341,12 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
if (!isInAsyncMode) {
throw new RuntimeException("Span is not in async mode, please use '#prepareForAsync' to active.");
}
if (isAsyncStopped) {
throw new RuntimeException("Can not do async finish for the span repeately.");
}
this.endTime = System.currentTimeMillis();
context.asyncStop(this);
isAsyncStopped = true;
return this;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册