當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。