Skip to content

Commit

Permalink
Use english comment (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
glmapper authored and caojie09 committed Apr 11, 2019
1 parent cf68585 commit 2a0a3f2
Show file tree
Hide file tree
Showing 154 changed files with 1,236 additions and 1,466 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class StatementInterceptorChainImpl extends BaseStatementInterceptorChain {
super(sql, sql, invocation);
}

@Override
protected void beforeInvoke(Invocation invocation) {
invocation.getArgs()[0] = getProcessingSql();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.alipay.common.tracer.core.utils.StringUtils;
import com.alipay.sofa.tracer.plugins.datasource.tracer.*;
import com.alipay.sofa.tracer.plugins.datasource.utils.DataSourceUtils;
import com.alipay.sofa.tracer.plugins.datasource.tracer.Endpoint;

import javax.sql.DataSource;
import java.util.ArrayList;
Expand Down Expand Up @@ -93,6 +92,7 @@ public List<KeyValueAnnotation> getTraceAnnotations() {
/**
* init method must be invoked first after construction
*/
@Override
public void init() {
if (initialized.compareAndSet(false, true)) {
if (StringUtils.isBlank(dbType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
statKey.setEnd(TracerUtils.getLoadTestMark(sofaTracerSpan));
//value the count and duration
long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime();
long values[] = new long[] { 1, duration };
long[] values = new long[] { 1, duration };
//reserve
this.addStat(statKey, values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public static String resolveDatabaseFromUrl(String url) {
int start = url.lastIndexOf("/");
if (start < 0) {
/**
* oracle sid 格式,{@see jdbc:oracle:thin:@host:port:SID}
* oracle sid format,{@see jdbc:oracle:thin:@host:port:SID}
*/
if ("oracle".equals(resolveDbTypeFromUrl(url))) {
start = url.lastIndexOf(":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import static org.mockito.Mockito.when;

/**
* @author qilong.zql 18/8/27-上午9:23
* @author qilong.zql 18/8/27-AM 9:23
*/
public class DruidTest extends BaseTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,23 @@
@Activate(group = { Constants.PROVIDER, Constants.CONSUMER }, value = "dubboSofaTracerFilter", order = 1)
public class DubboSofaTracerFilter implements Filter {

private String appName = StringUtils.EMPTY_STRING;
private String appName = StringUtils.EMPTY_STRING;

private static final String BLANK = StringUtils.EMPTY_STRING;
private static final String BLANK = StringUtils.EMPTY_STRING;

private static final String SUCCESS_CODE = "00";
private static final String SUCCESS_CODE = "00";

private static final String FAILED_CODE = "99";
private static final String FAILED_CODE = "99";

private static final String SPAN_INVOKE_KEY = "sofa.current.span.key";
private static final String TIME_OUT_ERROR_CODE = "03";

private static final String SPAN_INVOKE_KEY = "sofa.current.span.key";

private DubboConsumerSofaTracer dubboConsumerSofaTracer;

private DubboProviderSofaTracer dubboProviderSofaTracer;

private static Map<String, SofaTracerSpan> TracerSpanMap = new ConcurrentHashMap<String, SofaTracerSpan>();
private static Map<String, SofaTracerSpan> TracerSpanMap = new ConcurrentHashMap<String, SofaTracerSpan>();

@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
Expand Down Expand Up @@ -90,7 +92,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
public Result onResponse(Result result, Invoker<?> invoker, Invocation invocation) {
String spanKey = getTracerSpanMapKey(invoker);
try {
// 只有异步才进行回调打印
// only the asynchronous callback to print
boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation);
if (!isAsync) {
return result;
Expand Down Expand Up @@ -206,17 +208,17 @@ private Result doClientFilter(RpcContext rpcContext, Invoker<?> invoker, Invocat
// Record client send event
sofaTracerSpan.log(LogData.CLIENT_SEND_EVENT_VALUE);
}
// 将当前 span 缓存
// cache the current span
TracerSpanMap.put(getTracerSpanMapKey(invoker), sofaTracerSpan);
if (clientSpan != null && clientSpan.getParentSofaTracerSpan() != null) {
//restore parent
sofaTraceContext.push(clientSpan.getParentSofaTracerSpan());
}
CompletableFuture<Object> future = (CompletableFuture<Object>) RpcContext.getContext().getFuture();
future.whenComplete((object, throwable)-> {
if (throwable != null && throwable instanceof TimeoutException) {
if (throwable instanceof TimeoutException) {
sofaTracerSpan.setTag(Tags.ERROR.getKey(),throwable.getMessage());
dubboConsumerSofaTracer.clientReceiveTagFinish(sofaTracerSpan, "03");
dubboConsumerSofaTracer.clientReceiveTagFinish(sofaTracerSpan, TIME_OUT_ERROR_CODE);
}
});
}
Expand All @@ -242,7 +244,6 @@ private Result doServerFilter(RpcContext rpcContext, Invoker<?> invoker, Invocat
Throwable exception = null;
try {
result = invoker.invoke(invocation);
// 处理返回结果
if (result == null) {
return null;
} else {
Expand Down Expand Up @@ -277,7 +278,6 @@ private Result doServerFilter(RpcContext rpcContext, Invoker<?> invoker, Invocat

private SofaTracerSpan serverReceived(Invocation invocation) {
Map<String, String> tags = new HashMap<String, String>();
//server tags 必须设置
tags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);
String serializeSpanContext = invocation.getAttachments()
.get(CommonSpanTags.RPC_TRACE_NAME);
Expand Down Expand Up @@ -305,7 +305,6 @@ private SofaTracerSpan serverReceived(Invocation invocation) {
SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
// Record server receive event
serverSpan.log(LogData.SERVER_RECV_EVENT_VALUE);
// 放到线程上下文
sofaTraceContext.push(serverSpan);
return serverSpan;
}
Expand All @@ -322,10 +321,10 @@ private void appendElapsedTimeTags(Invocation invocation, SofaTracerSpan sofaTra
if (isClient) {
elapsed = invocation.getAttachment(CommonSpanTags.CLIENT_SERIALIZE_TIME);
deElapsed = invocation.getAttachment(CommonSpanTags.CLIENT_DESERIALIZE_TIME);
//客户端请求序列化耗时
//The client request serialization time-consuming
sofaTracerSpan
.setTag(CommonSpanTags.CLIENT_SERIALIZE_TIME, parseAttachment(elapsed, 0));
//客户端接受响应反序列化耗时
//The client accepted response deserialization time-consuming
sofaTracerSpan.setTag(CommonSpanTags.CLIENT_DESERIALIZE_TIME,
parseAttachment(deElapsed, 0));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
String methodName = tagsWithStr.get(CommonSpanTags.METHOD);
statKey.setKey(buildString(new String[] { fromApp, toApp, serviceName, methodName }));
String resultCode = tagsWithStr.get(CommonSpanTags.RESULT_CODE);
statKey.setResult(resultCode.equals("00") ? "Y" : "N");
statKey.setResult("00".equals(resultCode) ? "Y" : "N");
statKey.setEnd(buildString(new String[] { getLoadTestMark(sofaTracerSpan) }));
statKey.setLoadTest(TracerUtils.isLoadTest(sofaTracerSpan));
statKey.addKey(CommonSpanTags.LOCAL_APP, fromApp);
statKey.addKey(CommonSpanTags.REMOTE_APP, toApp);
statKey.addKey(CommonSpanTags.SERVICE, serviceName);
statKey.addKey(CommonSpanTags.METHOD, methodName);
//次数和耗时,最后一个耗时是单独打印的字段
long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime();
long[] values = new long[] { 1, duration };
this.addStat(statKey, values);
Expand All @@ -82,7 +81,7 @@ protected String getLoadTestMark(SofaTracerSpan span) {
@Override
public void print(StatKey statKey, long[] values) {
if (this.isClosePrint.get()) {
//关闭统计日志输出
//Close the statistics log output
return;
}

Expand All @@ -102,7 +101,7 @@ public void print(StatKey statKey, long[] values) {
} else {
appender.append(jsonBuffer.toString());
}
// 这里强制刷一次
// Forced to flush
appender.flush();
} catch (Throwable t) {
SelfLog.error("stat log<" + statTracerName + "> error!", t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
String methodName = tagsWithStr.get(CommonSpanTags.METHOD);
statKey.setKey(buildString(new String[] { fromApp, toApp, serviceName, methodName }));
String resultCode = tagsWithStr.get(CommonSpanTags.RESULT_CODE);
statKey.setResult(resultCode.equals("00") ? "Y" : "N");
statKey.setResult("00".equals(resultCode) ? "Y" : "N");
statKey.setEnd(buildString(new String[] { getLoadTestMark(sofaTracerSpan) }));
statKey.setLoadTest(TracerUtils.isLoadTest(sofaTracerSpan));
statKey.addKey(CommonSpanTags.LOCAL_APP, fromApp);
Expand All @@ -82,7 +82,7 @@ protected String getLoadTestMark(SofaTracerSpan span) {
@Override
public void print(StatKey statKey, long[] values) {
if (this.isClosePrint.get()) {
//关闭统计日志输出
//Close the statistics log output
return;
}

Expand All @@ -102,7 +102,7 @@ public void print(StatKey statKey, long[] values) {
} else {
appender.append(jsonBuffer.toString());
}
// 这里强制刷一次
// Forced to flush
appender.flush();
} catch (Throwable t) {
SelfLog.error("stat log <" + statTracerName + "> error!", t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,21 @@ public void encode(Channel channel, ChannelBuffer buffer, Object message) throws
return;
}
}
// 其它走原来
codec.encode(channel, buffer, message);
}

/**
* @param channel 长连接
* @param buffer UnsafeByteArrayOutputStream
* @param message 原生Request对象
* @param invocation Request里的Invocation
* @throws IOException 序列化出现异常
* @param channel a long connection
* @param buffer buffer
* @param message the original Request object
* @param invocation Invocation in Request
* @throws IOException serialization exception
*/
protected void encodeRequestWithTracer(Channel channel, ChannelBuffer buffer, Object message,
RpcInvocation invocation) throws IOException {
long startTime = System.currentTimeMillis();
int index = buffer.writerIndex();
// 序列化
// serialization
codec.encode(channel, buffer, message);
int reqSize = buffer.writerIndex() - index;
long elapsed = System.currentTimeMillis() - startTime;
Expand All @@ -82,11 +81,11 @@ protected void encodeRequestWithTracer(Channel channel, ChannelBuffer buffer, Ob
}

/**
* @param channel 长连接
* @param buffer UnsafeByteArrayOutputStream
* @param result 原生Resopnse对象
* @param rpcResult Resopnse对象的结果
* @throws IOException 序列化出现异常
* @param channel a long connection
* @param buffer buffer
* @param result the original Request object
* @param rpcResult result of Response
* @throws IOException serialization exception
*/
protected void encodeResultWithTracer(Channel channel, ChannelBuffer buffer, Object result,
RpcResult rpcResult) throws IOException {
Expand All @@ -101,7 +100,7 @@ protected void encodeResultWithTracer(Channel channel, ChannelBuffer buffer, Obj
}

/**
* 反序列化操作
* deserialization operation
* @param channel
* @param input
* @return
Expand All @@ -115,7 +114,7 @@ public Object decode(Channel channel, ChannelBuffer input) throws IOException {
int size = input.readerIndex() - index;
long elapsed = System.currentTimeMillis() - startTime;
if (ret instanceof Request) {
// 服务端反序列化Request
// server-side deserialize the Request
Object data = ((Request) ret).getData();
if (data instanceof RpcInvocation) {
RpcInvocation invocation = (RpcInvocation) data;
Expand All @@ -125,7 +124,7 @@ public Object decode(Channel channel, ChannelBuffer input) throws IOException {
}

} else if (ret instanceof Response) {
// 客户端反序列化Response
// client-side deserialize the Response
Object result = ((Response) ret).getResult();
if (result instanceof RpcResult) {
RpcResult rpcResult = (RpcResult) result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,24 @@ public void testBefore() throws Exception {
// registry
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("N/A");
// 服务提供者协议配置
// protocolConfig
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("dubbo");
protocol.setThreadpool("fixed");
protocol.setPort(12280);
protocol.setSerialization("hessian2");
// 服务提供者连接注册中心,设置属性
DubboServiceImpl dubboServiceImpl = new DubboServiceImpl();
ServiceConfig<DubboService> service = new ServiceConfig<DubboService>();
ServiceConfig<DubboService> service = new ServiceConfig<>();
service.setApplication(application);
service.setProtocol(protocol); // 多个协议可以用setProtocols()
//Multiple protocols can be used with setProtocols()
service.setProtocol(protocol);
service.setInterface(DubboService.class.getName());
service.setRef(dubboServiceImpl);
service.setGroup("tracer");
service.setVersion("1.0");
service.setFilter("dubboSofaTracerFilter");
service.setRegistry(registryConfig);
//services.setRegister(false);
// 暴露及注册服务
// Exposure and registration services
service.export();
List<URL> exportedUrls = service.getExportedUrls();
Assert.assertTrue(exportedUrls.size() == 1);
Expand All @@ -80,8 +79,8 @@ public void testBefore() throws Exception {
public void testTracer() throws Exception {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("N/A");
// 服务调用者连接注册中心,设置属性
ReferenceConfig<DubboService> reference = new ReferenceConfig<DubboService>(); // 此实例很重,封装了与注册中心的连接以及与提供者的连接,请自行缓存,否则可能造成内存和连接泄漏
//The service caller connects to the registry and sets the properties.
ReferenceConfig<DubboService> reference = new ReferenceConfig<>();
reference.setInterface(DubboService.class);
reference.setRegistry(registryConfig);
reference.setUrl(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
statKey.setEnd(TracerUtils.getLoadTestMark(sofaTracerSpan));
//value the count and duration
long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime();
long values[] = new long[] { 1, duration };
long[] values = new long[] { 1, duration };
//reserve
this.addStat(statKey, values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public abstract class AbstractHttpRequestInterceptor {

protected AbstractTracer httpClientTracer;

protected String appName = null;
protected String appName;

protected String targetAppName = null;
protected String targetAppName;

public AbstractHttpRequestInterceptor(AbstractTracer httpClientTracer, String appName,
String targetAppName) {
Expand All @@ -68,7 +68,6 @@ public void appendHttpClientRequestSpanTags(HttpRequest httpRequest,
//targetAppName
httpClientSpan.setTag(CommonSpanTags.REMOTE_APP,
this.targetAppName == null ? StringUtils.EMPTY_STRING : this.targetAppName);
//url ((HttpRequestWrapper) request).getOriginal().getRequestLine().getUri()
if (httpRequest instanceof HttpRequestWrapper) {
HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper) httpRequest;
httpClientSpan.setTag(CommonSpanTags.REQUEST_URL, httpRequestWrapper.getOriginal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
statKey.setEnd(TracerUtils.getLoadTestMark(sofaTracerSpan));
//value the count and duration
long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime();
long values[] = new long[] { 1, duration };
long[] values = new long[] { 1, duration };
//reserve
this.addStat(statKey, values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
*/
public class SofaTracerOkHttpInterceptor implements okhttp3.Interceptor {

protected String appName = null;
protected String appName;

protected String targetAppName = null;
protected String targetAppName;

protected AbstractTracer okHttpTracer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
statKey.setEnd(TracerUtils.getLoadTestMark(sofaTracerSpan));
//value the count and duration
long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime();
long values[] = new long[] { 1, duration };
long[] values = new long[] { 1, duration };
//reserve
this.addStat(statKey, values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static AsyncRestTemplate buildAsyncRestTemplate() {
return asyncRestTemplate;
}

public synchronized static AbstractTracer getRestTemplateTracer() {
public static AbstractTracer getRestTemplateTracer() {
if (restTemplateTracer == null) {
synchronized (RestTemplateTracer.class) {
if (restTemplateTracer == null) {
Expand Down
Loading

0 comments on commit 2a0a3f2

Please sign in to comment.