Java Code Examples for net.sf.cglib.proxy.Enhancer#setUseCache()
The following examples show how to use
net.sf.cglib.proxy.Enhancer#setUseCache() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyFactoryFactoryImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
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" ); } }
Example 2
Source File: ClassByImplementationBenchmark.java From byte-buddy with Apache License 2.0 | 6 votes |
/** * 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}) { protected Object getCallback(Method method) { if (method.getDeclaringClass() == baseClass) { return new FixedValue() { public Object loadObject() { return null; } }; } else { return NoOp.INSTANCE; } } }; enhancer.setCallbackFilter(callbackHelper); enhancer.setCallbacks(callbackHelper.getCallbacks()); return (ExampleInterface) enhancer.create(); }
Example 3
Source File: NoHeapJvmOomExecutor.java From chaosblade-exec-jvm with Apache License 2.0 | 5 votes |
@Override protected void innerRun(EnhancerModel enhancerModel, JvmOomConfiguration jvmOomConfiguration) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(OomObject.class); enhancer.setUseCache(false); enhancer.setCallback(new MethodInterceptor() { @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { return proxy.invokeSuper(obj, args); } }); enhancer.create(); }
Example 4
Source File: MyTest4.java From Project with Apache License 2.0 | 5 votes |
public static void main(String[] args) { //使用动态代理动态生成类(不是实例) while (true) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(MyTest4.class); enhancer.setUseCache(false); enhancer.setCallback((MethodInterceptor) (obj, method, ags, proxy) -> proxy.invokeSuper(obj, ags)); System.out.println("Hello World"); // 在运行期不断创建 MyTest 类的子类 enhancer.create(); } }
Example 5
Source File: MetaSpaceOOM.java From Java-Interview with MIT License | 5 votes |
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() ; } }
Example 6
Source File: MetaSpaceOOM.java From Java-Interview with MIT License | 5 votes |
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() ; } }
Example 7
Source File: MethodAreaOOM.java From JavaBase with MIT License | 5 votes |
public static void main(String[] args) { while (true) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(OOMObject.class); enhancer.setUseCache(false); enhancer.setCallback((MethodInterceptor) (obj, method, args1, proxy) -> proxy.invokeSuper(obj, args) ); enhancer.create(); } }
Example 8
Source File: TrivialClassCreationBenchmark.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * 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(); }
Example 9
Source File: SeiFactoryImpl.java From tomee with Apache License 2.0 | 5 votes |
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(); }
Example 10
Source File: ConcurrentGetInstantiator.java From objenesis with Apache License 2.0 | 5 votes |
@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; } }