use of net.sf.cglib.proxy.Enhancer in project mastering-java by Kingminghuang.
the class JavaMethodAreaOOM method main.
/**
* Under JDK 1.6 or before
* VM Args: -XX:PermSize=10M -XX:MaxPermSize=10M
* @param args
*/
public static void main(String[] args) {
while (true) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(OOMObject.class);
enhancer.setUseCache(false);
enhancer.setCallback((MethodInterceptor) (obj, method, objArgs, methodProxy) -> methodProxy.invokeSuper(obj, objArgs));
enhancer.create();
}
}
use of net.sf.cglib.proxy.Enhancer in project yyl_example by Relucent.
the class CgLibTest method main.
public static void main(String[] args) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(HelloWorld.class);
//设置回调方法实现类
enhancer.setCallback(new MethodInterceptorImpl());
//实例化已经添加回调实现的HELLOWORLD实例
HelloWorld my = (HelloWorld) enhancer.create();
int result = my.print();
System.out.println(result);
}
use of net.sf.cglib.proxy.Enhancer in project yyl_example by Relucent.
the class EnhancerTest method main.
public static void main(String[] args) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(null);
enhancer.setInterfaces(new Class[] { I.class });
enhancer.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
if (Object.class.equals(method.getDeclaringClass())) {
return methodProxy.invokeSuper(o, args);
}
System.out.println("->" + method.getName());
return null;
}
});
I a = I.class.cast(enhancer.create());
a.method();
}
use of net.sf.cglib.proxy.Enhancer in project aries by apache.
the class AsyncService method proxyClass.
private Object proxyClass(Class<?> mostSpecificClass, TrackingInvocationHandler handler, ClassLoader classLoader) {
acceptClassType(mostSpecificClass);
Enhancer enhancer = new Enhancer();
enhancer.setClassLoader(classLoader);
enhancer.setSuperclass(mostSpecificClass);
enhancer.setCallback(handler);
return enhancer.create();
}
use of net.sf.cglib.proxy.Enhancer in project cloudstack by apache.
the class AsyncCallbackDispatcher method getTarget.
@SuppressWarnings("unchecked")
public T getTarget() {
Class<?> clz = _targetObject.getClass();
String clzName = clz.getName();
if (clzName.contains("EnhancerByCloudStack"))
clz = clz.getSuperclass();
Enhancer en = null;
synchronized (enMap) {
en = enMap.get(clz);
if (en == null) {
en = new Enhancer();
en.setSuperclass(clz);
en.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
return null;
}
});
enMap.put(clz, en);
}
}
try {
T t = (T) en.create();
Factory factory = (Factory) t;
factory.setCallback(0, new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
if (arg1.getParameterTypes().length == 0 && arg1.getName().equals("finalize")) {
return null;
} else {
_callbackMethod = arg1;
_callbackMethod.setAccessible(true);
return null;
}
}
});
return t;
} catch (Throwable e) {
s_logger.error("Unexpected exception", e);
}
return null;
}
Aggregations