本文整理汇总了Java中javassist.util.proxy.ProxyFactory.setUseCache方法的典型用法代码示例。如果您正苦于以下问题:Java ProxyFactory.setUseCache方法的具体用法?Java ProxyFactory.setUseCache怎么用?Java ProxyFactory.setUseCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.util.proxy.ProxyFactory
的用法示例。
在下文中一共展示了ProxyFactory.setUseCache方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: benchmarkJavassist
import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
* Performs a benchmark for a trivial class creation using javassist proxies.
*
* @return The created instance, in order to avoid JIT removal.
*/
@Benchmark
public Class<?> benchmarkJavassist() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setUseCache(false);
ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {
@Override
public ClassLoader get(ProxyFactory proxyFactory) {
return newClassLoader();
}
};
proxyFactory.setSuperclass(baseClass);
proxyFactory.setFilter(new MethodFilter() {
public boolean isHandled(Method method) {
return false;
}
});
return proxyFactory.createClass();
}
示例2: createJavassistProxyFactory
import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private static ProxyFactory createJavassistProxyFactory(Class<?> persistentClass, Class<?>[] interfaces) {
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(persistentClass);
factory.setInterfaces(interfaces);
factory.setFilter(METHOD_FILTERS);
factory.setUseCache(true);
if (WRITE_CLASSES_DIRECTORY != null) {
factory.writeDirectory = WRITE_CLASSES_DIRECTORY;
}
return factory;
}
示例3: createProxyFactory
import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private static ProxyFactory createProxyFactory(Class<?> persistentClass, Class<?>[] interfaces) {
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(persistentClass);
factory.setInterfaces(interfaces);
factory.setFilter(METHOD_FILTERS);
factory.setUseCache(true);
if (WRITE_CLASSES_DIRECTORY != null) {
factory.writeDirectory = WRITE_CLASSES_DIRECTORY;
}
return factory;
}
示例4: benchmarkJavassist
import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
* Performs a benchmark of a class extension using javassist proxies.
*
* @return The created instance, in order to avoid JIT removal.
* @throws java.lang.Exception If the invocation causes an exception.
*/
@Benchmark
public ExampleClass benchmarkJavassist() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory() {
@Override
protected ClassLoader getClassLoader() {
return newClassLoader();
}
};
proxyFactory.setUseCache(false);
proxyFactory.setSuperclass(baseClass);
proxyFactory.setFilter(new MethodFilter() {
public boolean isHandled(Method method) {
return method.getDeclaringClass() == baseClass;
}
});
@SuppressWarnings("unchecked")
Object instance = proxyFactory.createClass().getDeclaredConstructor().newInstance();
((javassist.util.proxy.Proxy) instance).setHandler(new MethodHandler() {
public Object invoke(Object self,
Method thisMethod,
Method proceed,
Object[] args) throws Throwable {
return proceed.invoke(self, args);
}
});
return (ExampleClass) instance;
}
示例5: load
import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@Override
public Class<?> load(final Class<?> frameClass) throws Exception {
final Class<?> handlerClass = getHandlerClass(frameClass);
ProxyFactory proxyFactory = new ProxyFactory() {
@Override
protected ClassLoader getClassLoader() {
return new URLClassLoader(new URL[0], handlerClass.getClassLoader());
}
};
proxyFactory.setUseCache(false);
proxyFactory.setSuperclass(handlerClass);
return proxyFactory.createClass();
}
示例6: benchmarkJavassist
import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
* Performs a benchmark of an interface implementation using javassist proxies.
*
* @return The created instance, in order to avoid JIT removal.
* @throws java.lang.Exception If the reflective invocation causes an exception.
*/
@Benchmark
public ExampleInterface benchmarkJavassist() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setUseCache(false);
ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {
@Override
public ClassLoader get(ProxyFactory proxyFactory) {
return newClassLoader();
}
};
proxyFactory.setSuperclass(Object.class);
proxyFactory.setInterfaces(new Class<?>[]{baseClass});
proxyFactory.setFilter(new MethodFilter() {
public boolean isHandled(Method method) {
return true;
}
});
@SuppressWarnings("unchecked")
Object instance = proxyFactory.createClass().getDeclaredConstructor().newInstance();
((javassist.util.proxy.Proxy) instance).setHandler(new MethodHandler() {
public Object invoke(Object self,
Method thisMethod,
Method proceed,
Object[] args) throws Throwable {
Class<?> returnType = thisMethod.getReturnType();
if (returnType.isPrimitive()) {
if (returnType == boolean.class) {
return defaultBooleanValue;
} else if (returnType == byte.class) {
return defaultByteValue;
} else if (returnType == short.class) {
return defaultShortValue;
} else if (returnType == char.class) {
return defaultCharValue;
} else if (returnType == int.class) {
return defaultIntValue;
} else if (returnType == long.class) {
return defaultLongValue;
} else if (returnType == float.class) {
return defaultFloatValue;
} else {
return defaultDoubleValue;
}
} else {
return defaultReferenceValue;
}
}
});
return (ExampleInterface) instance;
}
示例7: createProxy
import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
public static Object createProxy(final EntityMeta meta, final Object key, final EntitySession session, final ElementIdentity factory) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException
{
if (null == meta)
{
return null;
}
final Class<?> clazz = meta.getType(meta.getId().fromKey(key));
Class<?> proxy = proxies.get(clazz);
if (null == proxy)
{
ProxyFactory.classLoaderProvider = pf ->
{
final List<ClassLoader> loaders = new ArrayList<>(2);
loaders.add(AssociationUtils.class.getClassLoader());
if (null == pf)
{
return new CompositeClassLoader(ProxyFactory.class.getClassLoader(), loaders);
}
final Class<?> type = pf.getSuperclass();
if (type != null)
{
loaders.add(type.getClassLoader());
}
return new CompositeClassLoader(ProxyFactory.class.getClassLoader(), loaders);
};
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setSuperclass(clazz);
proxyFactory.setUseCache(false);
proxy = proxyFactory.createClass();
proxies.put(clazz, proxy);
}
final Object instance = proxy.newInstance();
if (null == instance)
{
return null;
}
final AssociationAccessor accessor = new ManyToOneAccessor(key, session, factory);
final LazyAssociationHandler handler = new LazyAssociationHandler(meta, accessor, session);
((ProxyObject) instance).setHandler(handler);
return clazz.cast(instance);
}