1. 将各种BuriedPointType去掉构造函数,改成静态单例。

This commit is contained in:
zhangxin10 2016-01-12 10:01:42 +08:00
parent cbdd1d6f44
commit 72c9d15f09
13 changed files with 97 additions and 37 deletions

View File

@ -4,6 +4,17 @@ import com.ai.cloud.skywalking.api.IBuriedPointType;
import com.ai.cloud.skywalking.model.CallType;
public class DubboBuriedPointType implements IBuriedPointType {
private static DubboBuriedPointType dubboBuriedPointType;
public static IBuriedPointType instance() {
if (dubboBuriedPointType == null) {
dubboBuriedPointType = new DubboBuriedPointType();
}
return dubboBuriedPointType;
}
@Override
public String getTypeName() {
return "D";
@ -13,4 +24,9 @@ public class DubboBuriedPointType implements IBuriedPointType {
public CallType getCallType() {
return CallType.ASYNC;
}
private DubboBuriedPointType() {
//Non
}
}

View File

@ -4,6 +4,18 @@ import com.ai.cloud.skywalking.api.IBuriedPointType;
import com.ai.cloud.skywalking.model.CallType;
public class JDBCBuriedPointType implements IBuriedPointType {
private static JDBCBuriedPointType jdbcBuriedPointType;
public static IBuriedPointType instance() {
if (jdbcBuriedPointType == null) {
jdbcBuriedPointType = new JDBCBuriedPointType();
}
return jdbcBuriedPointType;
}
@Override
public String getTypeName() {
return "J";
@ -13,4 +25,8 @@ public class JDBCBuriedPointType implements IBuriedPointType {
public CallType getCallType() {
return CallType.LOCAL;
}
private JDBCBuriedPointType(){
//Non
}
}

View File

@ -5,6 +5,16 @@ import com.ai.cloud.skywalking.model.CallType;
public class SpringBuriedPointType implements IBuriedPointType {
private static SpringBuriedPointType springBuriedPointType;
public static IBuriedPointType instance() {
if (springBuriedPointType == null) {
springBuriedPointType = new SpringBuriedPointType();
}
return springBuriedPointType;
}
@Override
public String getTypeName() {
return "M";
@ -15,4 +25,8 @@ public class SpringBuriedPointType implements IBuriedPointType {
return CallType.LOCAL;
}
private SpringBuriedPointType() {
// Non
}
}

View File

@ -4,6 +4,17 @@ import com.ai.cloud.skywalking.api.IBuriedPointType;
import com.ai.cloud.skywalking.model.CallType;
public class WEBBuriedPointType implements IBuriedPointType {
private static WEBBuriedPointType webBuriedPointType;
public static IBuriedPointType instance() {
if (webBuriedPointType == null) {
webBuriedPointType = new WEBBuriedPointType();
}
return webBuriedPointType;
}
@Override
public String getTypeName() {
return "W";
@ -13,4 +24,8 @@ public class WEBBuriedPointType implements IBuriedPointType {
public CallType getCallType() {
return CallType.ASYNC;
}
private WEBBuriedPointType() {
// Non
}
}

View File

@ -102,7 +102,7 @@ public class SWDubboEnhanceFilter implements Filter {
}
viewPoint.append(")");
return Identification.newBuilder().viewPoint(viewPoint.toString()).spanType(new DubboBuriedPointType()).build();
return Identification.newBuilder().viewPoint(viewPoint.toString()).spanType(DubboBuriedPointType.instance()).build();
}

View File

@ -21,7 +21,7 @@ public class HttpClientTracing {
httpRequest.setHeader(traceHearName,
"ContextData=" + sender.beforeSend(Identification.newBuilder()
.viewPoint(url)
.spanType(new WEBBuriedPointType())
.spanType(WEBBuriedPointType.instance())
.build())
.toString());
return executor.execute();

View File

@ -21,7 +21,7 @@ public class HttpClientTracing {
httpRequest.setHeader(traceHearName,
"ContextData=" + sender.beforeSend(Identification.newBuilder()
.viewPoint(url)
.spanType(new WEBBuriedPointType())
.spanType(WEBBuriedPointType.instance())
.build())
.toString());
return executor.execute();

View File

@ -26,7 +26,7 @@ public class CallableStatementTracing {
"callableStatement."
+ method
+ (sql == null || sql.length() == 0 ? ""
: ":" + sql)).spanType(new JDBCBuriedPointType()).build());
: ":" + sql)).spanType(JDBCBuriedPointType.instance()).build());
return exec.exe(realStatement, sql);
} catch (SQLException e) {
sender.handleException(e);

View File

@ -26,7 +26,7 @@ public class ConnectionTracing {
"connection."
+ method
+ (sql == null || sql.length() == 0 ? ""
: ":" + sql)).spanType(new JDBCBuriedPointType()).build());
: ":" + sql)).spanType(JDBCBuriedPointType.instance()).build());
return exec.exe(realConnection, sql);
} catch (SQLException e) {
sender.handleException(e);

View File

@ -26,7 +26,7 @@ public class PreparedStatementTracing {
"preaparedStatement."
+ method
+ (sql == null || sql.length() == 0 ? ""
: ":" + sql)).spanType(new JDBCBuriedPointType()).build());
: ":" + sql)).spanType(JDBCBuriedPointType.instance()).build());
return exec.exe(realStatement, sql);
} catch (SQLException e) {
sender.handleException(e);

View File

@ -1,43 +1,42 @@
package com.ai.cloud.skywalking.plugin.jdbc.tracing;
import java.sql.SQLException;
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
import com.ai.cloud.skywalking.buriedpoint.type.JDBCBuriedPointType;
import com.ai.cloud.skywalking.model.Identification;
import java.sql.SQLException;
/**
* 连接级追踪用于追踪用于Statement的操作追踪
*
* @author wusheng
*
* @author wusheng
*/
public class StatementTracing {
private static RPCBuriedPointSender sender = new RPCBuriedPointSender();
private static RPCBuriedPointSender sender = new RPCBuriedPointSender();
public static <R> R execute(java.sql.Statement realStatement,
String connectInfo, String method, String sql, Executable<R> exec)
throws SQLException {
try {
sender.beforeSend(Identification
.newBuilder()
.viewPoint(connectInfo)
.businessKey(
"statement."
+ method
+ (sql == null || sql.length() == 0 ? ""
: ":" + sql)).spanType(new JDBCBuriedPointType()).build());
return exec.exe(realStatement, sql);
} catch (SQLException e) {
sender.handleException(e);
throw e;
} finally {
sender.afterSend();
}
}
public static <R> R execute(java.sql.Statement realStatement,
String connectInfo, String method, String sql, Executable<R> exec)
throws SQLException {
try {
sender.beforeSend(Identification
.newBuilder()
.viewPoint(connectInfo)
.businessKey(
"statement."
+ method
+ (sql == null || sql.length() == 0 ? ""
: ":" + sql)).spanType(JDBCBuriedPointType.instance()).build());
return exec.exe(realStatement, sql);
} catch (SQLException e) {
sender.handleException(e);
throw e;
} finally {
sender.afterSend();
}
}
public interface Executable<R> {
public R exe(java.sql.Statement realStatement, String sql)
throws SQLException;
}
public interface Executable<R> {
public R exe(java.sql.Statement realStatement, String sql)
throws SQLException;
}
}

View File

@ -25,7 +25,7 @@ public class TracingAspect {
viewPoint.append(arg.getClass().getName());
}
viewPoint.append(")");
_sender.beforeSend(Identification.newBuilder().viewPoint(viewPoint.toString()).spanType(new SpringBuriedPointType()).build());
_sender.beforeSend(Identification.newBuilder().viewPoint(viewPoint.toString()).spanType(SpringBuriedPointType.instance()).build());
return proceedingJoinPoint.proceed();
} catch (Throwable e) {
_sender.handleException(e);

View File

@ -71,7 +71,7 @@ public class SkyWalkingFilter implements Filter {
private Identification generateIdentification(HttpServletRequest request) {
return Identification.newBuilder()
.viewPoint(request.getRequestURL().toString())
.spanType(new WEBBuriedPointType())
.spanType(WEBBuriedPointType.instance())
.build();
}