ObjectName objectName = new ObjectName("speed:type=MockGBean");
kernel.loadGBean(objectName, mockGBean);
kernel.startGBean(objectName);
// reflect proxy
ProxyFactory vmProxyFactory = new VMProxyFactory(MyInterface.class);
ProxyMethodInterceptor vmMethodInterceptor = vmProxyFactory.getMethodInterceptor();
MyInterface vmProxy = (MyInterface) vmProxyFactory.create(vmMethodInterceptor);
vmMethodInterceptor.connect(kernel.getMBeanServer(), objectName);
iterations = 50000;
for (int i = 0; i < iterations; i++) {
vmProxy.doNothing();
}
start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
vmProxy.doNothing();
}
end = System.currentTimeMillis();
printResults("ReflectionProxy", end, start, iterations);
// cglib proxy (front half)
/*
ProxyFactory frontCGLibProxyFactory = new CGLibProxyFactory(MyInterface.class);
ProxyMethodInterceptor frontCGLibMethodInterceptor = new CGLibMethodInterceptor(MyInterface.class);
Class enhancedType = frontCGLibProxyFactory.create(frontCGLibMethodInterceptor).getClass();
frontCGLibMethodInterceptor = new CGLibMethodInterceptor(enhancedType) {
public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) throws Throwable {
return null;
}
};
MyInterface frontCGLibProxy = (MyInterface) frontCGLibProxyFactory.create(frontCGLibMethodInterceptor);
frontCGLibMethodInterceptor.connect(kernel.getMBeanServer(), objectName);
iterations = 100000000;
for (int i = 0; i < iterations; i++) {
frontCGLibProxy.doNothing();
}
start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
frontCGLibProxy.doNothing();
}
end = System.currentTimeMillis();
printResults("Front CGLibProxy", end, start, iterations);
*/
// Raw Invoker
RawInvoker rawInvoker = (RawInvoker) kernel.getAttribute(objectName, "$$RAW_INVOKER$$");
int rawIndex = ((Integer) rawInvoker.getOperationIndex().get(new GOperationSignature("doNothing", new String[0]))).intValue();
iterations = 2000000;
for (int i = 0; i < iterations; i++) {
rawInvoker.invoke(rawIndex, NO_ARGS);
}
start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
rawInvoker.invoke(rawIndex, NO_ARGS);
}
end = System.currentTimeMillis();
printResults("Raw Invoker", end, start, iterations);
// cglib proxy
ProxyFactory cgLibProxyFactory = new CGLibProxyFactory(MyInterface.class);
ProxyMethodInterceptor cgLibMethodInterceptor = cgLibProxyFactory.getMethodInterceptor();
MyInterface cgLibProxy = (MyInterface) cgLibProxyFactory.create(cgLibMethodInterceptor);
cgLibMethodInterceptor.connect(kernel.getMBeanServer(), objectName);
iterations = 1000000;
for (int i = 0; i < iterations; i++) {
cgLibProxy.doNothing();
}