本文整理汇总了Java中net.sf.cglib.reflect.FastMethod.invoke方法的典型用法代码示例。如果您正苦于以下问题:Java FastMethod.invoke方法的具体用法?Java FastMethod.invoke怎么用?Java FastMethod.invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.cglib.reflect.FastMethod
的用法示例。
在下文中一共展示了FastMethod.invoke方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
private Object handle(RpcRequest request) throws Throwable {
String className = request.getClassName();
Object serviceBean = handlerMap.get(className);
Class<?> serviceClass = serviceBean.getClass();
String methodName = request.getMethodName();
Class<?>[] parameterTypes = request.getParameterTypes();
Object[] parameters = request.getParameters();
/*
* Method method = serviceClass.getMethod(methodName, parameterTypes);
* method.setAccessible(true); return method.invoke(serviceBean,
* parameters);
*/
FastClass serviceFastClass = FastClass.create(serviceClass);
FastMethod serviceFastMethod = serviceFastClass.getMethod(methodName, parameterTypes);
return serviceFastMethod.invoke(serviceBean, parameters);
}
示例2: invoke
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
/**
* �������AOP���
*
* @param methodName ��������
* @param className ��ȫ��
* @param dao BaseDAO
* @param aspectData AOP xml�����ļ�����
* @param queryWrapper ��ѯ����
* @param queryEnumType ��ѯ����
* @return �Ƿ����ִ��
*/
private boolean invoke(String methodName, String className, SqlSession dao, AspectData aspectData,
QueryAspectWrapper queryWrapper, QueryEnumType queryEnumType)
{
if (getJavaClass(className) == null || aepectObj == null)
return false;
Class<?>[] params = {SqlSession.class, AspectData.class, QueryAspectWrapper.class, QueryEnumType.class};
try
{
FastClass fastClass = ReflectHelper.getFastClass(aspectClass);
FastMethod mt = ReflectHelper.getFastMethod(fastClass, methodName, params);
if (mt == null)
return false;
Boolean ret = (Boolean)mt.invoke(aepectObj, new Object[] {dao, aspectData, queryWrapper, queryEnumType});
return ret;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
示例3: doconfirmorcancel
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
private void doconfirmorcancel(Class<?> clazz, String lookup, String method, //
Class<?>[] mParamsTypes, Object[] args) throws Exception {
Class<?> confirmclass = GuiceDI.getInstance(ServiceInfosHolder.class).getImplClass(clazz, lookup);
FastClass confrimfast = FastClass.create(confirmclass);
// fast class反射调用
Object confirmtarget = confrimfast.newInstance();
FastMethod confirmmethod = confrimfast.getMethod(method, mParamsTypes);
confirmmethod.invoke(confirmtarget, args);
}
示例4: handleRequest
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
protected Object handleRequest(RpcRequest request) throws Exception {
Class<?> serviceClass = serviceBean.getClass();
String methodName = request.getMethodName();
Class<?>[] parameterTypes = request.getParameterTypes();
Object[] parameters = request.getParameters();
// use cglib go to invoke
FastClass serviceFastClass = FastClass.create(serviceClass);
FastMethod serviceFastMethod = serviceFastClass.getMethod(methodName, parameterTypes);
return serviceFastMethod.invoke(serviceBean, parameters);
}
示例5: dispatch
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
private boolean dispatch(Dispatcher<BaseType> dispatcher, BaseType instance) {
FastMethod method = getMethod(dispatcher, instance);
if (method == null) {
return false;
}
try {
method.invoke(this, new Object[]{ instance });
return true;
} catch (InvocationTargetException e) {
throw Throwables.propagate(e.getCause());
}
}
示例6: dispatchBefore
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
private boolean dispatchBefore(Dispatcher<BaseType> dispatcher, BaseType instance) {
FastMethod method = getMethod(dispatcher, instance);
if (method == null) {
return true; // non-presence of before method means continue execution
}
try {
Object result = method.invoke(this, new Object[]{ instance });
if (method.getReturnType().equals(Boolean.TYPE)) {
return Boolean.class.cast(result); // method determines whether to continue
}
return true;
} catch (InvocationTargetException e) {
throw Throwables.propagate(e.getCause());
}
}
示例7: dotMethodDuckInvokeMethod
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
/**
* NOTE: Code-generation-invoked method, method name and parameter order matters
* @param method method
* @param target target
* @param args args
* @param forge forge
* @return result
*/
public static Object dotMethodDuckInvokeMethod(FastMethod method, Object target, Object[] args, ExprDotMethodForgeDuck forge) {
try {
return method.invoke(target, args);
} catch (InvocationTargetException e) {
String message = JavaClassHelper.getMessageInvocationTarget(forge.getStatementName(), method.getJavaMethod(), target.getClass().getName(), args, e.getTargetException());
log.error(message, e.getTargetException());
}
return null;
}
示例8: testGetterSpecial
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
public void testGetterSpecial() throws Exception {
Class clazz = SupportBeanComplexProps.class;
FastClass fastClass = FastClass.create(Thread.currentThread().getContextClassLoader(), clazz);
// set up bean
SupportBeanComplexProps bean = SupportBeanComplexProps.makeDefaultBean();
// try mapped property
Method method = clazz.getMethod("getMapped", new Class[]{String.class});
FastMethod fastMethod = fastClass.getMethod(method);
Object result = fastMethod.invoke(bean, new Object[]{"keyOne"});
assertEquals("valueOne", result);
result = fastMethod.invoke(bean, new Object[]{"keyTwo"});
assertEquals("valueTwo", result);
// try index property
method = clazz.getMethod("getIndexed", new Class[]{int.class});
fastMethod = fastClass.getMethod(method);
result = fastMethod.invoke(bean, new Object[]{0});
assertEquals(1, result);
result = fastMethod.invoke(bean, new Object[]{1});
assertEquals(2, result);
// try nested property
method = clazz.getMethod("getNested", new Class[]{});
fastMethod = fastClass.getMethod(method);
SupportBeanComplexProps.SupportBeanSpecialGetterNested nested = (SupportBeanComplexProps.SupportBeanSpecialGetterNested) fastMethod.invoke(bean, new Object[]{});
Class nestedClazz = SupportBeanComplexProps.SupportBeanSpecialGetterNested.class;
Method methodNested = nestedClazz.getMethod("getNestedValue", new Class[]{});
FastClass fastClassNested = FastClass.create(Thread.currentThread().getContextClassLoader(), nestedClazz);
fastClassNested.getMethod(methodNested);
}
示例9: invokeService
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
public static RpcResponse invokeService(RpcRequest request, Object serviceBean) {
if (serviceBean==null) {
serviceBean = serviceMap.get(request.getClassName());
}
if (serviceBean == null) {
// TODO
}
RpcResponse response = new RpcResponse();
response.setRequestId(request.getRequestId());
try {
Class<?> serviceClass = serviceBean.getClass();
String methodName = request.getMethodName();
Class<?>[] parameterTypes = request.getParameterTypes();
Object[] parameters = request.getParameters();
/*Method method = serviceClass.getMethod(methodName, parameterTypes);
method.setAccessible(true);
return method.invoke(serviceBean, parameters);*/
FastClass serviceFastClass = FastClass.create(serviceClass);
FastMethod serviceFastMethod = serviceFastClass.getMethod(methodName, parameterTypes);
Object result = serviceFastMethod.invoke(serviceBean, parameters);
response.setResult(result);
} catch (Throwable t) {
t.printStackTrace();
response.setError(t);
}
return response;
}
示例10: invokeService
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
/**
* init local rpc service map
*/
public static RpcResponse invokeService(RpcRequest request, Object serviceBean) {
if (serviceBean==null) {
serviceBean = regitsryMap.get(request.getRegistryKey());
}
if (serviceBean == null) {
// TODO
}
RpcResponse response = new RpcResponse();
response.setRequestId(request.getRequestId());
try {
Class<?> serviceClass = serviceBean.getClass();
String methodName = request.getMethodName();
Class<?>[] parameterTypes = request.getParameterTypes();
Object[] parameters = request.getParameters();
/*Method method = serviceClass.getMethod(methodName, parameterTypes);
method.setAccessible(true);
return method.invoke(serviceBean, parameters);*/
FastClass serviceFastClass = FastClass.create(serviceClass);
FastMethod serviceFastMethod = serviceFastClass.getMethod(methodName, parameterTypes);
Object result = serviceFastMethod.invoke(serviceBean, parameters);
response.setResult(result);
} catch (Throwable t) {
t.printStackTrace();
response.setError(t);
}
return response;
}
示例11: getResultSetValue
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
/**
* ��������ָ������ֵ
*
* @param rs �����
* @param javaType ����JAVA����
* @param colnumName ����
* @return ֵ
* @throws Exception
*/
public static final Object getResultSetValue(ResultSet rs, Class<?> javaType, String colnumName)
throws Exception
{
String jdbcmt = TransformFactory.getInstance().getJdbcResultMethod(javaType);
FastMethod method = ReflectHelper.getResultSetStringFastMethod(jdbcmt);
if (method == null)
{
Class<?> rsClass = rs.getClass();
Method m = rsClass.getMethod(jdbcmt, new Class[] { String.class });
return m.invoke(rs, colnumName);
}
return method.invoke(rs, new Object[] { colnumName });
}
示例12: getProperty
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
private static Object getProperty(Object object, String property) {
FastMethod method = getPropertyMethod(object.getClass(), property);
try {
return method.invoke(object, ArrayUtils.EMPTY_OBJECT_ARRAY);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException("Unable to call method " + method + '.', e);
}
}
示例13: performanceForWrite
import net.sf.cglib.reflect.FastMethod; //导入方法依赖的package包/类
@Test
public void performanceForWrite() {
try {
AccountVO vo = new AccountVO();
long start = System.currentTimeMillis();
for (int i = 0, len = 0; i < LOOP; i++) {
vo.code_account = "test";// setter
VOHelper.cast(String.class, vo.code_account);//因为asm中有赋值的保护,所以,把其他的也补偿一个,以作为对比
}
long end = System.currentTimeMillis();
System.out.println("getter/setter:" + (end - start));// 性能基线
Field f = vo.getClass().getDeclaredField("code_account");
f.setAccessible(true);// 加上确实快一些
start = System.currentTimeMillis();
for (int i = 0; i < LOOP; i++) {
f.set(vo, "test");// setter
VOHelper.cast(String.class, vo.code_account);//因为asm中有赋值的保护,所以,把其他的也补偿一个,以作为对比
}
end = System.currentTimeMillis();
System.out.println("ref:" + (end - start));
//
Class[] paramTypes_write = new Class[] { String.class };
Object[] args_write = new Object[] { "test" };
FastClass fc = FastClass.create(AccountVO.class);
FastMethod write = fc.getMethod("setName", paramTypes_write);
start = System.currentTimeMillis();
for (int i = 0; i < LOOP; i++) {
write.invoke(vo, args_write);
VOHelper.cast(String.class, vo.code_account);//因为asm中有赋值的保护,所以,把其他的也补偿一个,以作为对比
}
end = System.currentTimeMillis();
System.out.println("cglib:" + (end - start));
// mybatis reflection
MetaObject object = SystemMetaObject.forObject(vo);
//
start = System.currentTimeMillis();
for (int i = 0; i < LOOP; i++) {
String v = VOHelper.cast(String.class, "test_new");//因为asm中有赋值的保护,所以,把其他的也补偿一个,以作为对比
object.setValue("code_account", v);//setter
}
end = System.currentTimeMillis();
System.out.println("mybatis ref:" + (end - start));
//asm style
IValueObjectWrapper<AccountVO> wrapper = EntityWrapperHelper.wrapper(AccountVO.class);
start = System.currentTimeMillis();
for (int i = 0; i < LOOP; i++) {
wrapper.set(vo, "code_account", "test_new");//setter
}
end = System.currentTimeMillis();
System.out.println("asm style:" + (end - start));
} catch (Exception e) {
Assert.fail("soso", e);
}
}