Search in sources :

Example 1 with ServiceRepository

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);
}
Also used : ServiceDescriptor(org.apache.dubbo.rpc.model.ServiceDescriptor) ServiceRepository(org.apache.dubbo.rpc.model.ServiceRepository)

Example 2 with ServiceRepository

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());
}
Also used : NettyServerBuilder(io.grpc.netty.NettyServerBuilder) ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) Server(io.grpc.Server) Method(java.lang.reflect.Method) ServiceRepository(org.apache.dubbo.rpc.model.ServiceRepository) IOException(java.io.IOException) RpcException(org.apache.dubbo.rpc.RpcException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) ProviderModel(org.apache.dubbo.rpc.model.ProviderModel)

Example 3 with ServiceRepository

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();
}
Also used : ServiceDescriptor(org.apache.dubbo.rpc.model.ServiceDescriptor) ServiceRepository(org.apache.dubbo.rpc.model.ServiceRepository)

Example 4 with ServiceRepository

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);
    }
}
Also used : ServiceDescriptor(org.apache.dubbo.rpc.model.ServiceDescriptor) ServiceRepository(org.apache.dubbo.rpc.model.ServiceRepository) MethodDescriptor(org.apache.dubbo.rpc.model.MethodDescriptor)

Example 5 with ServiceRepository

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);
    }
}
Also used : ServiceDescriptor(org.apache.dubbo.rpc.model.ServiceDescriptor) ServiceRepository(org.apache.dubbo.rpc.model.ServiceRepository) URL(org.apache.dubbo.common.URL)

Aggregations

ServiceRepository (org.apache.dubbo.rpc.model.ServiceRepository)8 ServiceDescriptor (org.apache.dubbo.rpc.model.ServiceDescriptor)5 IOException (java.io.IOException)3 URL (org.apache.dubbo.common.URL)2 MethodDescriptor (org.apache.dubbo.rpc.model.MethodDescriptor)2 ProviderModel (org.apache.dubbo.rpc.model.ProviderModel)2 Server (io.grpc.Server)1 NettyServerBuilder (io.grpc.netty.NettyServerBuilder)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Cleanable (org.apache.dubbo.common.serialize.Cleanable)1 ObjectInput (org.apache.dubbo.common.serialize.ObjectInput)1 Invoker (org.apache.dubbo.rpc.Invoker)1 ProtocolServer (org.apache.dubbo.rpc.ProtocolServer)1 RpcException (org.apache.dubbo.rpc.RpcException)1 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1