@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { T target = this.target; if (target == null) { throw new ServiceUnavailableException("Proxy not bound to a type=" + type.getName() + ". " + "Call AstrixRule.registerProvider to register a provider for the given bean"); } return ReflectionUtil.invokeMethod(method, target, args); } }
@Override public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable { try { return ReflectionUtil.invokeMethod(method, gigaSpace, args); } catch (SpaceCacheException e) { throw new ServiceUnavailableException("SpaceCacheNotAvailable", e); } }
@Override RoutingKey getRoutingKey(Object element) { try { Object result = ReflectionUtil.invokeMethod(method, element, null); return RoutingKey.create(result); } catch (Throwable e) { throw new RuntimeException("Failed to invoke routing Method on: " + element, e); } } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { Method targetMethod = targetProvider.getClass().getMethod(method.getName(), method.getParameterTypes()); Observable<Object> observableResult = Observable.create((s) -> { try { Object result = ReflectionUtil.invokeMethod(targetMethod, targetProvider, args); s.onNext(result); s.onCompleted(); } catch (Throwable e) { s.onError(e); } }); if (method.getReturnType().equals(Future.class)) { return observableResult.toBlocking().toFuture(); } if (method.getReturnType().equals(Observable.class)) { return observableResult; } return reactiveTypeConverter.toCustomReactiveType(method.getReturnType(), observableResult); } catch (NoSuchMethodException e) { throw new RuntimeException("Target service does not contain method: " + e.getMessage()); } } });
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object[] marshalledAndUnmarshalledArgs = new Object[args.length]; for (int i = 0; i < args.length; i++) { // simulate client serialization before sending request over network Object serialized = clientSerializer.serialize(args[i], clientVersion); // simulate server deserialization after receiving request from network Object deserialized = serverSerializer.deserialize(serialized, method.getParameterTypes()[i], clientVersion); if (args[i] != null && !args[i].getClass().equals(deserialized.getClass())) { throw new IllegalArgumentException("Deserialization of service arguments failed. clientSerializer=" + clientSerializer.getClass().getName() + " serverSerializer=" + serverSerializer.getClass().getName()); } marshalledAndUnmarshalledArgs[i] = deserialized; } Object result = ReflectionUtil.invokeMethod(method, provider, marshalledAndUnmarshalledArgs); // simulate server serialization before sending response over network Object serialized = serverSerializer.serialize(result, clientVersion); // simulate client deserialization after receiving response from server. Object deserialized = clientSerializer.deserialize(serialized, method.getReturnType(), clientVersion); return deserialized; }
private Object proxyInvocation(final Method method, final Object[] args) throws Throwable { CheckedCommand<Object> serviceInvocation = () -> ReflectionUtil.invokeMethod(method, targetBean, args); for (BeanProxy proxy : proxys) { if (proxy.isEnabled()) { serviceInvocation = proxy.proxyInvocation(serviceInvocation); } } return serviceInvocation.call(); }
@SuppressWarnings("unchecked") private Object proxyReactiveInvocation(final Method method, final Object[] args) { Supplier<Observable<Object>> serviceInvocation = () -> { try { Object reactiveResult = ReflectionUtil.invokeMethod(method, targetBean, args); if (isObservableType(method.getReturnType())) { return (Observable<Object>) reactiveResult; } return toObservable(method.getReturnType(), reactiveResult); } catch (Throwable e) { return Observable.error(e); } }; for (BeanProxy proxy : proxys) { if (proxy.isEnabled()) { serviceInvocation = proxy.proxyReactiveInvocation(serviceInvocation); } } if (isObservableType(method.getReturnType())) { return serviceInvocation.get(); // return Observable.create((s) -> { // serviceInvocation.get().subscribe(s); // }); } Observable<Object> asyncResult = serviceInvocation.get(); return this.reactiveTypeConverter.toCustomReactiveType(method.getReturnType(), asyncResult); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getDeclaringClass().equals(Object.class)) { return ReflectionUtil.invokeMethod(method, this, args);