Skip to content

Commit

Permalink
Redesigned plugin apis.
Browse files Browse the repository at this point in the history
  • Loading branch information
lioolli committed Jul 31, 2015
1 parent c0043c4 commit 7c4ad07
Show file tree
Hide file tree
Showing 28 changed files with 646 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public interface ByteCodeInstrumentor {

InstrumentClass getClass(ClassLoader classLoader, String jvmClassName, byte[] classFileBuffer) throws InstrumentException;
InstrumentClass getClass(ClassLoader classLoader, String jvmClassName, byte[] classFileBuffer) throws NotFoundInstrumentException;

boolean findClass(ClassLoader classLoader, String javassistClassName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package com.navercorp.pinpoint.bootstrap.instrument;

import com.navercorp.pinpoint.bootstrap.interceptor.Interceptor;

import java.util.List;

import com.navercorp.pinpoint.bootstrap.FieldAccessor;
import com.navercorp.pinpoint.bootstrap.MetadataAccessor;
import com.navercorp.pinpoint.bootstrap.interceptor.Interceptor;

/**
* @author emeroad
* @author netspider
Expand All @@ -33,97 +35,143 @@ public interface InstrumentClass {
String getSuperClass();

String[] getInterfaces();

MethodInfo getConstructor(String[] parameterTypes);

@Deprecated
boolean insertCodeBeforeMethod(String methodName, String[] args, String code);

@Deprecated
boolean insertCodeAfterMethod(String methodName, String[] args, String code);

@Deprecated
int addAllConstructorInterceptor(Interceptor interceptor) throws InstrumentException, NotFoundInstrumentException;

@Deprecated
int addAllConstructorInterceptor(Interceptor interceptor, Type type) throws InstrumentException, NotFoundInstrumentException;

int addConstructorInterceptor(String[] args, Interceptor interceptor) throws InstrumentException, NotFoundInstrumentException;
List<MethodInfo> getDeclaredMethods();

int addConstructorInterceptor(String[] args, Interceptor interceptor, Type type) throws InstrumentException, NotFoundInstrumentException;
List<MethodInfo> getDeclaredMethods(MethodFilter filter);

int reuseInterceptor(String methodName, String[] args, int interceptorId) throws InstrumentException, NotFoundInstrumentException;
MethodInfo getDeclaredMethod(String name, String[] parameterTypes);

ClassLoader getClassLoader();

int reuseInterceptor(String methodName, String[] args, int interceptorId, Type type) throws InstrumentException, NotFoundInstrumentException;

public boolean isInterceptable();

boolean hasConstructor(String[] parameterTypes);

int addInterceptor(String methodName, String[] args, Interceptor interceptor) throws InstrumentException, NotFoundInstrumentException;
boolean hasDeclaredMethod(String methodName, String[] parameterTypes, String returnType);

boolean hasDeclaredMethod(String methodName, String[] parameterTypes);

boolean hasMethod(String methodName, String[] parameterTypes, String returnType);

boolean hasMethod(String methodName, String[] parameterTypes);

boolean hasField(String name, String type);

boolean hasField(String name);

int addGroupInterceptor(String methodName, String[] args, Interceptor interceptor, String scopeName) throws InstrumentException, NotFoundInstrumentException;


int addGroupInterceptor(String methodName, String[] args, Interceptor interceptor, InterceptorGroupDefinition scopeDefinition) throws InstrumentException;
int addConstructorInterceptor(String[] parameterTypes, int interceptorId) throws InstrumentException, NotFoundInstrumentException;

int addGroupInterceptorIfDeclared(String methodName, String[] args, Interceptor interceptor, String scopeName) throws InstrumentException;
int addConstructorInterceptor(String[] parameterTypes, int interceptorId, Type type) throws InstrumentException, NotFoundInstrumentException;

int addGroupInterceptorIfDeclared(String methodName, String[] args, Interceptor interceptor, InterceptorGroupDefinition scopeDefinition) throws InstrumentException;
int addInterceptor(String methodName, String[] parameterTypes, int interceptorId) throws InstrumentException, NotFoundInstrumentException;

int addInterceptor(String methodName, String[] parameterTypes, int interceptorId, Type type) throws InstrumentException, NotFoundInstrumentException;

int addInterceptor(String methodName, String[] args, Interceptor interceptor, Type type) throws InstrumentException, NotFoundInstrumentException;


void weave(String adviceClassName, ClassLoader classLoader) throws InstrumentException;

boolean addDebugLogBeforeAfterMethod();

boolean addDebugLogBeforeAfterConstructor();

byte[] toBytecode() throws InstrumentException;

Class<?> toClass() throws InstrumentException;


void addMetadata(MetadataAccessor metadata, String initialValue) throws InstrumentException;

void addMetadata(MetadataAccessor metadata) throws InstrumentException;

void addGetter(FieldAccessor getter, String fieldName) throws InstrumentException;

/**
* Use addTraceValue instead of this method.
* You should check that class already have Declared method.
* If class already have method, this method throw exception.
*/
@Deprecated
void addTraceVariable(String variableName, String setterName, String getterName, String variableType, String initValue) throws InstrumentException;
void addDelegatorMethod(String methodName, String[] args) throws InstrumentException;

byte[] toBytecode() throws InstrumentException;




/**
* Use addTraceValue instead of this method.
*/
@Deprecated
void addTraceVariable(String variableName, String setterName, String getterName, String variableType) throws InstrumentException;

void addTraceValue(Class<?> traceValue, String initValue) throws InstrumentException;

void addTraceValue(Class<?> traceValue) throws InstrumentException;
void addTraceValue(Class<?> accessorType, String initialValue) throws InstrumentException;

@Deprecated
void addTraceValue(Class<?> accessorType) throws InstrumentException;

boolean insertCodeAfterConstructor(String[] args, String code);
@Deprecated
void addGetter(String getterName, String fieldName, String fieldType) throws InstrumentException;

@Deprecated
void addGetter(Class<?> interfaceType, String fieldName) throws InstrumentException;


@Deprecated
int addConstructorInterceptor(String[] args, Interceptor interceptor) throws InstrumentException, NotFoundInstrumentException;

boolean insertCodeBeforeConstructor(String[] args, String code);
@Deprecated
int addConstructorInterceptor(String[] args, Interceptor interceptor, Type type) throws InstrumentException, NotFoundInstrumentException;

List<MethodInfo> getDeclaredMethods();
@Deprecated
int addInterceptor(String methodName, String[] args, Interceptor interceptor) throws InstrumentException, NotFoundInstrumentException;

@Deprecated
int addInterceptor(String methodName, String[] args, Interceptor interceptor, Type type) throws InstrumentException, NotFoundInstrumentException;

List<MethodInfo> getDeclaredMethods(MethodFilter methodFilter);
@Deprecated
int reuseInterceptor(String methodName, String[] args, int interceptorId) throws InstrumentException, NotFoundInstrumentException;

MethodInfo getDeclaredMethod(String name, String[] parameterTypes);
@Deprecated
int reuseInterceptor(String methodName, String[] args, int interceptorId, Type type) throws InstrumentException, NotFoundInstrumentException;


@Deprecated
int addGroupInterceptor(String methodName, String[] args, Interceptor interceptor, String scopeName) throws InstrumentException, NotFoundInstrumentException;

@Deprecated
int addGroupInterceptor(String methodName, String[] args, Interceptor interceptor, InterceptorGroupDefinition scopeDefinition) throws InstrumentException;

@Deprecated
int addGroupInterceptorIfDeclared(String methodName, String[] args, Interceptor interceptor, String scopeName) throws InstrumentException;

@Deprecated
int addGroupInterceptorIfDeclared(String methodName, String[] args, Interceptor interceptor, InterceptorGroupDefinition scopeDefinition) throws InstrumentException;

@Deprecated
InstrumentClass getNestedClass(String className);

MethodInfo getConstructor(String[] parameterTypes);
@Deprecated
boolean addDebugLogBeforeAfterMethod();

public boolean isInterceptable();
@Deprecated
boolean addDebugLogBeforeAfterConstructor();

boolean hasDeclaredMethod(String methodName, String[] args);
@Deprecated
Class<?> toClass() throws InstrumentException;

boolean hasConstructor(String[] parameterTypeArray);

boolean hasMethod(String methodName, String[] parameterTypeArray, String returnType);
@Deprecated
boolean insertCodeAfterConstructor(String[] args, String code);

boolean hasField(String name, String type);

InstrumentClass getNestedClass(String className);

void addGetter(String getterName, String fieldName, String fieldType) throws InstrumentException;
@Deprecated
boolean insertCodeBeforeConstructor(String[] args, String code);

void addGetter(Class<?> interfaceType, String fieldName) throws InstrumentException;
@Deprecated
boolean insertCodeBeforeMethod(String methodName, String[] args, String code);

@Deprecated
boolean insertCodeAfterMethod(String methodName, String[] args, String code);

@Deprecated
void addTraceVariable(String variableName, String setterName, String getterName, String variableType, String initValue) throws InstrumentException;

/**
* You should check that class already have Declared method.
* If class already have method, this method throw exception.
*/
void addDelegatorMethod(String methodName, String[] args) throws InstrumentException;
@Deprecated
void addTraceVariable(String variableName, String setterName, String getterName, String variableType) throws InstrumentException;

@Deprecated
public int addAllConstructorInterceptor(Interceptor interceptor) throws InstrumentException, NotFoundInstrumentException;

@Deprecated
public int addAllConstructorInterceptor(Interceptor interceptor, Type type) throws InstrumentException, NotFoundInstrumentException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.navercorp.pinpoint.bootstrap.instrument;

import com.navercorp.pinpoint.bootstrap.interceptor.MethodDescriptor;
import com.navercorp.pinpoint.bootstrap.interceptor.group.ExecutionPolicy;
import com.navercorp.pinpoint.bootstrap.interceptor.group.InterceptorGroup;

/**
* @author emeroad
Expand All @@ -31,4 +33,12 @@ public interface MethodInfo {
boolean isConstructor();

MethodDescriptor getDescriptor();

int addInterceptor(String interceptorClassName, Object... constructorArgs) throws InstrumentException;

int addInterceptor(String interceptorClassName, InterceptorGroup group, Object... constructorArgs) throws InstrumentException;

int addInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object... constructorArgs) throws InstrumentException;

void addInterceptor(int interceptorId) throws InstrumentException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
import com.navercorp.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass;
import com.navercorp.pinpoint.bootstrap.interceptor.group.InterceptorGroup;
import com.navercorp.pinpoint.bootstrap.plugin.transformer.ClassFileTransformerBuilder;

Expand Down Expand Up @@ -81,13 +82,8 @@ public interface ProfilerPluginContext {
* @return {@link ProfilerConfig}
*/
public ProfilerConfig getConfig();

/**
* Get {@link ByteCodeInstrumentor}
*
* @return {@link ByteCodeInstrumentor}
*/
public ByteCodeInstrumentor getByteCodeInstrumentor();

public InstrumentClass getInstrumentClass(ClassLoader classLoader, String className, byte[] classFileBuffer);

public InterceptorGroup getInterceptorGroup(String name);

Expand All @@ -98,13 +94,29 @@ public interface ProfilerPluginContext {
*/
public void addApplicationTypeDetector(ApplicationTypeDetector... detectors);

public void addClassFileTransformer(String targetClassName, ClassFileTransformer transformer);

public void retransform(Class<?> target, ClassFileTransformer classEditor);




/**
* Add a {@link ClassEditor} to Pinpoint agent.
*
* @param classEditor
*/
public void addClassFileTransformer(ClassFileTransformer transformer);
@Deprecated

public void addClassFileTransformer(ClassFileTransformer transformer);
/**
* Get {@link ByteCodeInstrumentor}
*
* @return {@link ByteCodeInstrumentor}
*/
@Deprecated
public ByteCodeInstrumentor getByteCodeInstrumentor();

/**
* Get a {@link ClassFileTransformerBuilder}.
*
Expand All @@ -114,5 +126,6 @@ public interface ProfilerPluginContext {
* @param targetClassName target class name
* @return {@link ClassFileTransformerBuilder}
*/
@Deprecated
public ClassFileTransformerBuilder getClassFileTransformerBuilder(String targetClassName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
/**
* specify when this interceptor have to be invoked.
*/
public ExecutionPolicy executionPoint() default ExecutionPolicy.BOUNDARY;
public ExecutionPolicy executionPolicy() default ExecutionPolicy.BOUNDARY;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @author minwoo.jung
* @author jaehong.kim
*/
@Group(value = HttpClient4Constants.HTTP_CLIENT4_SCOPE, executionPoint = ExecutionPolicy.INTERNAL)
@Group(value = HttpClient4Constants.HTTP_CLIENT4_SCOPE, executionPolicy = ExecutionPolicy.INTERNAL)
public class HttpClientExecuteMethodInternalInterceptor implements SimpleAroundInterceptor, HttpClient4Constants {

private boolean isHasCallbackParam;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
*
* @see com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.client.TProtocolWriteFieldStopInterceptor TProtocolWriteFieldStopInterceptor
*/
@Group(value=THRIFT_CLIENT_SCOPE, executionPoint=ExecutionPolicy.BOUNDARY)
@Group(value=THRIFT_CLIENT_SCOPE, executionPolicy=ExecutionPolicy.BOUNDARY)
public class TServiceClientSendBaseInterceptor implements SimpleAroundInterceptor, ThriftConstants {

private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
/**
* @author HyunGil Jeong
*/
@Group(value=THRIFT_CLIENT_SCOPE, executionPoint=ExecutionPolicy.BOUNDARY)
@Group(value=THRIFT_CLIENT_SCOPE, executionPolicy=ExecutionPolicy.BOUNDARY)
public class TAsyncClientManagerCallInterceptor implements SimpleAroundInterceptor, ThriftConstants {

private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* @see com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadTTypeInterceptor TProtocolReadTTypeInterceptor
* @see com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadMessageEndInterceptor TProtocolReadMessageEndInterceptor
*/
@Group(value=THRIFT_SERVER_SCOPE, executionPoint=ExecutionPolicy.INTERNAL)
@Group(value=THRIFT_SERVER_SCOPE, executionPolicy=ExecutionPolicy.INTERNAL)
public class ProcessFunctionProcessInterceptor implements SimpleAroundInterceptor, ThriftConstants {

private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
* @see com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadTTypeInterceptor TProtocolReadTTypeInterceptor
* @see com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadMessageEndInterceptor TProtocolReadMessageEndInterceptor
*/
@Group(value=THRIFT_SERVER_SCOPE, executionPoint=ExecutionPolicy.BOUNDARY)
@Group(value=THRIFT_SERVER_SCOPE, executionPolicy=ExecutionPolicy.BOUNDARY)
public class TBaseProcessorProcessInterceptor implements SimpleAroundInterceptor, ThriftConstants {

private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
* @see com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadTTypeInterceptor TProtocolReadTTypeInterceptor
* @see com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadMessageEndInterceptor TProtocolReadMessageEndInterceptor
*/
@Group(value=THRIFT_SERVER_SCOPE, executionPoint=ExecutionPolicy.BOUNDARY)
@Group(value=THRIFT_SERVER_SCOPE, executionPolicy=ExecutionPolicy.BOUNDARY)
public class TBaseAsyncProcessorProcessInterceptor implements SimpleAroundInterceptor, ThriftConstants {

private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*
* @see com.navercorp.pinpoint.plugin.thrift.interceptor.client.TServiceClientSendBaseInterceptor TServiceClientSendBaseInterceptor
*/
@Group(value=THRIFT_CLIENT_SCOPE, executionPoint=ExecutionPolicy.INTERNAL)
@Group(value=THRIFT_CLIENT_SCOPE, executionPolicy=ExecutionPolicy.INTERNAL)
public class TProtocolWriteFieldStopInterceptor implements SimpleAroundInterceptor, ThriftConstants {

private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* @see com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadTTypeInterceptor TProtocolReadTTypeInterceptor
* @see com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadMessageEndInterceptor TProtocolReadMessageEndInterceptor
*/
@Group(value=THRIFT_SERVER_SCOPE, executionPoint=ExecutionPolicy.INTERNAL)
@Group(value=THRIFT_SERVER_SCOPE, executionPolicy=ExecutionPolicy.INTERNAL)
public class TProtocolReadFieldBeginInterceptor implements SimpleAroundInterceptor, ThriftConstants {

private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
Expand Down
Loading

0 comments on commit 7c4ad07

Please sign in to comment.