[#49] Removed ParameterExtractorFactory

This commit is contained in:
Jongho Moon
2014-11-21 15:47:05 +09:00
parent 43488a1cc2
commit a473ac95fa
11 changed files with 129 additions and 194 deletions
@@ -88,7 +88,6 @@ public class ClassEditorBuilder {
private Condition condition;
private String scopeName;
private Object[] constructorArguments;
private ParameterExtractorFactory parameterExtractorFactory;
private boolean singleton;
public InterceptorBuilder(String methodName, String[] parameterTypeNames, MethodFilter filter) {
@@ -112,11 +111,6 @@ public class ClassEditorBuilder {
return this;
}
public InterceptorBuilder using(ParameterExtractorFactory factory) {
this.parameterExtractorFactory = factory;
return this;
}
public InterceptorBuilder singleton(boolean singleton) {
this.singleton = singleton;
return this;
@@ -128,7 +122,7 @@ public class ClassEditorBuilder {
}
private InterceptorInjector build() {
InterceptorFactory interceptorFactory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, constructorArguments, parameterExtractorFactory, scopeName);
InterceptorFactory interceptorFactory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, constructorArguments, scopeName);
InterceptorInjector injector;
@@ -11,7 +11,6 @@ import com.nhn.pinpoint.bootstrap.instrument.MethodInfo;
import com.nhn.pinpoint.bootstrap.instrument.Scope;
import com.nhn.pinpoint.bootstrap.interceptor.Interceptor;
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
import com.nhn.pinpoint.bootstrap.interceptor.StaticAroundInterceptor;
import com.nhn.pinpoint.exception.PinpointException;
@@ -25,16 +24,14 @@ public class DefaultInterceptorFactory implements InterceptorFactory {
private final String interceptorClassName;
private final Object[] providedArguments;
private final ParameterExtractorFactory parameterExtractorFactory;
private final String scopeName;
public DefaultInterceptorFactory(ByteCodeInstrumentor instrumentor, TraceContext traceContext, String interceptorClassName, Object[] providedArguments, ParameterExtractorFactory parameterExtractorFactory, String scopeName) {
public DefaultInterceptorFactory(ByteCodeInstrumentor instrumentor, TraceContext traceContext, String interceptorClassName, Object[] providedArguments, String scopeName) {
this.instrumentor = instrumentor;
this.traceContext = traceContext;
this.interceptorClassName = interceptorClassName;
this.providedArguments = providedArguments == null ? NO_ARGS : providedArguments;
this.parameterExtractorFactory = parameterExtractorFactory;
this.scopeName = scopeName;
}
@@ -178,14 +175,12 @@ public class DefaultInterceptorFactory implements InterceptorFactory {
return traceContext;
} else if (type == MethodDescriptor.class) {
return targetMethod.getDescriptor();
} else if (type == ParameterExtractor.class) {
if (parameterExtractorFactory == null) {
return null;
}
return parameterExtractorFactory.get(target, targetMethod);
} else if (type == ByteCodeInstrumentor.class) {
return instrumentor;
} else if (type == MethodInfo.class) {
return targetMethod;
} else if (type == InstrumentClass.class) {
return target;
}
return null;
@@ -1,9 +0,0 @@
package com.nhn.pinpoint.bootstrap.plugin;
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
import com.nhn.pinpoint.bootstrap.instrument.MethodInfo;
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
public interface ParameterExtractorFactory {
public ParameterExtractor get(InstrumentClass targetClass, MethodInfo targetMethod);
}
@@ -27,19 +27,17 @@ public class DefaultInterceptorFactoryTest {
private final InstrumentClass aClass = mock(InstrumentClass.class);
private final MethodInfo aMethod = mock(MethodInfo.class);
private final MethodDescriptor descriptor = mock(MethodDescriptor.class);
private final ParameterExtractorFactory extractorFactory = mock(ParameterExtractorFactory.class);
private final ParameterExtractor extractor = mock(ParameterExtractor.class);
@Before
public void setUp() {
reset(instrumentor, traceContext, aClass, aMethod);
when(aMethod.getDescriptor()).thenReturn(descriptor);
when(extractorFactory.get(aClass, aMethod)).thenReturn(extractor);
}
@Test
public void test0() throws Exception {
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0", null, null, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0", null, null);
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
assertEquals(TestInterceptor0.class, interceptor.getClass());
@@ -49,7 +47,7 @@ public class DefaultInterceptorFactoryTest {
public void test1() throws Exception {
Object[] args = new Object[] { "arg0" };
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0", args, null, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0", args, null);
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
assertEquals(TestInterceptor0.class, interceptor.getClass());
@@ -60,7 +58,7 @@ public class DefaultInterceptorFactoryTest {
public void test2() throws Exception {
Object[] args = new Object[] { 1 };
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0", args, null, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0", args, null);
factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
}
@@ -68,7 +66,7 @@ public class DefaultInterceptorFactoryTest {
public void test3() throws Exception {
Object[] args = new Object[] { "arg0", (byte)1, (short)2, (float)3.0 };
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", args, null, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", args, null);
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
assertEquals(TestInterceptor1.class, interceptor.getClass());
@@ -82,7 +80,7 @@ public class DefaultInterceptorFactoryTest {
public void test4() throws Exception {
Object[] args = new Object[] { (byte)1, (short)2, (float)3.0, "arg0" };
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", args, null, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", args, null);
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
assertEquals(TestInterceptor1.class, interceptor.getClass());
@@ -96,7 +94,7 @@ public class DefaultInterceptorFactoryTest {
public void test5() throws Exception {
Object[] args = new Object[] { (short)2, (float)3.0, "arg0", (byte)1 };
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", args, null, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", args, null);
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
assertEquals(TestInterceptor1.class, interceptor.getClass());
@@ -110,7 +108,7 @@ public class DefaultInterceptorFactoryTest {
public void test6() throws Exception {
Object[] args = new Object[] { (float)3.0, (short)2, (byte)1, "arg0" };
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", args, null, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", args, null);
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
assertEquals(TestInterceptor1.class, interceptor.getClass());
@@ -124,13 +122,13 @@ public class DefaultInterceptorFactoryTest {
public void test7() throws Exception {
Object[] args = new Object[] { (double)3.0, (short)2, (byte)1, "arg0" };
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", args, null, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", null, null);
factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
}
@Test(expected=PinpointException.class)
public void test8() throws Exception {
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", null, null, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1", null, null);
factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
}
@@ -138,7 +136,7 @@ public class DefaultInterceptorFactoryTest {
public void test9() throws Exception {
Object[] args = new Object[] { "arg0", 1, 2.0, true, 3L };
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2", args, extractorFactory, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2", args, null);
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
assertEquals(TestInterceptor2.class, interceptor.getClass());
@@ -149,14 +147,15 @@ public class DefaultInterceptorFactoryTest {
assertEquals(args[4], getField(interceptor, "field4"));
assertSame(descriptor, getField(interceptor, "descriptor"));
assertSame(extractor, getField(interceptor, "parameterExtractor"));
assertSame(aClass, getField(interceptor, "targetClass"));
assertSame(aMethod, getField(interceptor, "targetMethod"));
}
@Test
public void test10() throws Exception {
Object[] args = new Object[] { "arg0", 1, 2.0 };
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2", args, extractorFactory, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2", args, null);
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
assertEquals(TestInterceptor2.class, interceptor.getClass());
@@ -167,14 +166,15 @@ public class DefaultInterceptorFactoryTest {
assertEquals(0L, getField(interceptor, "field4"));
assertSame(descriptor, getField(interceptor, "descriptor"));
assertSame(extractor, getField(interceptor, "parameterExtractor"));
assertSame(aClass, getField(interceptor, "targetClass"));
assertSame(aMethod, getField(interceptor, "targetMethod"));
}
@Test
public void test11() throws Exception {
Object[] args = new Object[] { "arg0", 1 };
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2", args, extractorFactory, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2", args, null);
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
assertEquals(TestInterceptor2.class, interceptor.getClass());
@@ -185,12 +185,13 @@ public class DefaultInterceptorFactoryTest {
assertEquals(0L, getField(interceptor, "field4"));
assertSame(descriptor, getField(interceptor, "descriptor"));
assertSame(extractor, getField(interceptor, "parameterExtractor"));
assertSame(aClass, getField(interceptor, "targetClass"));
assertSame(aMethod, getField(interceptor, "targetMethod"));
}
@Test
public void test12() throws Exception {
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2", null, extractorFactory, null);
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2", null, null);
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
assertEquals(TestInterceptor2.class, interceptor.getClass());
@@ -201,23 +202,27 @@ public class DefaultInterceptorFactoryTest {
assertEquals(0L, getField(interceptor, "field4"));
assertSame(descriptor, getField(interceptor, "descriptor"));
assertSame(extractor, getField(interceptor, "parameterExtractor"));
assertSame(aClass, getField(interceptor, "targetClass"));
assertSame(aMethod, getField(interceptor, "targetMethod"));
}
@Test
public void test13() throws Exception {
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2", null, null, null);
Object[] args = new Object[] { "arg0" };
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2", args, null);
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
assertEquals(TestInterceptor2.class, interceptor.getClass());
assertEquals(null, getField(interceptor, "field0"));
assertEquals(args[0], getField(interceptor, "field0"));
assertEquals(0, getField(interceptor, "field1"));
assertEquals(0.0, getField(interceptor, "field2"));
assertEquals(false, getField(interceptor, "field3"));
assertEquals(0L, getField(interceptor, "field4"));
assertSame(descriptor, getField(interceptor, "descriptor"));
assertNull(getField(interceptor, "parameterExtractor"));
assertSame(aClass, getField(interceptor, "targetClass"));
assertNull(getField(interceptor, "targetMethod"));
}
@@ -2,8 +2,9 @@ package com.nhn.pinpoint.bootstrap.plugin;
import com.nhn.pinpoint.bootstrap.context.TraceContext;
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
import com.nhn.pinpoint.bootstrap.instrument.MethodInfo;
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
public class TestInterceptors {
@@ -95,7 +96,8 @@ public class TestInterceptors {
private final TraceContext context;
private final ByteCodeInstrumentor instrumentor;
private final MethodDescriptor descriptor;
private final ParameterExtractor parameterExtractor;
private final InstrumentClass targetClass;
private final MethodInfo targetMethod;
private final String field0;
private final int field1;
@@ -104,11 +106,12 @@ public class TestInterceptors {
private final long field4;
public TestInterceptor2(String field0, TraceContext context, int field1, ByteCodeInstrumentor instrumentor, double field2, MethodDescriptor descriptor, boolean field3, ParameterExtractor parameterExtractor, long field4) {
public TestInterceptor2(String field0, TraceContext context, int field1, ByteCodeInstrumentor instrumentor, double field2, MethodDescriptor descriptor, boolean field3, InstrumentClass targetClass, MethodInfo targetMethod, long field4) {
this.context = context;
this.instrumentor = instrumentor;
this.descriptor = descriptor;
this.parameterExtractor = parameterExtractor;
this.targetClass = targetClass;
this.targetMethod = targetMethod;
this.field0 = field0;
this.field1 = field1;
this.field2 = field2;
@@ -116,11 +119,12 @@ public class TestInterceptors {
this.field4 = field4;
}
public TestInterceptor2(String field0, int field1, double field2, TraceContext context, ByteCodeInstrumentor instrumentor, MethodDescriptor descriptor, ParameterExtractor parameterExtractor) {
public TestInterceptor2(String field0, int field1, double field2, TraceContext context, ByteCodeInstrumentor instrumentor, InstrumentClass targetClass, MethodDescriptor descriptor, MethodInfo targetMethod) {
this.context = context;
this.instrumentor = instrumentor;
this.descriptor = descriptor;
this.parameterExtractor = parameterExtractor;
this.targetClass = targetClass;
this.targetMethod = targetMethod;
this.field0 = field0;
this.field1 = field1;
this.field2 = field2;
@@ -128,11 +132,12 @@ public class TestInterceptors {
this.field4 = 0;
}
public TestInterceptor2(TraceContext context, ByteCodeInstrumentor instrumentor, MethodDescriptor descriptor, ParameterExtractor parameterExtractor, String field0, int field1) {
public TestInterceptor2(TraceContext context, ByteCodeInstrumentor instrumentor, MethodDescriptor descriptor, InstrumentClass targetClass, MethodInfo targetMethod, String field0, int field1) {
this.context = context;
this.instrumentor = instrumentor;
this.descriptor = descriptor;
this.parameterExtractor = parameterExtractor;
this.targetClass = targetClass;
this.targetMethod = targetMethod;
this.field0 = field0;
this.field1 = field1;
this.field2 = 0;
@@ -140,11 +145,12 @@ public class TestInterceptors {
this.field4 = 0;
}
public TestInterceptor2(TraceContext context, ByteCodeInstrumentor instrumentor, MethodDescriptor descriptor, ParameterExtractor parameterExtractor) {
public TestInterceptor2(TraceContext context, ByteCodeInstrumentor instrumentor, InstrumentClass targetClass, MethodDescriptor descriptor, MethodInfo targetMethod) {
this.context = context;
this.instrumentor = instrumentor;
this.descriptor = descriptor;
this.parameterExtractor = parameterExtractor;
this.targetClass = targetClass;
this.targetMethod = targetMethod;
this.field0 = null;
this.field1 = 0;
this.field2 = 0;
@@ -152,12 +158,13 @@ public class TestInterceptors {
this.field4 = 0;
}
public TestInterceptor2(TraceContext context, ByteCodeInstrumentor instrumentor, MethodDescriptor descriptor) {
this.context = context;
this.instrumentor = instrumentor;
public TestInterceptor2(MethodDescriptor descriptor, InstrumentClass targetClass, String field0) {
this.context = null;
this.instrumentor = null;
this.descriptor = descriptor;
this.parameterExtractor = null;
this.field0 = null;
this.targetClass = targetClass;
this.targetMethod = null;
this.field0 = field0;
this.field1 = 0;
this.field2 = 0;
this.field3 = false;
@@ -176,8 +183,12 @@ public class TestInterceptors {
return descriptor;
}
public ParameterExtractor getParameterExtractor() {
return parameterExtractor;
public MethodInfo getTargetMethod() {
return targetMethod;
}
public InstrumentClass getTargetClass() {
return targetClass;
}
public String getField0() {
@@ -47,7 +47,7 @@ public class ArcusPlugin implements ProfilerPlugin {
}
private ClassEditor getArcusClientEditor(ProfilerPluginContext context, ArcusPluginConfig config) {
boolean traceArcusKey = config.isArcusKeyTrace();
boolean traceKey = config.isArcusKeyTrace();
ClassEditorBuilder builder = context.newClassEditorBuilder();
builder.edit("net.spy.memcached.ArcusClient");
@@ -63,8 +63,8 @@ public class ArcusPlugin implements ProfilerPlugin {
builder.interceptMethodsFilteredBy(new ArcusMethodFilter())
.with("com.nhn.pinpoint.plugin.arcus.interceptor.ApiInterceptor")
.in(Commons.ARCUS_SCOPE)
.using(traceArcusKey ? Commons.ARCUS_KEY_EXTRACTOR_FACTORY : null);
.constructedWith(traceKey)
.in(Constants.ARCUS_SCOPE);
return builder.build();
}
@@ -105,16 +105,16 @@ public class ArcusPlugin implements ProfilerPlugin {
.with("com.nhn.pinpoint.plugin.arcus.interceptor.FrontCacheGetFutureConstructInterceptor");
builder.intercept("get", "long", "java.util.concurrent.TimeUnit")
.with("com.nhn.pinpoint.plugin.arcus.interceptor.FrontCacheGetFutureGetInterceptor")
.in(Commons.ARCUS_SCOPE);
.in(Constants.ARCUS_SCOPE);
builder.intercept("get")
.with("com.nhn.pinpoint.plugin.arcus.interceptor.FrontCacheGetFutureGetInterceptor")
.in(Commons.ARCUS_SCOPE);
.in(Constants.ARCUS_SCOPE);
return builder.build();
}
private ClassEditor getFrontCacheMemcachedClientEditor(ProfilerPluginContext context, ArcusPluginConfig config) {
boolean traceArcusKey = config.isMemcachedKeyTrace();
boolean traceKey = config.isMemcachedKeyTrace();
ClassEditorBuilder builder = context.newClassEditorBuilder();
builder.edit("net.spy.memcached.plugin.FrontCacheMemcachedClient");
@@ -129,15 +129,15 @@ public class ArcusPlugin implements ProfilerPlugin {
builder.interceptMethodsFilteredBy(new FrontCacheMemcachedMethodFilter())
.with("com.nhn.pinpoint.plugin.arcus.interceptor.ApiInterceptor")
.in(Commons.ARCUS_SCOPE)
.using(traceArcusKey ? Commons.ARCUS_KEY_EXTRACTOR_FACTORY : null);
.in(Constants.ARCUS_SCOPE)
.constructedWith(traceKey);
return builder.build();
}
private ClassEditor getMemcachedClientEditor(ProfilerPluginContext context, ArcusPluginConfig config) {
boolean traceArcusKey = config.isMemcachedKeyTrace();
boolean traceKey = config.isMemcachedKeyTrace();
ClassEditorBuilder builder = context.newClassEditorBuilder();
builder.edit("net.spy.memcached.MemcachedClient");
@@ -158,8 +158,8 @@ public class ArcusPlugin implements ProfilerPlugin {
builder.interceptMethodsFilteredBy(new MemcachedMethodFilter())
.with("com.nhn.pinpoint.plugin.arcus.interceptor.ApiInterceptor")
.in(Commons.ARCUS_SCOPE)
.using(traceArcusKey ? Commons.ARCUS_KEY_EXTRACTOR_FACTORY : null);
.in(Constants.ARCUS_SCOPE)
.constructedWith(traceKey);
return builder.build();
}
@@ -172,7 +172,7 @@ public class ArcusPlugin implements ProfilerPlugin {
builder.intercept("get", "long", "java.util.concurrent.TimeUnit")
.with("com.nhn.pinpoint.plugin.arcus.interceptor.FutureGetInterceptor")
.in(Commons.ARCUS_SCOPE);
.in(Constants.ARCUS_SCOPE);
return builder.build();
}
@@ -1,26 +0,0 @@
package com.nhn.pinpoint.plugin.arcus;
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
import com.nhn.pinpoint.bootstrap.instrument.MethodInfo;
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
import com.nhn.pinpoint.bootstrap.plugin.ParameterExtractorFactory;
public abstract class Commons {
private Commons() {}
public static final String ARCUS_SCOPE = "ArcusScope";
public static final ParameterExtractorFactory ARCUS_KEY_EXTRACTOR_FACTORY = new ParameterExtractorFactory() {
@Override
public ParameterExtractor get(InstrumentClass targetClass, MethodInfo targetMethod) {
final int index = ParameterUtils.findFirstString(targetMethod, 3);
if (index != -1) {
return new IndexParameterExtractor(index);
}
return null;
}
};
}
@@ -0,0 +1,8 @@
package com.nhn.pinpoint.plugin.arcus;
public abstract class Constants {
private Constants() {}
public static final String ARCUS_SCOPE = "ArcusScope";
}
@@ -1,30 +0,0 @@
package com.nhn.pinpoint.plugin.arcus;
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
/**
* @author emeroad
*/
public class IndexParameterExtractor implements ParameterExtractor {
private final int index;
public IndexParameterExtractor(int index) {
this.index = index;
}
@Override
public int getIndex() {
return index;
}
@Override
public Object extractObject(Object[] parameterList) {
if (parameterList == null) {
return NULL;
}
return parameterList[index];
}
}
@@ -8,9 +8,11 @@ import net.spy.memcached.MemcachedNode;
import net.spy.memcached.ops.Operation;
import com.nhn.pinpoint.bootstrap.context.RecordableTrace;
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
import com.nhn.pinpoint.bootstrap.context.TraceContext;
import com.nhn.pinpoint.bootstrap.instrument.MethodInfo;
import com.nhn.pinpoint.bootstrap.interceptor.SpanEventSimpleAroundInterceptor;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.plugin.arcus.ParameterUtils;
import com.nhn.pinpoint.plugin.arcus.accessor.OperationAccessor;
import com.nhn.pinpoint.plugin.arcus.accessor.ServiceCodeAccessor;
@@ -18,15 +20,29 @@ import com.nhn.pinpoint.plugin.arcus.accessor.ServiceCodeAccessor;
* @author emeroad
*/
public class ApiInterceptor extends SpanEventSimpleAroundInterceptor {
private final ParameterExtractor parameterExtractor;
private final boolean traceKey;
private final int keyIndex;
public ApiInterceptor() {
this(null);
}
public ApiInterceptor(ParameterExtractor parameterExtractor) {
public ApiInterceptor(TraceContext context, MethodInfo targetMethod, boolean traceKey) {
super(ApiInterceptor.class);
this.parameterExtractor = parameterExtractor;
if (traceKey) {
int index = ParameterUtils.findFirstString(targetMethod, 3);
if (index != -1) {
this.traceKey = true;
this.keyIndex = index;
} else {
this.traceKey = false;
this.keyIndex = -1;
}
} else {
this.traceKey = false;
this.keyIndex = -1;
}
this.setTraceContext(context);
this.setMethodDescriptor(targetMethod.getDescriptor());
}
@Override
@@ -36,11 +52,9 @@ public class ApiInterceptor extends SpanEventSimpleAroundInterceptor {
@Override
public void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) {
if (parameterExtractor != null) {
final int index = parameterExtractor.getIndex();
final Object recordObject = parameterExtractor.extractObject(args);
trace.recordApi(getMethodDescriptor(), recordObject, index);
if (traceKey) {
final Object recordObject = args[keyIndex];
trace.recordApi(getMethodDescriptor(), recordObject, keyIndex);
} else {
trace.recordApi(getMethodDescriptor());
}
@@ -52,6 +66,7 @@ public class ApiInterceptor extends SpanEventSimpleAroundInterceptor {
if (op != null) {
MemcachedNode handlingNode = op.getHandlingNode();
SocketAddress socketAddress = handlingNode.getSocketAddress();
if (socketAddress instanceof InetSocketAddress) {
InetSocketAddress address = (InetSocketAddress) socketAddress;
trace.recordEndPoint(address.getHostName() + ":" + address.getPort());
@@ -2,63 +2,35 @@ package com.nhn.pinpoint.plugin.arcus.interceptor;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.List;
import net.spy.memcached.ConnectionFactory;
import net.spy.memcached.MemcachedClient;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.nhn.pinpoint.bootstrap.context.TraceContext;
import com.nhn.pinpoint.bootstrap.instrument.MethodInfo;
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
import com.nhn.pinpoint.plugin.arcus.IndexParameterExtractor;
import com.nhn.pinpoint.plugin.arcus.interceptor.ApiInterceptor;
import com.nhn.pinpoint.plugin.arcus.accessor.ServiceCodeAccessor;
import com.nhn.pinpoint.profiler.interceptor.DefaultMethodDescriptor;
import com.nhn.pinpoint.test.interceptor.BaseInterceptorTest;
public class ApiInterceptorTest extends BaseInterceptorTest {
public class ApiInterceptorTest {
static final Logger logger = LoggerFactory.getLogger(ApiInterceptorTest.class);
@Test
public void testAround() {
String[] parameterTypes = new String[] { "java.lang.String", "int", "java.lang.Object" };
String[] parameterNames = new String[] { "key", "exptime", "value" };
Object[] args = new Object[] { "key", 10, "my_value" };
ApiInterceptor interceptor = new ApiInterceptor(new IndexParameterExtractor(0));
MemcachedClient client = mock(MockMemcachedClient.class);
TraceContext traceContext = mock(TraceContext.class);
MethodDescriptor methodDescriptor = new DefaultMethodDescriptor(Object.class.getName(), "set", parameterTypes, parameterNames);
MethodInfo methodInfo = mock(MethodInfo.class);
ServiceCodeAccessor target = mock(ServiceCodeAccessor.class);
@Before
public void beforeEach() {
setInterceptor(interceptor);
MethodDescriptor methodDescriptor = new DefaultMethodDescriptor(
MockMemcachedClient.class.getName(), "set", new String[] {
"java.lang.String", "int", "java.lang.Object" },
new String[] { "key", "exptime", "value" });
/* NPE 때문에 일단 빼기로 함.
setMethodDescriptor(methodDescriptor);
*/
super.beforeEach();
}
when(methodInfo.getDescriptor()).thenReturn(methodDescriptor);
when(methodInfo.getParameterTypes()).thenReturn(parameterTypes);
when(target.__getServiceCode()).thenReturn("serviceCode");
@Test
public void testAround() {
Object[] args = new Object[] {"key", 10, "my_value"};
interceptor.before(client, args);
interceptor.after(client, args, null, null);
}
ApiInterceptor interceptor = new ApiInterceptor(traceContext, methodInfo, true);
/**
* Fake MemcachedClient
*/
class MockMemcachedClient extends MemcachedClient {
public MockMemcachedClient(ConnectionFactory cf,
List<InetSocketAddress> addrs) throws IOException {
super(cf, addrs);
}
public String __getServiceCode() {
return "MEMCACHED";
}
}
interceptor.before(target, args);
interceptor.after(target, args, null, null);
}
}