From d65b68ee4d854d3b974ff8a18fc4198011550835 Mon Sep 17 00:00:00 2001 From: emeroad Date: Mon, 5 Oct 2015 21:15:55 +0900 Subject: [PATCH] replace varargs type api -> Object[] --- .../bootstrap/instrument/InstrumentClass.java | 27 +++++--- .../instrument/InstrumentMethod.java | 16 +++-- .../PinpointClassFileTransformers.java | 2 +- .../pinpoint/common/util/VarArgs.java | 26 ++++++++ .../pinpoint/plugin/arcus/ArcusPlugin.java | 8 ++- .../plugin/jdbc/cubrid/CubridPlugin.java | 6 +- .../plugin/httpclient4/HttpClient4Plugin.java | 10 +-- .../pinpoint/plugin/ibatis/IBatisPlugin.java | 5 +- .../plugin/jackson/JacksonPlugin.java | 32 ++++++---- .../pinpoint/plugin/jetty/JettyPlugin.java | 4 +- .../plugin/json_lib/JsonLibPlugin.java | 2 +- .../pinpoint/plugin/jdbc/jtds/JtdsPlugin.java | 6 +- .../plugin/jdbc/mysql/MySqlPlugin.java | 6 +- .../pinpoint/plugin/okhttp/OkHttpPlugin.java | 8 ++- .../plugin/jdbc/oracle/OraclePlugin.java | 6 +- .../pinpoint/plugin/redis/RedisPlugin.java | 6 +- .../spring/beans/BeanMethodTransformer.java | 4 +- .../spring/beans/SpringBeansPlugin.java | 6 +- .../plugin/spring/web/SpringWebMvcPlugin.java | 5 +- .../pinpoint/plugin/thrift/ThriftPlugin.java | 6 +- .../pinpoint/plugin/tomcat/TomcatPlugin.java | 4 +- .../profiler/instrument/JavassistClass.java | 63 +++++++++++++------ .../profiler/instrument/JavassistMethod.java | 25 ++++++-- .../AnnotatedInterceptorInjector.java | 2 +- .../plugin/DefaultClassEditorBuilderTest.java | 5 +- 25 files changed, 204 insertions(+), 86 deletions(-) create mode 100644 commons/src/main/java/com/navercorp/pinpoint/common/util/VarArgs.java diff --git a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/InstrumentClass.java b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/InstrumentClass.java index f52fd60b0f70..776e88b1c3c7 100644 --- a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/InstrumentClass.java +++ b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/InstrumentClass.java @@ -70,16 +70,27 @@ public interface InstrumentClass { void addField(String accessorTypeName, String initValExp) throws InstrumentException; void addGetter(String getterTypeName, String fieldName) throws InstrumentException; - - int addInterceptor(String interceptorClassName, Object... constructorArgs) throws InstrumentException; - - int addInterceptor(MethodFilter filter, String interceptorClassName, Object... constructorArgs) throws InstrumentException; - int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, Object... constructorArgs) throws InstrumentException; - int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object... constructorArgs) throws InstrumentException; - - int addGroupedInterceptor(MethodFilter filter, String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object... constructorArgs) throws InstrumentException; + int addInterceptor(String interceptorClassName) throws InstrumentException; + + int addInterceptor(String interceptorClassName, Object[] constructorArgs) throws InstrumentException; + + int addInterceptor(MethodFilter filter, String interceptorClassName) throws InstrumentException; + + int addInterceptor(MethodFilter filter, String interceptorClassName, Object[] constructorArgs) throws InstrumentException; + + int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group) throws InstrumentException; + + int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException; + + int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group) throws InstrumentException; + + int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException; + + int addGroupedInterceptor(MethodFilter filter, String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException; + + int addGroupedInterceptor(MethodFilter filter, String interceptorClassName, Object[] constructorArgs, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException; /** * You should check that class already have Declared method. diff --git a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/InstrumentMethod.java b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/InstrumentMethod.java index b3fb316f3fb9..977893940b57 100644 --- a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/InstrumentMethod.java +++ b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/InstrumentMethod.java @@ -35,12 +35,18 @@ public interface InstrumentMethod { boolean isConstructor(); MethodDescriptor getDescriptor(); - - int addInterceptor(String interceptorClassName, Object... constructorArgs) throws InstrumentException; - - int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, Object... constructorArgs) throws InstrumentException; - int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object... constructorArgs) throws InstrumentException; + int addInterceptor(String interceptorClassName) throws InstrumentException; + + int addInterceptor(String interceptorClassName, Object[] constructorArgs) throws InstrumentException; + + int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group) throws InstrumentException; + + int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException; + + int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group) throws InstrumentException; + + int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException; void addInterceptor(int interceptorId) throws InstrumentException; } diff --git a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/transformer/PinpointClassFileTransformers.java b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/transformer/PinpointClassFileTransformers.java index 360ea3fb35fe..a6efa6a4639d 100644 --- a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/transformer/PinpointClassFileTransformers.java +++ b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/instrument/transformer/PinpointClassFileTransformers.java @@ -26,7 +26,7 @@ */ public class PinpointClassFileTransformers { - public static PinpointClassFileTransformer addInterceptor(final String interceptorClassName, final Object... constructorArgs) { + public static PinpointClassFileTransformer addInterceptor(final String interceptorClassName, final Object[] constructorArgs) { return new PinpointClassFileTransformer() { @Override diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/util/VarArgs.java b/commons/src/main/java/com/navercorp/pinpoint/common/util/VarArgs.java new file mode 100644 index 000000000000..2cfc47689d50 --- /dev/null +++ b/commons/src/main/java/com/navercorp/pinpoint/common/util/VarArgs.java @@ -0,0 +1,26 @@ +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.common.util; + +public final class VarArgs { + private VarArgs() { + } + + public static T[] va(T... args) { + return args; + } +} diff --git a/plugins/arcus/src/main/java/com/navercorp/pinpoint/plugin/arcus/ArcusPlugin.java b/plugins/arcus/src/main/java/com/navercorp/pinpoint/plugin/arcus/ArcusPlugin.java index 2a3da0bb28c0..0553b86eb663 100644 --- a/plugins/arcus/src/main/java/com/navercorp/pinpoint/plugin/arcus/ArcusPlugin.java +++ b/plugins/arcus/src/main/java/com/navercorp/pinpoint/plugin/arcus/ArcusPlugin.java @@ -29,6 +29,8 @@ import com.navercorp.pinpoint.plugin.arcus.filter.ArcusMethodFilter; import com.navercorp.pinpoint.plugin.arcus.filter.FrontCacheMemcachedMethodFilter; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * * @author jaehong.kim @@ -89,7 +91,7 @@ public byte[] transform(Instrumentor context, ClassLoader loader, String classNa for (InstrumentMethod m : target.getDeclaredMethods(new ArcusMethodFilter())) { try { - m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", traceKey); + m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", va(traceKey)); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("Unsupported method " + className + "." + m.getName(), e); @@ -165,7 +167,7 @@ public byte[] transform(Instrumentor context, ClassLoader loader, String classNa for (InstrumentMethod m : target.getDeclaredMethods(new FrontCacheMemcachedMethodFilter())) { try { - m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", traceKey); + m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", va(traceKey)); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("Unsupported method " + className + "." + m.getName(), e); @@ -195,7 +197,7 @@ public byte[] transform(Instrumentor context, ClassLoader loader, String classNa for (InstrumentMethod m : target.getDeclaredMethods(new FrontCacheMemcachedMethodFilter())) { try { - m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", traceKey); + m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", va(traceKey)); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("Unsupported method " + className + "." + m.getName(), e); diff --git a/plugins/cubrid-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/cubrid/CubridPlugin.java b/plugins/cubrid-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/cubrid/CubridPlugin.java index 4f7f54abdef7..022962610f5b 100644 --- a/plugins/cubrid-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/cubrid/CubridPlugin.java +++ b/plugins/cubrid-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/cubrid/CubridPlugin.java @@ -25,6 +25,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * @author Jongho Moon * @@ -81,7 +83,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri InstrumentClass target = instrumentContext.getInstrumentClass(loader, className, classfileBuffer); InterceptorGroup group = instrumentContext.getInterceptorGroup(CubridConstants.GROUP_CUBRID); - target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.DriverConnectInterceptor", group, ExecutionPolicy.ALWAYS, new CubridJdbcUrlParser()); + target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.DriverConnectInterceptor", va(new CubridJdbcUrlParser()), group, ExecutionPolicy.ALWAYS); return target.toBytecode(); } @@ -102,7 +104,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri int maxBindValueSize = config.getMaxSqlBindValueSize(); InterceptorGroup group = instrumentContext.getInterceptorGroup(CubridConstants.GROUP_CUBRID); - target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor", group, maxBindValueSize); + target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor", va(maxBindValueSize), group); target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementBindVariableInterceptor", group); return target.toBytecode(); diff --git a/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/HttpClient4Plugin.java b/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/HttpClient4Plugin.java index 6ccb27ae69b4..a5a4cd567ea9 100644 --- a/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/HttpClient4Plugin.java +++ b/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/HttpClient4Plugin.java @@ -28,6 +28,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * @author netspider * @author emeroad @@ -142,8 +144,8 @@ private void injectHttpClientExecuteMethodWithHttpRequestInterceptor(InstrumentC InstrumentMethod execute = target.getDeclaredMethod("execute", parameterTypeNames); if (execute != null) { - execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodWithHttpRequestInterceptor", isHasCallbackParam); - execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodInternalInterceptor", isHasCallbackParam); + execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodWithHttpRequestInterceptor", va(isHasCallbackParam)); + execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodInternalInterceptor", va(isHasCallbackParam)); } } @@ -151,8 +153,8 @@ private void injectHttpClientExecuteMethodWithHttpUriRequestInterceptor(Instrume InstrumentMethod execute = target.getDeclaredMethod("execute", parameterTypeNames); if (execute != null) { - execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodWithHttpUriRequestInterceptor", isHasCallbackParam); - execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodInternalInterceptor", isHasCallbackParam); + execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodWithHttpUriRequestInterceptor", va(isHasCallbackParam)); + execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodInternalInterceptor", va(isHasCallbackParam)); } } diff --git a/plugins/ibatis/src/main/java/com/navercorp/pinpoint/plugin/ibatis/IBatisPlugin.java b/plugins/ibatis/src/main/java/com/navercorp/pinpoint/plugin/ibatis/IBatisPlugin.java index f8f5624cadd4..081ad655160a 100644 --- a/plugins/ibatis/src/main/java/com/navercorp/pinpoint/plugin/ibatis/IBatisPlugin.java +++ b/plugins/ibatis/src/main/java/com/navercorp/pinpoint/plugin/ibatis/IBatisPlugin.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.plugin.ibatis; import static com.navercorp.pinpoint.common.trace.HistogramSchema.NORMAL_SCHEMA; +import static com.navercorp.pinpoint.common.util.VarArgs.va; import java.security.ProtectionDomain; import java.util.List; @@ -94,8 +95,8 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, final List methodsToTrace = target.getDeclaredMethods(methodFilter); for (InstrumentMethod methodToTrace : methodsToTrace) { String sqlMapOperationInterceptor = "com.navercorp.pinpoint.plugin.ibatis.interceptor.SqlMapOperationInterceptor"; - methodToTrace.addGroupedInterceptor(sqlMapOperationInterceptor, group, ExecutionPolicy.BOUNDARY, - serviceType); + methodToTrace.addGroupedInterceptor(sqlMapOperationInterceptor, va(serviceType), group, ExecutionPolicy.BOUNDARY + ); } return target.toBytecode(); diff --git a/plugins/jackson/src/main/java/com/navercorp/pinpoint/plugin/jackson/JacksonPlugin.java b/plugins/jackson/src/main/java/com/navercorp/pinpoint/plugin/jackson/JacksonPlugin.java index a10b4cbb3c63..31cc75ab62db 100644 --- a/plugins/jackson/src/main/java/com/navercorp/pinpoint/plugin/jackson/JacksonPlugin.java +++ b/plugins/jackson/src/main/java/com/navercorp/pinpoint/plugin/jackson/JacksonPlugin.java @@ -28,6 +28,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * @author Sungkook Kim * @@ -62,16 +64,16 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader, InterceptorGroup group = instrumentContext.getInterceptorGroup(GROUP); final InstrumentMethod constructor1 = target.getConstructor(); - addInterceptor(constructor1, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE); + addInterceptor(constructor1, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group); final InstrumentMethod constructor2 = target.getConstructor("com.fasterxml.jackson.core.JsonFactory"); - addInterceptor(constructor2, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE); + addInterceptor(constructor2, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group); final InstrumentMethod constructor3 = target.getConstructor("com.fasterxml.jackson.core.JsonFactory", "com.fasterxml.jackson.databind.ser.DefaultSerializerProvider", "com.fasterxml.jackson.databind.deser.DefaultDeserializationContext"); - addInterceptor(constructor3, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE); + addInterceptor(constructor3, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group); for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValue"))) { - addInterceptor(method, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE); + addInterceptor(method, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group); } for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValueAsString"))) { @@ -101,23 +103,23 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader, InterceptorGroup group = instrumentContext.getInterceptorGroup(GROUP); final InstrumentMethod constructor1 = target.getConstructor(); - addInterceptor(constructor1, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE); + addInterceptor(constructor1, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group); final InstrumentMethod constructor2 = target.getConstructor("org.codehaus.jackson.JsonFactory"); - addInterceptor(constructor2, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE); + addInterceptor(constructor2, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group); final InstrumentMethod constructor3 = target.getConstructor("org.codehaus.jackson.JsonFactory", "org.codehaus.jackson.map.SerializerProvider", "org.codehaus.jackson.map.DeserializerProvider"); - addInterceptor(constructor3, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE); + addInterceptor(constructor3, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group); final InstrumentMethod constructor4 = target.getConstructor("org.codehaus.jackson.map.SerializerFactory"); - addInterceptor(constructor4, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE); + addInterceptor(constructor4, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group); final InstrumentMethod constructor5 = target.getConstructor("org.codehaus.jackson.JsonFactory", "org.codehaus.jackson.map.SerializerProvider", "org.codehaus.jackson.map.DeserializerProvider", "org.codehaus.jackson.map.SerializationConfig", "org.codehaus.jackson.map.DeserializationConfig"); - addInterceptor(constructor5, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE); + addInterceptor(constructor5, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group); for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValue"))) { - addInterceptor(method, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE); + addInterceptor(method, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group); } for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValueAsString"))) { @@ -166,7 +168,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader, InterceptorGroup group = instrumentContext.getInterceptorGroup(GROUP); for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValue"))) { - addInterceptor(method, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE); + addInterceptor(method, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group); } for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValueAsString"))) { @@ -183,10 +185,14 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader, }); } - private boolean addInterceptor(InstrumentMethod method, String interceptorClassName, InterceptorGroup group, Object... constructorArgs) { + private boolean addInterceptor(InstrumentMethod method, String interceptorClassName, InterceptorGroup group) { + return addInterceptor(method, interceptorClassName, null, group); + } + + private boolean addInterceptor(InstrumentMethod method, String interceptorClassName, Object[] constructorArgs, InterceptorGroup group) { if (method != null) { try { - method.addGroupedInterceptor(interceptorClassName, group, constructorArgs); + method.addGroupedInterceptor(interceptorClassName, constructorArgs, group); return true; } catch (InstrumentException e) { if (logger.isWarnEnabled()) { diff --git a/plugins/jetty/src/main/java/com/navercorp/pinpoint/plugin/jetty/JettyPlugin.java b/plugins/jetty/src/main/java/com/navercorp/pinpoint/plugin/jetty/JettyPlugin.java index 21bc892ab43f..fbc1bccf565b 100644 --- a/plugins/jetty/src/main/java/com/navercorp/pinpoint/plugin/jetty/JettyPlugin.java +++ b/plugins/jetty/src/main/java/com/navercorp/pinpoint/plugin/jetty/JettyPlugin.java @@ -18,6 +18,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + public class JettyPlugin implements ProfilerPlugin { @Override @@ -30,7 +32,7 @@ public void setup(ProfilerPluginSetupContext context) { } private void addServerInterceptor(ProfilerPluginSetupContext context, JettyConfiguration config){ - context.addClassFileTransformer("org.eclipse.jetty.server.Server", PinpointClassFileTransformers.addInterceptor("com.navercorp.pinpoint.plugin.jetty.interceptor.ServerHandleInterceptor", config.getJettyExcludeUrlFilter())); + context.addClassFileTransformer("org.eclipse.jetty.server.Server", PinpointClassFileTransformers.addInterceptor("com.navercorp.pinpoint.plugin.jetty.interceptor.ServerHandleInterceptor", va(config.getJettyExcludeUrlFilter()))); } private void addRequestEditor(ProfilerPluginSetupContext context) { diff --git a/plugins/json-lib/src/main/java/com/navercorp/pinpoint/plugin/json_lib/JsonLibPlugin.java b/plugins/json-lib/src/main/java/com/navercorp/pinpoint/plugin/json_lib/JsonLibPlugin.java index e89b9756a5ad..cacfd2ab3aef 100644 --- a/plugins/json-lib/src/main/java/com/navercorp/pinpoint/plugin/json_lib/JsonLibPlugin.java +++ b/plugins/json-lib/src/main/java/com/navercorp/pinpoint/plugin/json_lib/JsonLibPlugin.java @@ -137,7 +137,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader, private boolean addInterceptor(InstrumentMethod method, String interceptorClassName, InterceptorGroup group, Object... constructorArgs) { if (method != null && isPublicMethod(method)) { try { - method.addGroupedInterceptor(interceptorClassName, group, constructorArgs); + method.addGroupedInterceptor(interceptorClassName, constructorArgs, group); return true; } catch (InstrumentException e) { if (logger.isWarnEnabled()) { diff --git a/plugins/jtds/src/main/java/com/navercorp/pinpoint/plugin/jdbc/jtds/JtdsPlugin.java b/plugins/jtds/src/main/java/com/navercorp/pinpoint/plugin/jdbc/jtds/JtdsPlugin.java index 5a61f5c2bef2..d14b703e962b 100644 --- a/plugins/jtds/src/main/java/com/navercorp/pinpoint/plugin/jdbc/jtds/JtdsPlugin.java +++ b/plugins/jtds/src/main/java/com/navercorp/pinpoint/plugin/jdbc/jtds/JtdsPlugin.java @@ -25,6 +25,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * @author Jongho Moon * @@ -84,7 +86,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri InstrumentClass target = instrumentContext.getInstrumentClass(loader, className, classfileBuffer); InterceptorGroup group = instrumentContext.getInterceptorGroup(JtdsConstants.GROUP_JTDS); - target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.DriverConnectInterceptor", group, ExecutionPolicy.ALWAYS, new JtdsJdbcUrlParser()); + target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.DriverConnectInterceptor", va(new JtdsJdbcUrlParser()), group, ExecutionPolicy.ALWAYS); return target.toBytecode(); } @@ -105,7 +107,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri int maxBindValueSize = config.getMaxSqlBindValueSize(); InterceptorGroup group = instrumentContext.getInterceptorGroup(JtdsConstants.GROUP_JTDS); - target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor", group, maxBindValueSize); + target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor", va(maxBindValueSize), group); target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementBindVariableInterceptor", group); return target.toBytecode(); diff --git a/plugins/mysql-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlPlugin.java b/plugins/mysql-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlPlugin.java index 084998ff5f1c..4cb6bb887f70 100644 --- a/plugins/mysql-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlPlugin.java +++ b/plugins/mysql-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/mysql/MySqlPlugin.java @@ -26,6 +26,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; import com.navercorp.pinpoint.bootstrap.plugin.jdbc.PreparedStatementBindingMethodFilter; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * @author Jongho Moon * @@ -94,7 +96,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri InstrumentClass target = instrumentContext.getInstrumentClass(loader, className, classfileBuffer); InterceptorGroup group = instrumentContext.getInterceptorGroup(MySqlConstants.GROUP_NAME); - target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.DriverConnectInterceptor", group, ExecutionPolicy.ALWAYS, new MySqlJdbcUrlParser(), false); + target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.DriverConnectInterceptor", va(new MySqlJdbcUrlParser(), false), group, ExecutionPolicy.ALWAYS); return target.toBytecode(); } @@ -115,7 +117,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri int maxBindValueSize = config.getMaxSqlBindValueSize(); InterceptorGroup group = instrumentContext.getInterceptorGroup(MySqlConstants.GROUP_NAME); - target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor", group, maxBindValueSize); + target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor", va(maxBindValueSize), group); target.addGroupedInterceptor(PreparedStatementBindingMethodFilter.excludes("setRowId", "setNClob", "setSQLXML"), "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementBindVariableInterceptor", group, ExecutionPolicy.BOUNDARY); return target.toBytecode(); diff --git a/plugins/okhttp/src/main/java/com/navercorp/pinpoint/plugin/okhttp/OkHttpPlugin.java b/plugins/okhttp/src/main/java/com/navercorp/pinpoint/plugin/okhttp/OkHttpPlugin.java index caa7466559df..cab88392c0eb 100644 --- a/plugins/okhttp/src/main/java/com/navercorp/pinpoint/plugin/okhttp/OkHttpPlugin.java +++ b/plugins/okhttp/src/main/java/com/navercorp/pinpoint/plugin/okhttp/OkHttpPlugin.java @@ -27,6 +27,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * @author jaehong.kim * @@ -74,7 +76,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri for(InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("execute", "cancel"))) { logger.debug("[OkHttp] Add Dispatcher.execute | cancel interceptor."); - method.addInterceptor(OkHttpConstants.BASIC_METHOD_INTERCEPTOR, OkHttpConstants.OK_HTTP_CLIENT_INTERNAL); + method.addInterceptor(OkHttpConstants.BASIC_METHOD_INTERCEPTOR, va(OkHttpConstants.OK_HTTP_CLIENT_INTERNAL)); } InstrumentMethod enqueueMethod = target.getDeclaredMethod("enqueue", "com.squareup.okhttp.Call$AsyncCall"); if(enqueueMethod != null) { @@ -120,7 +122,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri if(sendRequestMethod != null) { logger.debug("[OkHttp] Add HttpEngine.sendRequest interceptor."); final ObjectRecipe objectRecipe = ObjectRecipe.byConstructor("com.navercorp.pinpoint.plugin.okhttp.OkHttpPluginConfig", context.getConfig()); - sendRequestMethod.addInterceptor("com.navercorp.pinpoint.plugin.okhttp.interceptor.HttpEngineSendRequestMethodInterceptor", objectRecipe); + sendRequestMethod.addInterceptor("com.navercorp.pinpoint.plugin.okhttp.interceptor.HttpEngineSendRequestMethodInterceptor", va(objectRecipe)); } InstrumentMethod connectMethod = target.getDeclaredMethod("connect"); @@ -132,7 +134,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri InstrumentMethod readResponseMethod = target.getDeclaredMethod("readResponse"); if(readResponseMethod != null) { logger.debug("[OkHttp] Add HttpEngine.connect interceptor."); - readResponseMethod.addInterceptor("com.navercorp.pinpoint.plugin.okhttp.interceptor.HttpEngineReadResponseMethodInterceptor", config.isStatusCode()); + readResponseMethod.addInterceptor("com.navercorp.pinpoint.plugin.okhttp.interceptor.HttpEngineReadResponseMethodInterceptor", va(config.isStatusCode())); } return target.toBytecode(); diff --git a/plugins/oracle-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/oracle/OraclePlugin.java b/plugins/oracle-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/oracle/OraclePlugin.java index b339ee17f823..09e3f78b665e 100644 --- a/plugins/oracle-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/oracle/OraclePlugin.java +++ b/plugins/oracle-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/oracle/OraclePlugin.java @@ -25,6 +25,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * @author Jongho Moon * @@ -86,7 +88,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri InstrumentClass target = instrumentContext.getInstrumentClass(loader, className, classfileBuffer); InterceptorGroup group = instrumentContext.getInterceptorGroup(OracleConstants.GROUP_ORACLE); - target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.DriverConnectInterceptor", group, ExecutionPolicy.ALWAYS, new OracleJdbcUrlParser()); + target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.DriverConnectInterceptor", va(new OracleJdbcUrlParser()), group, ExecutionPolicy.ALWAYS); return target.toBytecode(); } @@ -113,7 +115,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri int maxBindValueSize = config.getMaxSqlBindValueSize(); InterceptorGroup group = instrumentContext.getInterceptorGroup(OracleConstants.GROUP_ORACLE); - target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor", group, maxBindValueSize); + target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor", va(maxBindValueSize), group); target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementBindVariableInterceptor", group); return target.toBytecode(); diff --git a/plugins/redis/src/main/java/com/navercorp/pinpoint/plugin/redis/RedisPlugin.java b/plugins/redis/src/main/java/com/navercorp/pinpoint/plugin/redis/RedisPlugin.java index de783e1f70bf..6fb50aeb5449 100644 --- a/plugins/redis/src/main/java/com/navercorp/pinpoint/plugin/redis/RedisPlugin.java +++ b/plugins/redis/src/main/java/com/navercorp/pinpoint/plugin/redis/RedisPlugin.java @@ -29,6 +29,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * * @author jaehong.kim @@ -104,7 +106,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader, for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.chain(MethodFilters.name(JedisMethodNames.get()), MethodFilters.modifierNot(MethodFilters.SYNTHETIC)))) { try { - method.addInterceptor("com.navercorp.pinpoint.plugin.redis.interceptor.JedisMethodInterceptor", config.isIo()); + method.addInterceptor("com.navercorp.pinpoint.plugin.redis.interceptor.JedisMethodInterceptor", va(config.isIo())); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("Unsupported method " + method, e); @@ -196,7 +198,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader, for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.chain(MethodFilters.name(JedisPipelineMethodNames.get()), MethodFilters.modifierNot(MethodFilters.SYNTHETIC)))) { try { - method.addInterceptor("com.navercorp.pinpoint.plugin.redis.interceptor.JedisPipelineMethodInterceptor", config.isIo()); + method.addInterceptor("com.navercorp.pinpoint.plugin.redis.interceptor.JedisPipelineMethodInterceptor", va(config.isIo())); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("Unsupported method " + method, e); diff --git a/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/BeanMethodTransformer.java b/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/BeanMethodTransformer.java index aa1284f7657a..9153dc281b31 100644 --- a/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/BeanMethodTransformer.java +++ b/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/BeanMethodTransformer.java @@ -30,6 +30,8 @@ import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * @author Jongho Moon * @@ -64,7 +66,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri logger.trace("### c={}, m={}, params={}", new Object[] {className, method.getName(), Arrays.toString(method.getParameterTypes())}); } - method.addInterceptor(BasicMethodInterceptor.class.getName(), SpringBeansConstants.SERVICE_TYPE); + method.addInterceptor(BasicMethodInterceptor.class.getName(), va(SpringBeansConstants.SERVICE_TYPE)); } return target.toBytecode(); diff --git a/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansPlugin.java b/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansPlugin.java index 8f0d46d78c35..55afc83887ad 100644 --- a/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansPlugin.java +++ b/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansPlugin.java @@ -25,6 +25,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * @author Jongho Moon * @@ -47,10 +49,10 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri ObjectRecipe beanFilterRecipe = ObjectRecipe.byStaticFactory("com.navercorp.pinpoint.plugin.spring.beans.interceptor.TargetBeanFilter", "of", context.getConfig()); InstrumentMethod createBeanInstance = target.getDeclaredMethod("createBeanInstance", "java.lang.String", "org.springframework.beans.factory.support.RootBeanDefinition", "java.lang.Object[]"); - createBeanInstance.addInterceptor("com.navercorp.pinpoint.plugin.spring.beans.interceptor.CreateBeanInstanceInterceptor", beanTransformer, beanFilterRecipe); + createBeanInstance.addInterceptor("com.navercorp.pinpoint.plugin.spring.beans.interceptor.CreateBeanInstanceInterceptor", va(beanTransformer, beanFilterRecipe)); InstrumentMethod postProcessor = target.getDeclaredMethod("applyBeanPostProcessorsBeforeInstantiation", "java.lang.Class", "java.lang.String"); - postProcessor.addInterceptor("com.navercorp.pinpoint.plugin.spring.beans.interceptor.PostProcessorInterceptor", beanTransformer, beanFilterRecipe); + postProcessor.addInterceptor("com.navercorp.pinpoint.plugin.spring.beans.interceptor.PostProcessorInterceptor", va(beanTransformer, beanFilterRecipe)); return target.toBytecode(); } diff --git a/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/web/SpringWebMvcPlugin.java b/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/web/SpringWebMvcPlugin.java index 96c02da41989..b19e91edbc66 100644 --- a/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/web/SpringWebMvcPlugin.java +++ b/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/web/SpringWebMvcPlugin.java @@ -15,6 +15,7 @@ package com.navercorp.pinpoint.plugin.spring.web; import static com.navercorp.pinpoint.common.trace.HistogramSchema.*; +import static com.navercorp.pinpoint.common.util.VarArgs.va; import java.security.ProtectionDomain; @@ -42,8 +43,8 @@ public void setup(ProfilerPluginSetupContext context) { public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException { InstrumentClass target = instrumentContext.getInstrumentClass(loader, className, classfileBuffer); - target.getDeclaredMethod("doGet", "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse").addInterceptor(BasicMethodInterceptor.class.getName(), SPRING_MVC); - target.getDeclaredMethod("doPost", "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse").addInterceptor(BasicMethodInterceptor.class.getName(), SPRING_MVC); + target.getDeclaredMethod("doGet", "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse").addInterceptor(BasicMethodInterceptor.class.getName(), va(SPRING_MVC)); + target.getDeclaredMethod("doPost", "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse").addInterceptor(BasicMethodInterceptor.class.getName(), va(SPRING_MVC)); return target.toBytecode(); } diff --git a/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftPlugin.java b/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftPlugin.java index 8a48271bf932..7c55a5faab15 100644 --- a/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftPlugin.java +++ b/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftPlugin.java @@ -38,6 +38,8 @@ import com.navercorp.pinpoint.plugin.thrift.field.getter.TNonblockingTransportFieldGetter; import com.navercorp.pinpoint.plugin.thrift.field.getter.TTransportFieldGetter; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * @author HyunGil Jeong */ @@ -90,14 +92,14 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri final InstrumentMethod sendBase = target.getDeclaredMethod("sendBase", "java.lang.String", "org.apache.thrift.TBase"); if (sendBase != null) { String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.client.TServiceClientSendBaseInterceptor"; - sendBase.addInterceptor(interceptor, traceServiceArgs); + sendBase.addInterceptor(interceptor, va(traceServiceArgs)); } // TServiceClient.receiveBase(TBase, String) final InstrumentMethod receiveBase = target.getDeclaredMethod("receiveBase", "org.apache.thrift.TBase", "java.lang.String"); if (receiveBase != null) { String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.client.TServiceClientReceiveBaseInterceptor"; - receiveBase.addInterceptor(interceptor, traceServiceResult); + receiveBase.addInterceptor(interceptor, va(traceServiceResult)); } return target.toBytecode(); diff --git a/plugins/tomcat/src/main/java/com/navercorp/pinpoint/plugin/tomcat/TomcatPlugin.java b/plugins/tomcat/src/main/java/com/navercorp/pinpoint/plugin/tomcat/TomcatPlugin.java index c7eb9175c012..ad782d86fbb8 100644 --- a/plugins/tomcat/src/main/java/com/navercorp/pinpoint/plugin/tomcat/TomcatPlugin.java +++ b/plugins/tomcat/src/main/java/com/navercorp/pinpoint/plugin/tomcat/TomcatPlugin.java @@ -25,6 +25,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; +import static com.navercorp.pinpoint.common.util.VarArgs.va; + /** * @author Jongho Moon * @author jaehong.kim @@ -106,7 +108,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader, InstrumentMethod method = target.getDeclaredMethod("invoke", "org.apache.catalina.connector.Request", "org.apache.catalina.connector.Response"); if (method != null) { - method.addInterceptor("com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor", config.getTomcatExcludeUrlFilter()); + method.addInterceptor("com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor", va(config.getTomcatExcludeUrlFilter())); } return target.toBytecode(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/JavassistClass.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/JavassistClass.java index a2d2b0f13d7b..3735bc737156 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/JavassistClass.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/JavassistClass.java @@ -230,11 +230,11 @@ public boolean hasEnclosingMethod(String methodName, String... parameterTypes) { } catch (NotFoundException ignored) { return false; } - + if(behavior == null) { return false; } - + final MethodInfo methodInfo = behavior.getMethodInfo2(); if (!methodInfo.getName().equals(methodName)) { return false; @@ -312,7 +312,7 @@ public InstrumentMethod addDelegatorMethod(String methodName, String... paramTyp CtMethod delegatorMethod = CtNewMethod.delegator(superMethod, ctClass); ctClass.addMethod(delegatorMethod); - + return new JavassistMethod(pluginContext, interceptorRegistryBinder, this, delegatorMethod); } catch (NotFoundException ex) { throw new InstrumentException(getName() + "don't have super class(" + getSuperClass() + "). Cause:" + ex.getMessage(), ex); @@ -400,17 +400,32 @@ public void addGetter(String getterTypeName, String fieldName) throws Instrument } @Override - public int addInterceptor(String interceptorClassName, Object... constructorArgs) throws InstrumentException { - return addGroupedInterceptor(interceptorClassName, null, null, constructorArgs); + public int addInterceptor(String interceptorClassName) throws InstrumentException { + return addGroupedInterceptor(interceptorClassName, null, null, null); + } + @Override + public int addInterceptor(String interceptorClassName, Object[] constructorArgs) throws InstrumentException { + return addGroupedInterceptor(interceptorClassName, constructorArgs, null, null); + } + + @Override + public int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group) throws InstrumentException { + return addGroupedInterceptor(interceptorClassName, group, ExecutionPolicy.BOUNDARY); } @Override - public int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, Object... constructorArgs) throws InstrumentException { - return addGroupedInterceptor(interceptorClassName, group, ExecutionPolicy.BOUNDARY, constructorArgs); + public int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group) throws InstrumentException { + return addGroupedInterceptor(interceptorClassName, constructorArgs, group, ExecutionPolicy.BOUNDARY); } @Override - public int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object... constructorArgs) throws InstrumentException { + public int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException { + return addGroupedInterceptor(interceptorClassName, null, group, executionPolicy); + } + + + @Override + public int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException { Asserts.notNull(interceptorClassName, "interceptorClassName"); int interceptorId = -1; @@ -420,13 +435,13 @@ public int addGroupedInterceptor(String interceptorClassName, InterceptorGroup g TargetMethods targetMethods = interceptorType.getAnnotation(TargetMethods.class); if (targetMethods != null) { for (TargetMethod m : targetMethods.value()) { - interceptorId = addInterceptor0(m, interceptorClassName, group, executionPolicy, constructorArgs); + interceptorId = addInterceptor0(m, interceptorClassName, constructorArgs, group, executionPolicy); } } TargetMethod targetMethod = interceptorType.getAnnotation(TargetMethod.class); if (targetMethod != null) { - interceptorId = addInterceptor0(targetMethod, interceptorClassName, group, executionPolicy, constructorArgs); + interceptorId = addInterceptor0(targetMethod, interceptorClassName, constructorArgs, group, executionPolicy); } TargetConstructors targetConstructors = interceptorType.getAnnotation(TargetConstructors.class); @@ -460,20 +475,20 @@ private int addInterceptor0(TargetConstructor c, String interceptorClassName, In throw new NotFoundInstrumentException("Cannot find constructor with parameter types: " + Arrays.toString(c.value())); } - return constructor.addGroupedInterceptor(interceptorClassName, group, executionPolicy, constructorArgs); + return constructor.addGroupedInterceptor(interceptorClassName, constructorArgs, group, executionPolicy); } - private int addInterceptor0(TargetMethod m, String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object... constructorArgs) throws InstrumentException { + private int addInterceptor0(TargetMethod m, String interceptorClassName, Object[] constructorArgs, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException { InstrumentMethod method = getDeclaredMethod(m.name(), m.paramTypes()); if (method == null) { throw new NotFoundInstrumentException("Cannot find method " + m.name() + " with parameter types: " + Arrays.toString(m.paramTypes())); } - return method.addGroupedInterceptor(interceptorClassName, group, executionPolicy, constructorArgs); + return method.addGroupedInterceptor(interceptorClassName, constructorArgs, group, executionPolicy); } - private int addInterceptor0(TargetFilter annotation, String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object... constructorArgs) throws InstrumentException { + private int addInterceptor0(TargetFilter annotation, String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object[] constructorArgs) throws InstrumentException { String filterTypeName = annotation.type(); Asserts.notNull(filterTypeName, "type of @TargetFilter"); @@ -487,7 +502,7 @@ private int addInterceptor0(TargetFilter annotation, String interceptorClassName if (singleton && interceptorId != -1) { m.addInterceptor(interceptorId); } else { - interceptorId = m.addGroupedInterceptor(interceptorClassName, group, executionPolicy, constructorArgs); + interceptorId = m.addGroupedInterceptor(interceptorClassName, constructorArgs, group, executionPolicy); } } @@ -497,21 +512,31 @@ private int addInterceptor0(TargetFilter annotation, String interceptorClassName return interceptorId; } + + @Override + public int addInterceptor(MethodFilter filter, String interceptorClassName) throws InstrumentException { + return addGroupedInterceptor(filter, interceptorClassName, null, null, null); + } @Override - public int addInterceptor(MethodFilter filter, String interceptorClassName, Object... constructorArgs) throws InstrumentException { - return addInterceptor(filter, interceptorClassName, null, null, constructorArgs); + public int addInterceptor(MethodFilter filter, String interceptorClassName, Object[] constructorArgs) throws InstrumentException { + return addGroupedInterceptor(filter, interceptorClassName, constructorArgs, null, null); + } + + @Override + public int addGroupedInterceptor(MethodFilter filter, String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException { + return addGroupedInterceptor(filter, interceptorClassName, group, executionPolicy); } @Override - public int addGroupedInterceptor(MethodFilter filter, String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object... constructorArgs) throws InstrumentException { + public int addGroupedInterceptor(MethodFilter filter, String interceptorClassName, Object[] constructorArgs, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException { int interceptorId = -1; for (InstrumentMethod m : getDeclaredMethods(filter)) { if (interceptorId != -1) { m.addInterceptor(interceptorId); } else { - interceptorId = m.addGroupedInterceptor(interceptorClassName, group, executionPolicy, constructorArgs); + interceptorId = m.addGroupedInterceptor(interceptorClassName, constructorArgs, group, executionPolicy); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/JavassistMethod.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/JavassistMethod.java index 21e4ec4b6bb9..400291aa7819 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/JavassistMethod.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/JavassistMethod.java @@ -121,17 +121,32 @@ public MethodDescriptor getDescriptor() { } @Override - public int addInterceptor(String interceptorClassName, Object... constructorArgs) throws InstrumentException { - return addGroupedInterceptor(interceptorClassName, null, null, constructorArgs); + public int addInterceptor(String interceptorClassName) throws InstrumentException { + return addGroupedInterceptor(interceptorClassName, null, null, null); } @Override - public int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, Object... constructorArgs) throws InstrumentException { - return addGroupedInterceptor(interceptorClassName, group, null, constructorArgs); + public int addInterceptor(String interceptorClassName, Object[] constructorArgs) throws InstrumentException { + return addGroupedInterceptor(interceptorClassName, constructorArgs, null, null); } @Override - public int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy policy, Object... constructorArgs) throws InstrumentException { + public int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group) throws InstrumentException { + return addGroupedInterceptor(interceptorClassName, null, group, null); + } + + @Override + public int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException { + return addGroupedInterceptor(interceptorClassName, null, group, executionPolicy); + } + + @Override + public int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group) throws InstrumentException { + return addGroupedInterceptor(interceptorClassName, constructorArgs, group, null); + } + + @Override + public int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group, ExecutionPolicy policy) throws InstrumentException { try { return addInterceptor0(interceptorClassName, group, policy, constructorArgs); } catch (InstrumentException e) { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/plugin/xml/interceptor/AnnotatedInterceptorInjector.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/plugin/xml/interceptor/AnnotatedInterceptorInjector.java index 65673a15cb34..04513398d9f8 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/plugin/xml/interceptor/AnnotatedInterceptorInjector.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/plugin/xml/interceptor/AnnotatedInterceptorInjector.java @@ -53,7 +53,7 @@ public void edit(ClassLoader targetClassLoader, InstrumentClass targetClass, Ins int inject(InstrumentMethod targetMethod) throws InstrumentException { InterceptorGroup group = groupName == null ? null : pluginContext.getInterceptorGroup(groupName); - return targetMethod.addGroupedInterceptor(interceptorClassName, group, executionPolicy, providedArguments); + return targetMethod.addGroupedInterceptor(interceptorClassName, providedArguments, group, executionPolicy); } @Override diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/plugin/DefaultClassEditorBuilderTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/plugin/DefaultClassEditorBuilderTest.java index 0f765b1d30bf..16de6e223498 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/plugin/DefaultClassEditorBuilderTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/plugin/DefaultClassEditorBuilderTest.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.profiler.plugin; +import static com.navercorp.pinpoint.common.util.VarArgs.va; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -64,7 +65,7 @@ public void test() throws Exception { when(aMethod.getName()).thenReturn(methodName); when(aMethod.getParameterTypes()).thenReturn(parameterTypeNames); when(aMethod.getDescriptor()).thenReturn(aDescriptor); - when(aClass.addInterceptor(eq(methodName), eq(parameterTypeNames), isA(Interceptor.class))).thenReturn(0); + when(aClass.addInterceptor(eq(methodName), va(eq(parameterTypeNames)))).thenReturn(0); DefaultClassFileTransformerBuilder builder = new DefaultClassFileTransformerBuilder(context, "TargetClass"); @@ -78,7 +79,7 @@ public void test() throws Exception { transformer.transform(classLoader, className, null, null, classFileBuffer); - verify(aMethod).addGroupedInterceptor(eq("com.navercorp.pinpoint.profiler.plugin.TestInterceptor"), (InterceptorGroup)isNull(), (ExecutionPolicy)isNull(), eq("provided")); + verify(aMethod).addGroupedInterceptor(eq("com.navercorp.pinpoint.profiler.plugin.TestInterceptor"), eq(va("provided")), (InterceptorGroup)isNull(), (ExecutionPolicy)isNull()); verify(aClass).addField("some.accessor.Type", "new java.util.HashMap();"); verify(aClass).addGetter("some.getter.Type", "someField"); }