import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
-import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.RpcService;
import org.opendaylight.yangtools.yang.common.RpcResult;
}
static RpcMethodInvoker from(final Method method) {
- BindingReflections.resolveRpcInputClass(method)
- .orElseThrow(() -> new IllegalArgumentException("Method " + method + " does not have an input argument"));
-
final MethodHandle methodHandle;
try {
methodHandle = MethodHandles.publicLookup().unreflect(method);
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Type;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.concurrent.TimeUnit;
&& possibleMethod.getParameterCount() <= 2;
}
- /**
- * Extracts Output class for RPC method.
- *
- * @param targetMethod method to scan
- * @return Optional.empty() if result type could not be get, or return type is Void.
- * @deprecated This method is unused and scheduled for removal
- */
- @Deprecated(since = "10.0.4", forRemoval = true)
- @SuppressWarnings("rawtypes")
- public static Optional<Class<?>> resolveRpcOutputClass(final Method targetMethod) {
- checkState(isRpcMethod(targetMethod), "Supplied method is not a RPC invocation method");
- Type futureType = targetMethod.getGenericReturnType();
- Type rpcResultType = ClassLoaderUtils.getFirstGenericParameter(futureType).orElse(null);
- Type rpcResultArgument = ClassLoaderUtils.getFirstGenericParameter(rpcResultType).orElse(null);
- if (rpcResultArgument instanceof Class cls && !Void.class.equals(rpcResultArgument)) {
- return Optional.of(cls);
- }
- return Optional.empty();
- }
-
- /**
- * Extracts input class for RPC method.
- *
- * @param targetMethod method to scan
- * @return Optional.empty() if RPC has no input, RPC input type otherwise.
- * @deprecated This method is unused and scheduled for removal
- */
- @Deprecated(since = "10.0.4", forRemoval = true)
- @SuppressWarnings("rawtypes")
- public static Optional<Class<? extends DataContainer>> resolveRpcInputClass(final Method targetMethod) {
- for (Class clazz : targetMethod.getParameterTypes()) {
- if (DataContainer.class.isAssignableFrom(clazz)) {
- return Optional.of(clazz);
- }
- }
- return Optional.empty();
- }
-
public static @NonNull QName getQName(final BaseIdentity identity) {
return getContractQName(identity);
}
assertTrue(BindingReflections.isRpcMethod(TestImplementation.class.getDeclaredMethod("rpcMethodTest")));
assertEquals(TestImplementation.class, BindingReflections.findAugmentationTarget(TestImplementation.class));
- assertEquals(Object.class, BindingReflections.resolveRpcOutputClass(
- TestImplementation.class.getDeclaredMethod("rpcMethodTest")).get());
- assertFalse(BindingReflections.resolveRpcOutputClass(
- TestImplementation.class.getDeclaredMethod("rpcMethodTest2")).isPresent());
-
assertEquals(QName.create("test", "test"), BindingReflections.getQName(TestIdentity.VALUE));
}
return null;
}
- @SuppressWarnings("static-method")
- ListenableFuture<?> rpcMethodTest2() {
- return null;
- }
-
@Override
public Class<TestImplementation> implementedInterface() {
return TestImplementation.class;