LocalReactiveServiceCallerImpl implements LocalReactiveServiceCaller, ReactiveServiceDiscovery { public ReactiveServiceInterface createReactiveServiceInterface(String group, String version, String serviceFullName, Class<?> javaInterface) { ReactiveServiceInterface serviceInterface = new ReactiveServiceInterface(); serviceInterface.setGroup(group); serviceInterface.setVersion(version); serviceInterface.setNamespace(javaInterface.getPackage().getName()); serviceInterface.setName(javaInterface.getSimpleName()); Deprecated interfaceDeprecated = javaInterface.getAnnotation(Deprecated.class); if (interfaceDeprecated != null) { serviceInterface.setDeprecated(true); } for (Method method : javaInterface.getMethods()) { if (!method.isDefault()) { String handlerName = method.getName(); ReactiveOperation operation = new ReactiveOperation(); Deprecated methodDeprecated = method.getAnnotation(Deprecated.class); if (methodDeprecated != null) { operation.setDeprecated(true); } serviceInterface.addOperation(operation); operation.setName(handlerName); operation.setReturnType(method.getReturnType().getCanonicalName()); operation.setReturnInferredType(ReactiveMethodSupport.parseInferredClass(method.getGenericReturnType()).getCanonicalName()); for (Parameter parameter : method.getParameters()) { OperationParameter param = new OperationParameter(); operation.addParameter(param); param.setName(parameter.getName()); param.setType(parameter.getType().getCanonicalName()); String inferredType = ReactiveMethodSupport.parseInferredClass(parameter.getParameterizedType()).getCanonicalName(); if (!param.getType().equals(inferredType)) { param.setInferredType(inferredType); } } } } return serviceInterface; } LocalReactiveServiceCallerImpl(); @Override boolean contains(String serviceName, String rpc); @Override boolean contains(Integer serviceId); @Override boolean contains(String serviceName); @Override Set<String> findAllServices(); void addProvider(@NotNull String group, String serviceName, @NotNull String version, Class<?> serviceInterface, Object handler); @Override @Nullable ReactiveMethodHandler getInvokeMethod(String serviceName, String method); @Override @Nullable ReactiveMethodHandler getInvokeMethod(Integer handlerId); @Override boolean containsHandler(Integer handlerId); ReactiveServiceInterface createReactiveServiceInterface(String group, String version,
                                                                   String serviceFullName, Class<?> javaInterface); @Override ReactiveServiceInterface findServiceByFullName(String serviceFullName);  }
@Test public void testAddServiceInterface() { ReactiveServiceInterface serviceInterface = serviceCaller.createReactiveServiceInterface("group1", "1.0.0", "com.alibaba.rsocket.rpc.DemoReactiveService", DemoReactiveService.class); System.out.println("=======Reactive Service Interface====="); System.out.println(serviceInterface.getNamespace()); System.out.println(serviceInterface.getName()); System.out.println("===============Operations====================="); List<ReactiveOperation> operations = serviceInterface.getOperations(); for (ReactiveOperation operation : operations) { System.out.println(operation.getName()); System.out.println(operation.getReturnType()); System.out.println(operation.getReturnInferredType()); System.out.println("deprecated: " + operation.isDeprecated()); if (!operation.getParameters().isEmpty()) { System.out.println("===============Parameters====================="); } for (OperationParameter parameter : operation.getParameters()) { System.out.println(parameter.getName()); System.out.println(parameter.getType()); System.out.println(parameter.getInferredType()); } System.out.println("================================"); } }