use of net.sf.cglib.proxy.CallbackFilter in project cloudstack by apache.
the class MethodCapturer method capture.
@SuppressWarnings("unchecked")
public static <T> MethodCapturer<T> capture(T obj) {
synchronized (s_cache) {
MethodCapturer<T> capturer = (MethodCapturer<T>) s_cache.get(obj);
if (capturer != null) {
return capturer;
}
final MethodCapturer<T> capturerNew = new MethodCapturer<T>();
Enhancer en = new Enhancer();
en.setSuperclass(obj.getClass());
en.setCallbacks(new Callback[] { new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
capturerNew.setMethod(arg1);
return null;
}
}, new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
return null;
}
} });
en.setCallbackFilter(new CallbackFilter() {
@Override
public int accept(Method method) {
if (method.getParameterTypes().length == 0 && method.getName().equals("finalize")) {
return 1;
}
return 0;
}
});
capturerNew.setInstance((T) en.create());
// here
if (s_cache.size() < CACHE_SIZE) {
s_cache.put(obj, capturerNew);
}
return capturerNew;
}
}
Aggregations