use of net.sf.cglib.proxy.CallbackHelper in project byte-buddy by raphw.
the class ClassByImplementationBenchmark method benchmarkCglib.
/**
* Performs a benchmark of an interface implementation using cglib.
*
* @return The created instance, in order to avoid JIT removal.
*/
@Benchmark
public ExampleInterface benchmarkCglib() {
Enhancer enhancer = new Enhancer();
enhancer.setUseCache(false);
enhancer.setClassLoader(newClassLoader());
enhancer.setSuperclass(baseClass);
CallbackHelper callbackHelper = new CallbackHelper(Object.class, new Class[] { baseClass }) {
@Override
protected Object getCallback(Method method) {
if (method.getDeclaringClass() == baseClass) {
return new FixedValue() {
@Override
public Object loadObject() throws Exception {
return null;
}
};
} else {
return NoOp.INSTANCE;
}
}
};
enhancer.setCallbackFilter(callbackHelper);
enhancer.setCallbacks(callbackHelper.getCallbacks());
return (ExampleInterface) enhancer.create();
}
Aggregations