Skip to content

Commit

Permalink
[pinpoint-apm#2862] Edit InstrumentUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
koo-taejin committed Apr 26, 2017
1 parent 7066ef6 commit c0dea8a
Showing 1 changed file with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,35 @@
*/
public final class InstrumentUtils {

public static void addScopeInterceptor(InstrumentClass clazz, String methodName, String[] parameterTypes, String interceptorClassName, String scopeName) throws InstrumentException {
if (clazz == null) {
throw new NullPointerException("clazz must not be null");
}
if (methodName == null) {
throw new NullPointerException("methodName must not be null");
}
if (interceptorClassName == null) {
throw new NullPointerException("interceptorClassName must not be null");
}
if (scopeName == null) {
throw new NullPointerException("scopeName must not be null");
}

final InstrumentMethod method = findMethod(clazz, methodName, parameterTypes);
method.addScopedInterceptor(interceptorClassName, scopeName);
}


@Deprecated
public static void addInterceptor(InstrumentClass clazz, String methodName, String[] parameterTypes, String interceptorClassName, String scopeName) throws InstrumentException {
addInterceptor(clazz, methodName, parameterTypes, interceptorClassName, scopeName, null);
addScopeInterceptor(clazz, methodName, parameterTypes, interceptorClassName, scopeName);
}

public static void addInterceptor(InstrumentClass clazz, String methodName, String[] parameterTypes, String interceptorClassName, String scopeName, ExecutionPolicy executionPolicy) throws InstrumentException {
addScopedInterceptor(clazz, methodName, parameterTypes, interceptorClassName, scopeName, executionPolicy);
}

public static void addScopedInterceptor(InstrumentClass clazz, String methodName, String[] parameterTypes, String interceptorClassName, String scopeName, ExecutionPolicy executionPolicy) throws InstrumentException {
if (clazz == null) {
throw new NullPointerException("clazz must not be null");
}
Expand All @@ -47,18 +71,19 @@ public static void addInterceptor(InstrumentClass clazz, String methodName, Stri
throw new NullPointerException("scopeName must not be null");
}

final InstrumentMethod method = clazz.getDeclaredMethod(methodName, parameterTypes);
if (method == null) {
throw new NotFoundInstrumentException("Cannot find method " + methodName + " with parameter types: " + Arrays.toString(parameterTypes));
}
final InstrumentMethod method = findMethod(clazz, methodName, parameterTypes);
method.addScopedInterceptor(interceptorClassName, scopeName, executionPolicy);
}

public static void addInterceptor(InstrumentClass clazz, String methodName, String[] parameterTypes, String interceptorClassName, Object[] interceptorParams, String scopeName) throws InstrumentException {
public static void addInterceptor(InstrumentClass clazz, String methodName, String[] parameterTypes, String interceptorClassName, Object[] interceptorParams, String scopeName) throws InstrumentException {
addInterceptor(clazz, methodName, parameterTypes, interceptorClassName, interceptorParams, scopeName, null);
}

public static void addInterceptor(InstrumentClass clazz, String methodName, String[] parameterTypes, String interceptorClassName, Object[] interceptorParams, String scopeName, ExecutionPolicy executionPolicy) throws InstrumentException {
addScopedInterceptor(clazz, methodName, parameterTypes, interceptorClassName, interceptorParams, scopeName, executionPolicy);
}

public static void addScopedInterceptor(InstrumentClass clazz, String methodName, String[] parameterTypes, String interceptorClassName, Object[] interceptorParams, String scopeName, ExecutionPolicy executionPolicy) throws InstrumentException {
if (clazz == null) {
throw new NullPointerException("clazz must not be null");
}
Expand All @@ -72,10 +97,16 @@ public static void addInterceptor(InstrumentClass clazz, String methodName, Stri
throw new NullPointerException("scopeName must not be null");
}

final InstrumentMethod method = findMethod(clazz, methodName, parameterTypes);
method.addScopedInterceptor(interceptorClassName, interceptorParams, scopeName, executionPolicy);
}

private static InstrumentMethod findMethod(InstrumentClass clazz, String methodName, String[] parameterTypes) throws NotFoundInstrumentException {
final InstrumentMethod method = clazz.getDeclaredMethod(methodName, parameterTypes);
if (method == null) {
throw new NotFoundInstrumentException("Cannot find method " + methodName + " with parameter types: " + Arrays.toString(parameterTypes));
}
method.addScopedInterceptor(interceptorClassName, interceptorParams, scopeName, executionPolicy);
return method;
}

}

0 comments on commit c0dea8a

Please sign in to comment.