use of org.apache.dubbo.rpc.service.GenericService in project dubbo by alibaba.
the class GenericServiceTest method testGenericReferenceException.
@SuppressWarnings("unchecked")
@Test
public void testGenericReferenceException() {
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setInterface(DemoService.class.getName());
service.setRef(new DemoServiceImpl());
ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
reference.setInterface(DemoService.class);
reference.setUrl("dubbo://127.0.0.1:29581?scope=remote&timeout=3000");
reference.setGeneric(true);
DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("generic-test")).registry(new RegistryConfig("N/A")).protocol(new ProtocolConfig("dubbo", 29581)).service(service).reference(reference);
bootstrap.start();
try {
GenericService genericService = ReferenceConfigCache.getCache().get(reference);
List<Map<String, Object>> users = new ArrayList<Map<String, Object>>();
Map<String, Object> user = new HashMap<String, Object>();
user.put("class", "org.apache.dubbo.config.api.User");
user.put("name", "actual.provider");
users.add(user);
users = (List<Map<String, Object>>) genericService.$invoke("getUsers", new String[] { List.class.getName() }, new Object[] { users });
Assertions.assertEquals(1, users.size());
Assertions.assertEquals("actual.provider", users.get(0).get("name"));
} finally {
bootstrap.stop();
}
}
use of org.apache.dubbo.rpc.service.GenericService in project incubator-dubbo-ops by apache.
the class GenericServiceImpl method invoke.
public Object invoke(String service, String method, String[] parameterTypes, Object[] params) {
ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
String group = Tool.getGroup(service);
String version = Tool.getVersion(service);
String intf = Tool.getInterface(service);
reference.setGeneric(true);
reference.setApplication(applicationConfig);
reference.setInterface(intf);
reference.setVersion(version);
reference.setGroup(group);
// Keep it consistent with the ConfigManager cache
reference.setSticky(false);
try {
removeGenericSymbol(parameterTypes);
GenericService genericService = reference.get();
return genericService.$invoke(method, parameterTypes, params);
} finally {
reference.destroy();
}
}
use of org.apache.dubbo.rpc.service.GenericService in project incubator-dubbo-ops by apache.
the class ApiDocsDubboGenericUtil method invoke.
/**
* Call duboo provider and return {@link CompletableFuture}
*
* @return java.util.concurrent.CompletableFuture<java.lang.Object>
* @param: address
* @param: interfaceName
* @param: methodName
* @param: async Whether the provider is asynchronous is to directly return the {@link CompletableFuture}
* returned by the provider, not to wrap it as {@link CompletableFuture}
* @param: paramTypes
* @param: paramValues
*/
public static CompletableFuture<Object> invoke(String address, String interfaceName, String methodName, boolean async, String version, String[] paramTypes, Object[] paramValues, String group) {
CompletableFuture future = null;
ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName, version, group);
if (null != reference) {
GenericService genericService = reference.get();
if (null != genericService) {
if (async) {
future = genericService.$invokeAsync(methodName, paramTypes, paramValues);
} else {
future = CompletableFuture.supplyAsync(() -> genericService.$invoke(methodName, paramTypes, paramValues), EXECUTOR);
}
future.exceptionally(ex -> {
if (StringUtils.contains(ex.toString(), "Failed to invoke remote method")) {
removeReferenceConfig(address, interfaceName, version, group);
}
return ex;
});
}
}
return future;
}
Aggregations