Skip to content

Commit

Permalink
[pinpoint-apm#2862] Edit InstrumentUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung authored and koo-taejin committed Apr 27, 2017
1 parent c0dea8a commit 81115d8
Showing 1 changed file with 8 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,84 +29,19 @@
*/
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 {
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");
}
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, executionPolicy);
}

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");
}
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, interceptorParams, scopeName, executionPolicy);
}

private static InstrumentMethod findMethod(InstrumentClass clazz, String methodName, String[] parameterTypes) throws NotFoundInstrumentException {
public 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));
}
return method;
}

public static InstrumentMethod findConstructor(InstrumentClass clazz, String... parameterTypes) throws NotFoundInstrumentException {
InstrumentMethod constructor = clazz.getConstructor(parameterTypes);
if (constructor == null) {
throw new NotFoundInstrumentException("Cannot find constructor with parameter types: " + Arrays.toString(parameterTypes));
}
return constructor;
}
}

0 comments on commit 81115d8

Please sign in to comment.