本文整理汇总了Java中net.sf.cglib.proxy.Enhancer.setUseCache方法的典型用法代码示例。如果您正苦于以下问题:Java Enhancer.setUseCache方法的具体用法?Java Enhancer.setUseCache怎么用?Java Enhancer.setUseCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.cglib.proxy.Enhancer
的用法示例。
在下文中一共展示了Enhancer.setUseCache方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static void main(String[] args) {
while(true) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(ClassPermGenOOM.class);
enhancer.setUseCache(Boolean.FALSE);
enhancer.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2,
MethodProxy arg3) throws Throwable {
return arg3.invokeSuper(arg0, arg2);
}
});
enhancer.create();
}
}
示例2: main
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static void main(String[] args) {
Tmp tmp = new Tmp();
while (!Thread.interrupted()) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(Tmp.class);
enhancer.setUseCache(false);
enhancer.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
return arg3.invokeSuper(arg0, arg2);
}
});
enhancer.create();
}
System.out.println(tmp.hashCode());
}
示例3: BasicProxyFactoryImpl
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public BasicProxyFactoryImpl(Class superClass, Class[] interfaces) {
if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) {
throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
}
Enhancer en = new Enhancer();
en.setUseCache( false );
en.setInterceptDuringConstruction( false );
en.setUseFactory( true );
en.setCallbackTypes( CALLBACK_TYPES );
en.setCallbackFilter( FINALIZE_FILTER );
if ( superClass != null ) {
en.setSuperclass( superClass );
}
if ( interfaces != null && interfaces.length > 0 ) {
en.setInterfaces( interfaces );
}
proxyClass = en.createClass();
try {
factory = ( Factory ) proxyClass.newInstance();
}
catch ( Throwable t ) {
throw new HibernateException( "Unable to build CGLIB Factory instance" );
}
}
示例4: benchmarkCglib
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
* 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();
}
示例5: main
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static void main(String[] args) {
while (true){
Enhancer enhancer = new Enhancer() ;
enhancer.setSuperclass(HeapOOM.class);
enhancer.setUseCache(false) ;
enhancer.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
return methodProxy.invoke(o,objects) ;
}
});
enhancer.create() ;
}
}
示例6: createProxy
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T createProxy(Class<T> targetClass) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(targetClass);
enhancer.setUseCache(false);
enhancer.setCallback(new MethodInterceptor() {
public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
System.out.println("方法调用前 先执行我。。。。。");
Object obj = methodProxy.invokeSuper(object, args);
System.out.println("方法调用后 再执行我。。。。。");
return obj;
}
});
return (T)enhancer.create();
}
示例7: forClass
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static <T> MethodProxy<T> forClass(Class<T> clazz) {
MethodSignatureInterceptor methodSignatureInterceptor = new MethodSignatureInterceptor();
final Enhancer enhancer = new Enhancer();
enhancer.setUseCache(false);
enhancer.setSuperclass(clazz);
enhancer.setCallbackType(methodSignatureInterceptor.getClass());
final Class<?> proxyClass = enhancer.createClass();
Enhancer.registerCallbacks(proxyClass, new Callback[]{methodSignatureInterceptor});
T proxied = (T) ObjenesisHelper.newInstance(proxyClass);
return new MethodProxy<>(methodSignatureInterceptor, proxied);
}
示例8: getInstance
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
* <pre>
* cglib生成的子类实例
* </pre>
*
* @param supperClass
* @return
*/
public static Object getInstance(Class<?> supperClass) {
Enhancer enhancer = new Enhancer();
//enhancer.setClassLoader(Thread.currentThread().getContextClassLoader());
enhancer.setSuperclass(supperClass);
enhancer.setCallback(new Interceptor());
enhancer.setUseCache(false);
Object dest = enhancer.create();
//logger.info(dest.toString());
return dest;
}
示例9: createEnhancedClass
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected Class<? extends T> createEnhancedClass(Class<T> clazz, Class[] ancillaryTypes) {
if (clazz == Object.class) {
clazz = (Class<T>) TrivialSubclassOfObjectToWorkAroundCGLIBBug.class;
}
Enhancer e = new Enhancer();
e.setClassLoader(clazz.getClassLoader());
e.setSuperclass(clazz);
e.setInterfaces(ancillaryTypes);
e.setUseFactory(true);
e.setUseCache(true);
e.setCallbackType(MethodInterceptor.class);
return e.createClass();
}
示例10: benchmarkCglib
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
* Performs a benchmark for a trivial class creation using cglib.
*
* @return The created instance, in order to avoid JIT removal.
*/
@Benchmark
public Class<?> benchmarkCglib() {
Enhancer enhancer = new Enhancer();
enhancer.setUseCache(false);
enhancer.setClassLoader(newClassLoader());
enhancer.setSuperclass(baseClass);
enhancer.setCallbackType(NoOp.class);
return enhancer.createClass();
}
示例11: enhanceServiceEndpointInterface
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
private Class enhanceServiceEndpointInterface(Class serviceEndpointInterface, ClassLoader classLoader) {
Enhancer enhancer = new Enhancer();
enhancer.setClassLoader(classLoader);
enhancer.setSuperclass(GenericServiceEndpointWrapper.class);
enhancer.setInterfaces(new Class[]{serviceEndpointInterface});
enhancer.setCallbackFilter(new NoOverrideCallbackFilter(GenericServiceEndpointWrapper.class));
enhancer.setCallbackTypes(new Class[]{NoOp.class, MethodInterceptor.class});
enhancer.setUseFactory(false);
enhancer.setUseCache(false);
return enhancer.createClass();
}
示例12: setUp
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Setup
public void setUp() {
for(int i = 0; i < COUNT; i++) {
Enhancer enhancer = new Enhancer();
enhancer.setUseCache(false); // deactivate the cache to get a new instance each time
enhancer.setCallbackType(NoOp.class);
Class<?> c = enhancer.createClass();
toInstantiate[i] = c;
}
}