public XdsChannel()

in dubbo-xds/src/main/java/org/apache/dubbo/registry/xds/util/XdsChannel.java [69:116]


    public XdsChannel(URL url) {
        ManagedChannel managedChannel = null;
        this.url = url;
        try {
            if (!url.getParameter(USE_AGENT, false)) {
                if (PLAINTEXT.equals(url.getParameter(SECURE))) {
                    managedChannel = NettyChannelBuilder.forAddress(url.getHost(), url.getPort())
                            .usePlaintext()
                            .build();
                } else {
                    XdsCertificateSigner signer = url.getOrDefaultApplicationModel()
                            .getExtensionLoader(XdsCertificateSigner.class)
                            .getExtension(url.getParameter("signer", "istio"));
                    XdsCertificateSigner.CertPair certPair = signer.GenerateCert(url);
                    SslContext context = GrpcSslContexts.forClient()
                            .trustManager(InsecureTrustManagerFactory.INSTANCE)
                            .keyManager(
                                    new ByteArrayInputStream(
                                            certPair.getPublicKey().getBytes(StandardCharsets.UTF_8)),
                                    new ByteArrayInputStream(
                                            certPair.getPrivateKey().getBytes(StandardCharsets.UTF_8)))
                            .build();
                    managedChannel = NettyChannelBuilder.forAddress(url.getHost(), url.getPort())
                            .sslContext(context)
                            .build();
                }
            } else {
                BootstrapperImpl bootstrapper = new BootstrapperImpl();
                Bootstrapper.BootstrapInfo bootstrapInfo = bootstrapper.bootstrap();
                URLAddress address =
                        URLAddress.parse(bootstrapInfo.servers().get(0).target(), null, false);
                EpollEventLoopGroup elg = new EpollEventLoopGroup();
                managedChannel = NettyChannelBuilder.forAddress(new DomainSocketAddress("/" + address.getPath()))
                        .eventLoopGroup(elg)
                        .channelType(EpollDomainSocketChannel.class)
                        .usePlaintext()
                        .build();
            }
        } catch (Exception e) {
            logger.error(
                    REGISTRY_ERROR_CREATE_CHANNEL_XDS,
                    "",
                    "",
                    "Error occurred when creating gRPC channel to control panel.",
                    e);
        }
        channel = managedChannel;
    }