use of org.apache.dubbo.rpc.model.ServiceRepository in project dubbo by alibaba.
the class SimpleRegistryExporter method registerProvider.
private void registerProvider(URL url, RegistryService registryService) {
ServiceRepository repository = ApplicationModel.getServiceRepository();
ServiceDescriptor serviceDescriptor = repository.registerService(RegistryService.class);
repository.registerProvider(url.getServiceKey(), registryService, serviceDescriptor, null, null);
}
use of org.apache.dubbo.rpc.model.ServiceRepository in project dubbo by alibaba.
the class GrpcProtocol method doExport.
@Override
protected <T> Runnable doExport(T proxiedImpl, Class<T> type, URL url) throws RpcException {
String key = url.getAddress();
ProtocolServer protocolServer = serverMap.computeIfAbsent(key, k -> {
DubboHandlerRegistry registry = new DubboHandlerRegistry();
NettyServerBuilder builder = NettyServerBuilder.forPort(url.getPort()).fallbackHandlerRegistry(registry);
Server originalServer = GrpcOptionsUtils.buildServerBuilder(url, builder).build();
GrpcRemotingServer remotingServer = new GrpcRemotingServer(originalServer, registry);
return new ProxyProtocolServer(remotingServer);
});
GrpcRemotingServer grpcServer = (GrpcRemotingServer) protocolServer.getRemotingServer();
ServiceRepository serviceRepository = ApplicationModel.getServiceRepository();
ProviderModel providerModel = serviceRepository.lookupExportedService(url.getServiceKey());
if (providerModel == null) {
throw new IllegalStateException("Service " + url.getServiceKey() + "should have already been stored in service repository, " + "but failed to find it.");
}
Object originalImpl = providerModel.getServiceInstance();
Class<?> implClass = originalImpl.getClass();
try {
Method method = implClass.getMethod("setProxiedImpl", type);
method.invoke(originalImpl, proxiedImpl);
} catch (Exception e) {
throw new IllegalStateException("Failed to set dubbo proxied service impl to stub, please make sure your stub " + "was generated by the dubbo-protoc-compiler.", e);
}
grpcServer.getRegistry().addService((BindableService) originalImpl, url.getServiceKey());
if (!grpcServer.isStarted()) {
grpcServer.start();
}
return () -> grpcServer.getRegistry().removeService(url.getServiceKey());
}
use of org.apache.dubbo.rpc.model.ServiceRepository in project dubbo by alibaba.
the class ReferenceConfig method checkAndUpdateSubConfigs.
/**
* This method should be called right after the creation of this class's instance, before any property in other config modules is used.
* Check each config modules are created properly and override their properties if necessary.
*/
public void checkAndUpdateSubConfigs() {
if (StringUtils.isEmpty(interfaceName)) {
throw new IllegalStateException("<dubbo:reference interface=\"\" /> interface not allow null!");
}
completeCompoundConfigs(consumer);
// get consumer's global configuration
checkDefault();
// init some null configuration.
List<ConfigInitializer> configInitializers = ExtensionLoader.getExtensionLoader(ConfigInitializer.class).getActivateExtension(URL.valueOf("configInitializer://"), (String[]) null);
configInitializers.forEach(e -> e.initReferConfig(this));
this.refresh();
if (getGeneric() == null && getConsumer() != null) {
setGeneric(getConsumer().getGeneric());
}
if (ProtocolUtils.isGeneric(generic)) {
interfaceClass = GenericService.class;
} else {
try {
interfaceClass = Class.forName(interfaceName, true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e.getMessage(), e);
}
checkInterfaceAndMethods(interfaceClass, getMethods());
}
initServiceMetadata(consumer);
serviceMetadata.setServiceType(getActualInterface());
// TODO, uncomment this line once service key is unified
serviceMetadata.setServiceKey(URL.buildKey(interfaceName, group, version));
ServiceRepository repository = ApplicationModel.getServiceRepository();
ServiceDescriptor serviceDescriptor = repository.registerService(interfaceClass);
repository.registerConsumer(serviceMetadata.getServiceKey(), serviceDescriptor, this, null, serviceMetadata);
resolveFile();
ConfigValidationUtils.validateReferenceConfig(this);
postProcessConfig();
}
use of org.apache.dubbo.rpc.model.ServiceRepository in project dubbo by alibaba.
the class RpcInvocation method initParameterDesc.
private void initParameterDesc() {
ServiceRepository repository = ApplicationModel.getServiceRepository();
if (StringUtils.isNotEmpty(serviceName)) {
ServiceDescriptor serviceDescriptor = repository.lookupService(serviceName);
if (serviceDescriptor != null) {
MethodDescriptor methodDescriptor = serviceDescriptor.getMethod(methodName, parameterTypes);
if (methodDescriptor != null) {
this.parameterTypesDesc = methodDescriptor.getParamDesc();
this.compatibleParamSignatures = methodDescriptor.getCompatibleParamSignatures();
this.returnTypes = methodDescriptor.getReturnTypes();
this.returnType = methodDescriptor.getReturnClass();
}
}
}
if (parameterTypesDesc == null) {
this.parameterTypesDesc = ReflectUtils.getDesc(this.getParameterTypes());
this.compatibleParamSignatures = Stream.of(this.parameterTypes).map(Class::getName).toArray(String[]::new);
this.returnTypes = RpcUtils.getReturnTypes(this);
this.returnType = RpcUtils.getReturnType(this);
}
}
use of org.apache.dubbo.rpc.model.ServiceRepository in project dubbo by alibaba.
the class ServiceConfig method doExportUrls.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void doExportUrls() {
ServiceRepository repository = ApplicationModel.getServiceRepository();
ServiceDescriptor serviceDescriptor = repository.registerService(getInterfaceClass());
repository.registerProvider(getUniqueServiceName(), ref, serviceDescriptor, this, serviceMetadata);
List<URL> registryURLs = ConfigValidationUtils.loadRegistries(this, true);
int protocolConfigNum = protocols.size();
for (ProtocolConfig protocolConfig : protocols) {
String pathKey = URL.buildKey(getContextPath(protocolConfig).map(p -> p + "/" + path).orElse(path), group, version);
// In case user specified path, register service one more time to map it to path.
repository.registerService(pathKey, interfaceClass);
doExportUrlsFor1Protocol(protocolConfig, registryURLs, protocolConfigNum);
}
}
Aggregations