当前位置: 首页>>代码示例>>Java>>正文


Java MethodAccess.get方法代码示例

本文整理汇总了Java中com.esotericsoftware.reflectasm.MethodAccess.get方法的典型用法代码示例。如果您正苦于以下问题:Java MethodAccess.get方法的具体用法?Java MethodAccess.get怎么用?Java MethodAccess.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.esotericsoftware.reflectasm.MethodAccess的用法示例。


在下文中一共展示了MethodAccess.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invokeMethod

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
/**
 * 执行某对象方法
 * 
 * @param owner
 *            对象
 * @param methodName
 *            方法名
 * @param args
 *            参数
 * @return 方法返回值
 */
public static final Object invokeMethod(Object owner, String methodName, Object... args) {
    Class<?> ownerClass = owner.getClass();
    String key = null;
    if (args != null) {
        Class<?>[] argsClass = new Class[args.length];
        for (int i = 0, j = args.length; i < j; i++) {
            if (args[i] != null) {
                argsClass[i] = args[i].getClass();
            }
        }
        key = ownerClass + "_" + methodName + "_" + StringUtils.join(argsClass, ","); // 用于区分重载的方法
    } else {
        key = ownerClass + "_" + methodName; // 用于区分重载的方法
    }
    MethodAccess methodAccess = methodMap.get(key);
    if (methodAccess == null) {
        methodAccess = MethodAccess.get(ownerClass);
        methodMap.put(key, methodAccess); // 缓存Method对象
    }
    return methodAccess.invoke(owner, methodName, args);
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:33,代码来源:InstanceUtil.java

示例2: invokeMethod

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
/**
 * 执行某对象方法
 *
 * @param owner
 *            对象
 * @param methodName
 *            方法名
 * @param args
 *            参数
 * @return 方法返回值
 */
public static final Object invokeMethod(Object owner, String methodName, Object... args) {
    Class<?> ownerClass = owner.getClass();
    String key = null;
    if (args != null) {
        Class<?>[] argsClass = new Class[args.length];
        for (int i = 0, j = args.length; i < j; i++) {
            if (args[i] != null) {
                argsClass[i] = args[i].getClass();
            }
        }
        key = ownerClass + "_" + methodName + "_" + StringUtils.join(argsClass, ","); // 用于区分重载的方法
    } else {
        key = ownerClass + "_" + methodName; // 用于区分重载的方法
    }
    MethodAccess methodAccess = methodMap.get(key);
    if (methodAccess == null) {
        methodAccess = MethodAccess.get(ownerClass);
        methodMap.put(key, methodAccess); // 缓存Method对象
    }
    return methodAccess.invoke(owner, methodName, args);
}
 
开发者ID:liuxx001,项目名称:bird-java,代码行数:33,代码来源:InstanceHelper.java

示例3: wrap

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
private void wrap(String route, Receiver<RequestType> handler, Method method, RoleType[] role) {
    MethodAccess access = MethodAccess.get(handler.getClass());

    int index = access.getIndex(method.getName());
    use(route, request -> {
        try {
            access.invoke(handler, index, request);
        } catch (Throwable e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                throw new RuntimeException(e);
            }
        }
    }, role);
}
 
开发者ID:codingchili,项目名称:chili-core,代码行数:17,代码来源:Protocol.java

示例4: doMethodCall

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
private Object doMethodCall(Code code) {
	Object[] params = new Object[code.b];
	for (int i = 0; i < code.b; ++i) {
		params[i] = regs[code.a + i + 2];
	}

	Object methodName = regs[code.a + 1];
	Object object = regs[code.a];

	try {
		MethodAccess access = methodAccessCache.get(object.getClass());
		if (access == null) {
			access = MethodAccess.get(object.getClass());
			methodAccessCache.put(object.getClass(), access);
		}

		Object retval = access
				.invoke(object, methodName.toString(), params);
		return retval;
	} catch (IllegalArgumentException e) {
		warn(e.toString());
		return null;
	}
}
 
开发者ID:tokuhirom,项目名称:jtt,代码行数:25,代码来源:VM.java

示例5: invoke

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
@Override
public Object invoke(RemotingProtocol msg) throws Exception {
    Stopwatch watch = Stopwatch.createStarted();

    String methodName = msg.getMethod();
    Object[] args = msg.getArgs();
    Class<?>[] mParamsType = msg.getmParamsTypes();
    Class<?> implClass = GuiceDI.getInstance(ServiceInfosHolder.class).getImplClass(msg.getDefineClass(), msg.getImplClass());

    if (implClass == null) {
        logger.error(String.format("define:%s impl:%s", msg.getDefineClass(), msg.getImplClass()));
        throw new NoImplClassException(msg.getDefineClass().getName());
    }
    String mkey = String.format("%s_%s", implClass.getSimpleName(), methodName);

    MethodAccess access = methodCache.get(mkey);
    if (access == null) {
        logger.info(String.format("method:%s args:%s", methodName, JSON.toJSONString(mParamsType)));
        access = MethodAccess.get(implClass);
        if (access != null) {
            methodCache.putIfAbsent(mkey, access);
        }
    }

    if (access == null) {
        throw new NoImplMethodException(implClass.getName(), methodName);
    }

    Object target = GuiceDI.getInstance(ServiceInfosHolder.class).getOjbectFromClass(implClass.getName());

    Object retval = null;
    //此步反射 非常耗时 
    retval = access.invoke(target, methodName, args);
    if (logger.isDebugEnabled())
        logger.debug(String.format("jdk invoke use:%s", watch.toString()));
    return retval;
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:38,代码来源:ReflectAsmInvoker.java

示例6: addTag

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
public void addTag(String tag, Method method) {
    if (tagMap.containsKey(tag)) {
        logger.warn(String.format("cid: %s, 存在相同的tag : %s", cid, tag));
    }
    Class<?> cls = method.getDeclaringClass();

    final Tag t = new Tag();
    t.setInvokeCls(cls);
    t.setMethodName(method.getName());
    Reconsume mReconsume = method.getAnnotation(Reconsume.class);
    if (null != mReconsume) {
        t.setReconsume(mReconsume.value());
    } else {
        Reconsume cReconsume = cls.getAnnotation(Reconsume.class);
        if (null != cReconsume) {
            t.setReconsume(cReconsume.value());
        }
    }
    MethodAccess methodAccess = check.get(cls);
    if (null == methodAccess) {
        methodAccess = MethodAccess.get(cls);
        check.put(cls, methodAccess);
    }
    t.setMethodAccess(methodAccess);
    t.setArgumentExtractors(ArgumentExtractors.getArgumentExtractor(method, method.getParameterTypes(), beanFactory));
    Stream.of(tag.split("\\|\\|")).forEach(tag_ -> tagMap.put(tag_.trim(), t));
}
 
开发者ID:onepiecex,项目名称:mq-aliyun,代码行数:28,代码来源:ConsumerId.java

示例7: handle

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
private Object handle(Request req) throws Throwable {
    String className = req.getClassName();
    String methodName = req.getMethodName();
    Class<?>[] parameterTypes = req.getParameterTypes();
    Object[] parameters = req.getParameters();
    //new object
    Class<?> clazz = Class.forName(className);
    ConstructorAccess<?> constructorAccess = ConstructorAccess.get(clazz);
    Object invokeObject = constructorAccess.newInstance();
    //get method access
    MethodAccess methodAccess = MethodAccess.get(clazz);
    Object result = methodAccess.invoke(invokeObject, methodName, parameterTypes, parameters);

    return result;
}
 
开发者ID:Yaccc,项目名称:xRPC,代码行数:16,代码来源:NettyServerHander.java

示例8: main

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
public static void main(String[] args) {
    User user = new User();
    //使用reflectasm生产User访问类
    MethodAccess access = MethodAccess.get(User.class);
    //invoke setName方法name值
    access.invoke(user, "setName", "张三");
    //invoke getName方法 获得值
    String name = (String) access.invoke(user, "getName", null);
    System.out.println(name);
}
 
开发者ID:ansafari,项目名称:melon,代码行数:11,代码来源:ReflectAsmTest.java

示例9: JATOInstanceActor

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
public JATOInstanceActor(JATOActorFactory actorFactory, T instance, Channel<MethodMessage> mailbox, Fiber fiber) {
    super(actorFactory, mailbox, fiber);
    this.instance = instance;
    this.clazz = (Class<T>) instance.getClass();
    methodAccess = MethodAccess.get(clazz);
    methodNameMap = buildMethodNameMap(methodAccess);
}
 
开发者ID:mySingleLive,项目名称:jato,代码行数:8,代码来源:JATOInstanceActor.java

示例10: getMethodAccess

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
private MethodAccess getMethodAccess(final Class<?> cls) {
    MethodAccess methodAccess = clsMethodPool.get(cls);

    if (methodAccess == null) {
        methodAccess = MethodAccess.get(cls);
        clsMethodPool.put(cls, methodAccess);
    }

    return methodAccess;
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:11,代码来源:ReflectASM.java

示例11: cache

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
private static MethodAccess cache(Object obj) {

        synchronized (obj.getClass()) {
            MethodAccess methodAccess = MethodAccess.get(obj.getClass());
            Field[] fields = null;
            try {
                // 这里查找了包括父类的属性
                fields = ReflectionUtils.findFields(obj.getClass());
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
            List<String> fieldList = new ArrayList<String>(fields.length);
            for (Field field : fields) {
                if (Modifier.isPrivate(field.getModifiers()) && !Modifier.isStatic(field.getModifiers())) {
                    //非公共私有变量
                    String fieldName = capitalize(field.getName());
                    int getIndex = methodAccess.getIndex("get" + fieldName);
                    int setIndex = methodAccess.getIndex("set" + fieldName);
                    METHOD_INDEX_MAP.put(obj.getClass().getName() + ".get" + fieldName, getIndex);
                    METHOD_INDEX_MAP.put(obj.getClass().getName() + ".set" + fieldName, setIndex);
                    fieldList.add(fieldName);
                }
            }
            FIELD_MAP.put(obj.getClass(), fieldList);
            METHOD_MAP.put(obj.getClass(), methodAccess);
            return methodAccess;
        }
    }
 
开发者ID:WenZuHuai,项目名称:light-task-scheduler,代码行数:29,代码来源:BeanUtils.java

示例12: MethodCall

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
public MethodCall(Object context, Class<?> contextClass, Method method) {
	this.context = context;
	this.requireParams = MethodCallUtils.getMethodParamsArray(method);

	methodAccess = MethodAccess.get(contextClass);
	methodIdx = methodAccess.getIndex(method.getName(), requireParams);
}
 
开发者ID:316181444,项目名称:GameServerFramework,代码行数:8,代码来源:MethodCall.java

示例13: ReflectedActionViewVarDef

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
protected ReflectedActionViewVarDef(Meta meta, Class<?> cls, Method method, App app) {
    this.cls = cls;
    this.method = method;
    if (!meta.isStatic) {
        methodAccess = MethodAccess.get(cls);
        methodIndex = methodAccess.getIndex(method.getName(), method.getParameterTypes());
    }
    initLoaders(app);
}
 
开发者ID:actframework,项目名称:actframework,代码行数:10,代码来源:ImplicitVariableProvider.java

示例14: init

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
private synchronized void init() {
    if (null != jobClass) {
        return;
    }
    disabled = false;
    jobClass = $.classForName(classInfo.className(), cl);
    disabled = disabled || !Env.matches(jobClass);
    method = methodInfo.method();
    disabled = disabled || !Env.matches(method);
    if (disabled) {
        return;
    }
    isStatic = methodInfo.isStatic();
    if (!isStatic) {
        singleton = ReflectedInvokerHelper.tryGetSingleton(jobClass, app);
    }
    ParamValueLoaderManager paramValueLoaderManager = app.service(ParamValueLoaderManager.class);
    if (null != paramValueLoaderManager) {
        paramValueLoaderService = paramValueLoaderManager.get(JobContext.class);
    } else {
        // this job is scheduled to run before ParamValueLoaderManager initialized
    }

    if (!Modifier.isStatic(method.getModifiers())) {
        Class[] paramTypes = paramTypes();
        //constructorAccess = ConstructorAccess.get(controllerClass);
        methodAccess = MethodAccess.get(jobClass);
        methodIndex = methodAccess.getIndex(methodInfo.name(), paramTypes);
    } else {
        method.setAccessible(true);
    }
}
 
开发者ID:actframework,项目名称:actframework,代码行数:33,代码来源:ReflectedJobInvoker.java

示例15: ReflectedCommandExecutor

import com.esotericsoftware.reflectasm.MethodAccess; //导入方法依赖的package包/类
public ReflectedCommandExecutor(CommandMethodMetaInfo methodMetaInfo, App app) {
    this.methodMetaInfo = $.notNull(methodMetaInfo);
    this.app = $.NPE(app);
    this.cl = app.classLoader();
    this.paramTypes = paramTypes();
    this.paramCount = methodMetaInfo.paramCount();
    this.isStatic = methodMetaInfo.isStatic();
    this.commanderClass = $.classForName(methodMetaInfo.classInfo().className(), cl);
    try {
        this.method = commanderClass.getMethod(methodMetaInfo.methodName(), paramTypes);
        this.async = null != method.getAnnotation(Async.class);
        this.reportProgress = method.getAnnotation(ReportProgress.class);
        FastJsonFilter filterAnno = method.getAnnotation(FastJsonFilter.class);
        if (null != filterAnno) {
            filters = filterAnno.value();
        }
        FastJsonFeature featureAnno = method.getAnnotation(FastJsonFeature.class);
        if (null != featureAnno) {
            features = featureAnno.value();
        }
    } catch (NoSuchMethodException e) {
        throw E.unexpected(e);
    }
    if (!methodMetaInfo.isStatic()) {
        methodAccess = MethodAccess.get(commanderClass);
        commandIndex = methodAccess.getIndex(methodMetaInfo.methodName(), paramTypes);
    } else {
        method.setAccessible(true);
    }
    Pattern pattern = method.getAnnotation(Pattern.class);
    if (null != pattern) {
        this.pattern = pattern.value();
    }
    this.paramLoaderService = app.service(ParamValueLoaderManager.class).get(CliContext.class);
    this.buildParsingContext();
}
 
开发者ID:actframework,项目名称:actframework,代码行数:37,代码来源:ReflectedCommandExecutor.java


注:本文中的com.esotericsoftware.reflectasm.MethodAccess.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。