本文整理了Java中java.lang.reflect.InvocationHandler.invoke()
方法的一些代码示例,展示了InvocationHandler.invoke()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InvocationHandler.invoke()
方法的具体详情如下:
包路径:java.lang.reflect.InvocationHandler
类名称:InvocationHandler
方法名:invoke
[英]Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.
[中]在代理实例上处理方法调用并返回结果。当在与其关联的代理实例上调用方法时,将在调用处理程序上调用此方法。
代码示例来源:origin: javamelody/javamelody
/** {@inheritDoc} */
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
return delegate.invoke(proxy, method, args);
} catch (final InvocationTargetException e) {
if (e.getTargetException() != null) {
throw e.getTargetException();
}
throw e;
}
}
}
代码示例来源:origin: rapidoid/rapidoid
public static <T> T implement(final Object target, final InvocationHandler handler, Class<?>... interfaces) {
final Class<?> targetClass = target.getClass();
return createProxy((proxy, method, args) -> {
if (method.getDeclaringClass().isAssignableFrom(targetClass)) {
return method.invoke(target, args);
}
return handler.invoke(proxy, method, args);
}, interfaces);
}
代码示例来源:origin: org.easymock/easymock
public Object invoke(Object obj, Method method, Object[] args) throws Throwable {
if (method.isBridge()) {
method = BridgeMethodResolver.findBridgedMethod(method);
}
// Never intercept EasyMock's own calls to fillInStackTrace
boolean internalFillInStackTraceCall = obj instanceof Throwable
&& method.getName().equals("fillInStackTrace")
&& ClassProxyFactory.isCallerMockInvocationHandlerInvoke(new Throwable());
if (internalFillInStackTraceCall
|| isMocked(method) && !Modifier.isAbstract(method.getModifiers())) {
return ProxyBuilder.callSuper(obj, method, args);
}
return delegate.invoke(obj, method, args);
}
代码示例来源:origin: jdbi/jdbi
private static Object invoke(Object target, Method method, Object[] args) {
if (Proxy.isProxyClass(target.getClass())) {
InvocationHandler handler = Proxy.getInvocationHandler(target);
return Unchecked.<Object[], Object>function((params) -> handler.invoke(target, method, params)).apply(args);
} else {
MethodHandle handle = Unchecked.function(MethodHandles.lookup()::unreflect).apply(method).bindTo(target);
return Unchecked.<Object[], Object>function(handle::invokeWithArguments).apply(args);
}
}
}
代码示例来源:origin: org.easymock/easymock
return handler.invoke(obj, method, args);
return handler.invoke(obj, method, args);
代码示例来源:origin: yu199195/myth
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
if (Object.class.equals(method.getDeclaringClass())) {
return method.invoke(this, args);
} else {
final Myth myth = method.getAnnotation(Myth.class);
if (Objects.isNull(myth)) {
return this.delegate.invoke(proxy, method, args);
}
try {
final MythTransactionEngine mythTransactionEngine =
SpringBeanUtils.getInstance().getBean(MythTransactionEngine.class);
final MythParticipant participant = buildParticipant(myth, method, args);
if (Objects.nonNull(participant)) {
mythTransactionEngine.registerParticipant(participant);
}
return this.delegate.invoke(proxy, method, args);
} catch (Throwable throwable) {
throwable.printStackTrace();
return DefaultValueUtils.getDefaultValue(method.getReturnType());
}
}
}
代码示例来源:origin: OpenHFT/Chronicle-Queue
@Override
public void onMessage(final Message message) {
a1[0] = message;
try {
handler.invoke(proxy, m1, a1);
} catch (Throwable throwable) {
Jvm.rethrow(throwable);
}
}
}
代码示例来源:origin: liuyangming/ByteTCC
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (Object.class.equals(method.getDeclaringClass())) {
return this.delegate.invoke(proxy, method, args);
} else {
final SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
CompensableManager compensableManager = beanFactory.getCompensableManager();
CompensableTransactionImpl compensable = //
(CompensableTransactionImpl) compensableManager.getCompensableTransactionQuietly();
if (compensable == null) {
return this.delegate.invoke(proxy, method, args);
}
final TransactionContext transactionContext = compensable.getTransactionContext();
if (transactionContext.isCompensable() == false) {
return this.delegate.invoke(proxy, method, args);
}
Method targetMethod = CompensableHystrixInvocationHandler.class.getDeclaredMethod(
CompensableHystrixBeanPostProcessor.HYSTRIX_INVOKER_NAME,
new Class<?>[] { CompensableHystrixInvocation.class });
CompensableHystrixInvocation invocation = new CompensableHystrixInvocation();
invocation.setThread(Thread.currentThread());
invocation.setMethod(method);
invocation.setArgs(args);
Object[] targetArgs = new Object[] { invocation };
return this.delegate.invoke(proxy, targetMethod, targetArgs);
}
}
代码示例来源:origin: jersey/jersey
try {
Object result = methodHandler.invoke(resource, method, args);
代码示例来源:origin: jersey/jersey
try {
Object result = methodHandler.invoke(resource, method, args);
代码示例来源:origin: patric-r/jvmtop
.invoke(
getOperatingSystemMXBean(),
Class.forName(osMXBeanClassName).getMethod("getProcessCpuTime"),
代码示例来源:origin: yu199195/hmily
final Hmily hmily = method.getAnnotation(Hmily.class);
if (Objects.isNull(hmily)) {
return this.delegate.invoke(proxy, method, args);
final Object invoke = delegate.invoke(proxy, method, args);
final HmilyParticipant hmilyParticipant = buildParticipant(hmily, method, args, hmilyTransactionContext);
if (hmilyTransactionContext.getRole() == HmilyRoleEnum.INLINE.getCode()) {
代码示例来源:origin: Dreampie/Resty
result = ih.invoke(proxy, method, args);
for (DataSourceMeta dsm : dataSourceMetas) {
dsm.commitTransaction();
result = ih.invoke(proxy, method, args);
代码示例来源:origin: liuyangming/ByteTCC
(CompensableTransactionImpl) compensableManager.getCompensableTransactionQuietly();
if (compensable == null) {
return this.delegate.invoke(proxy, method, args);
return this.delegate.invoke(proxy, method, args);
return this.delegate.invoke(proxy, method, args);
} finally {
Object interceptedValue = response.getHeader(TransactionInterceptor.class.getName());
代码示例来源:origin: com.jayway.awaitility/awaitility
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
return invocationHandler.invoke(obj, method, args);
}
};
代码示例来源:origin: mulesoft/mule
/**
* Performs the actual invocation on the proxied {@link Object}, or delegates the call to an inner proxy.
*
* See {@link InvocationHandler#invoke(Object, Method, Object[])}
*/
protected Object doInvoke(Object proxy, Method method, Object[] args) throws Throwable {
if (isNestedProxy()) {
return getInvocationHandler(getProxiedObject()).invoke(getProxiedObject(), method, args);
} else {
try {
return method.invoke(getProxiedObject(), args);
} catch (InvocationTargetException ite) {
// Unwrap target exception to ensure InvocationTargetException (in case of unchecked exceptions) or
// UndeclaredThrowableException (in case of checked exceptions) is not thrown by inner object instead of target exception.
throw ite.getTargetException();
}
}
}
代码示例来源:origin: net.java.dev.jna/jna
return f.handler.invoke(proxy, method, inArgs);
代码示例来源:origin: org.glassfish.jersey.core/jersey-server
try {
Object result = methodHandler.invoke(resource, method, args);
代码示例来源:origin: pac4j/play-pac4j
protected String getStringParam(final InvocationHandler invocationHandler, final Method method, final String defaultValue) throws Throwable {
String value = (String) invocationHandler.invoke(configuration, method, null);
if (value == null) {
value = defaultValue;
}
logger.debug("String param: {}: {}", method.getName(), value);
return value;
}
代码示例来源:origin: org.powermock/powermock-core
/**
* {@link #noMockito} is wrapped into it's own static class to make sure it is initialized not earlier than
* {@link #calledFromMockito()} is called for the first time.
*/
private static final class NoMockito {
static final boolean noMockito = Package.getPackage("org.mockito") == null;
private NoMockito() {}
}
public static final Object PROCEED = new Object();
内容来源于网络,如有侵权,请联系作者删除!