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


Java MethodProxy类代码示例

本文整理汇总了Java中net.sf.cglib.proxy.MethodProxy的典型用法代码示例。如果您正苦于以下问题:Java MethodProxy类的具体用法?Java MethodProxy怎么用?Java MethodProxy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: intercept

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
    if (args == null || args.length > 1 || args.length == 0) {
        return methodProxy.invokeSuper(obj, args);
    }

    if (method.getName().contains("guiRender") || method.getName().contains("mouseClick")) {
        Object arg0 = args[0];
        if (arg0 instanceof GuiScreenEvent) {
            GuiScreenEvent drawEvent = (GuiScreenEvent) arg0;

            if (drawEvent.getGui() instanceof GuiMainMenu) {
                // Don't invoke.
                return methodProxy.getSignature().getReturnType().getOpcode(VOID);
            }
        }
    }
    return methodProxy.invokeSuper(obj, args);
}
 
开发者ID:darkevilmac,项目名称:CreeperKiller,代码行数:20,代码来源:HammerKiller.java

示例2: intercept

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
    // Give our delegate a chance to intercept, and cache the decision
    if(delegatedMethods.get(method, () -> method.getDeclaringClass() != Object.class &&
                                          Methods.hasOverrideIn(Delegate.class, method))) {
        return method.invoke(delegate, args);
    }

    // If we have a value for the property, return that
    final Object value = values.get(method);
    if(value != null) return value;

    // If there's no value, then the method MUST be callable (or the code is broken).
    // This can only fail for an abstract non-property method (which we should probably be checking for).
    if(method.isDefault()) {
        // invokeSuper doesn't understand default methods
        return defaultMethodHandles.get(method)
                                   .bindTo(obj)
                                   .invokeWithArguments(args);
    } else {
        return proxy.invokeSuper(obj, args);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:24,代码来源:ReflectiveParserManifest.java

示例3: intercept

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
    if(isDecorated(method)) {
        // Decorated method
        return proxy.invokeSuper(obj, args);
    } else {
        final T t = ((Decorator<T>) obj).delegate();
        if(method.getDeclaringClass().isInstance(t)) {
            // Forwarded method
            return proxy.invoke(t, args);
        } else {
            // Forwarded method shadowed by an interface method in the decorator.
            //
            // This can happen if the decorator implements an interface that the
            // base class doesn't, and that interface contains a method that shadows
            // one on the base class. Java would allow the method to be called on the
            // base anyway, but MethodProxy refuses to invoke it on something that
            // is not assignable to the method's declaring type. So, unfortunately,
            // we have to fall back to the JDK to handle this case.
            return methodHandles.get(method, () ->
                resolver.virtualHandle(t.getClass(), method).bindTo(t)
            ).invokeWithArguments(args);
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:26,代码来源:LibCGDecoratorGenerator.java

示例4: intercept

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
/**
 * 实现MethodInterceptor接口要重写的方法。
 * 回调方法
 */
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
    Class[] paramTypes = method.getParameterTypes();

    // 找到realObject对象中,一模一样的方法
    Method method2 = ReflectUtils.findMethod(shadowObject.getClass(), method.getName(), paramTypes);

    if (method2 == null) {
        throw new RuntimeException("method \'" + shadowObject.getClass() + "." + method.getName() + "\' not found.");
    }

    try {
        return method2.invoke(shadowObject, args);
    } catch (InvocationTargetException e) {
        Throwable targetEx = e.getTargetException();

        throw targetEx;
    }
}
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:23,代码来源:CGLibProxy.java

示例5: invoke

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
private Object invoke(MethodProxy proxy, Object[] arguments, Class<?> declaredReturnType) throws Throwable {
  requests.increment();
  //noinspection unused
  try (TimerContext timer = TimerContext.timerMillis(totalRequestTime::add)) {
    UUID requestID = UUID.randomUUID();
    ServiceRequestMessage msg = ServiceRequestMessage.builder()
            .setRequestID(requestID.toString())
            .setServiceName(proxyInterface.getName())
            .setMethodName(proxy.getSignature().getName())
            .setArgumentTypes(fromTypes(proxy.getSignature().getArgumentTypes()))
            .setArguments(arguments)
            .build();

    if (LOGGER.isDebug()) LOGGER.debug("Signalling request");
    RequestHandler handler = RequestHandler.signal(requestSink, msg, true, maxWait);
    return handleResponses(handler, declaredReturnType);
  }
}
 
开发者ID:mnemonic-no,项目名称:common-services,代码行数:19,代码来源:ServiceMessageClient.java

示例6: intercept

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
public Object intercept(
	final Object obj, 
	final Method method, 
	final Object[] args, 
	final MethodProxy proxy) 
throws Throwable {
	if (constructed) {
		Object result = invoke(method, args, obj);
		if (result==INVOKE_IMPLEMENTATION) {
			return proxy.invoke( getImplementation(), args );
		}
		else {
			return result;
		}
	}
	else {
		//while constructor is running
		return proxy.invokeSuper(obj, args);
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:21,代码来源:CGLIBLazyInitializer.java

示例7: intercept

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
/**
 * 拦截所有调用,选择正确的实例执行命令
 * @param o 调用实例
 * @param method 调用方法
 * @param args 方法参数
 * @param methodProxy 方法代理
 * @return 命令返回值
 * @throws Throwable 方法执行异常或连接异常
 */
@Override
public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
    GedisInstanceType type;
    if (READ_METHOD_LIST.contains(method.getName())) {
        type = GedisInstanceType.READ;
    } else {
        type = GedisInstanceType.WRITE;
    }
    JedisPool pool = getJedisPoolByType(type);
    Jedis jedis = pool.getResource();
    try {
        return method.invoke(jedis, args);
    } catch (Exception e) {
        jedis.close();
        throw e;
    } finally {
        jedis.close();
    }
}
 
开发者ID:ganpengyu,项目名称:gedis,代码行数:29,代码来源:JedisMethodInterceptor.java

示例8: intercept

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
public Object intercept(final Object obj, final Method method,
                        final Object[] args, final MethodProxy proxy)
        throws Throwable {

    if (shouldSkip(method)) {
        return null;
    }
    Object result;
    if (baseClassMethod(method, obj.getClass())) {
        result = runBaseObjectMethod(obj, method, args, proxy);
    } else if (isParameterConverter(method)) {
        result = runBaseObjectMethod(obj, method, args, proxy);
    } else {
        result = testStepResult(obj, method, args, proxy);
    }
    return result;

}
 
开发者ID:tapack,项目名称:satisfy,代码行数:19,代码来源:SatisfyStepInterceptor.java

示例9: testStepResult

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
private Object testStepResult(final Object obj, final Method method,
                              final Object[] args, final MethodProxy
                                      proxy) throws Throwable {

    if (!isATestStep(method)) {
        return runNormalMethod(obj, method, args, proxy);
    }

    if (shouldSkip(method)) {
        notifySkippedStepStarted(method, args);
        return skipTestStep(obj, method, args, proxy);
    } else {
        notifyStepStarted(method, args);
        return runTestStep(obj, method, args, proxy);
    }

}
 
开发者ID:tapack,项目名称:satisfy,代码行数:18,代码来源:SatisfyStepInterceptor.java

示例10: runTestStep

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
private Object runTestStep(final Object obj, final Method method,
                           final Object[] args, final MethodProxy proxy)
        throws Throwable {
    LOGGER.debug("STARTING STEP: {}", method.getName());
    Object result = null;
    try {
        result = executeTestStepMethod(obj, method, args, proxy, result);
        LOGGER.debug("STEP DONE: {}", method.getName());
    } catch (AssertionError failedAssertion) {
        error = failedAssertion;
        logStepFailure(method, args, failedAssertion);
        return appropriateReturnObject(obj, method);
    } catch (AssumptionViolatedException assumptionFailed) {
        return appropriateReturnObject(obj, method);
    } catch (Throwable testErrorException) {
        error = testErrorException;
        logStepFailure(method, args, forError(error).convertToAssertion());
        return appropriateReturnObject(obj, method);
    }

    return result;
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:23,代码来源:SatisfyStepInterceptor.java

示例11: executeTestStepMethod

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
private Object executeTestStepMethod(Object obj, Method method, Object[]
        args, MethodProxy proxy, Object result) throws Throwable {
    try {
        result = invokeMethod(obj, args, proxy);
        notifyStepFinishedFor(method, args);
    } catch (PendingStepException pendingStep) {
        notifyStepPending(pendingStep.getMessage());
    } catch (IgnoredStepException ignoredStep) {
        notifyStepIgnored(ignoredStep.getMessage());
    } catch (AssumptionViolatedException assumptionViolated) {
        notifyAssumptionViolated(assumptionViolated.getMessage());
    }

    Preconditions.checkArgument(true);
    return result;
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:17,代码来源:SatisfyStepInterceptor.java

示例12: intercept

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
@Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        // 排除Object类中的toString等方法
        boolean objFlag = method.getDeclaringClass().getName().equals("java.lang.Object");
        if (!objFlag) {
            System.out.println("before");
        }
        Object result = null;
//      我们一般使用proxy.invokeSuper(obj,args)方法。这个很好理解,就是执行原始类的方法。还有一个方法proxy.invoke(obj,args),这是执行生成子类的方法。
//      如果传入的obj就是子类的话,会发生内存溢出,因为子类的方法不挺地进入intercept方法,而这个方法又去调用子类的方法,两个方法直接循环调用了。
        result = methodProxy.invokeSuper(obj, args);
//      result = methodProxy.invoke(obj, args);
        if (!objFlag) {
            System.out.println("after");
        }
        return result;
    }
 
开发者ID:MinsxCloud,项目名称:minsx-java-example,代码行数:18,代码来源:AccountCglibProxyFactory.java

示例13: main

import net.sf.cglib.proxy.MethodProxy; //导入依赖的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();
	}
}
 
开发者ID:hdcuican,项目名称:java_learn,代码行数:18,代码来源:ClassPermGenOOM.java

示例14: main

import net.sf.cglib.proxy.MethodProxy; //导入依赖的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());
}
 
开发者ID:zjulzq,项目名称:hotspot-gc-scenarios,代码行数:17,代码来源:Scenario4.java

示例15: intercept

import net.sf.cglib.proxy.MethodProxy; //导入依赖的package包/类
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
    boolean shouldProxy = method.isAnnotationPresent(Transactional.class);

    if (shouldProxy) {
        Connection conn = dataSource.getConnection();
        conn.setAutoCommit(false);
        Object result;
        try {
            result = methodProxy.invokeSuper(obj, args);
            conn.commit();
            return result;
        } catch (Exception e) {
            conn.rollback();
            throw e;
        }
    }

    return methodProxy.invokeSuper(obj, args);
}
 
开发者ID:ShotaOd,项目名称:carbon,代码行数:21,代码来源:TransactionInterceptor.java


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