Returns a {@link ClientBootstrap} instance for the named transport.
4834
@Override
    public synchronized ClientBootstrap newClientBootstrap() throws Exception {

        ClientSocketChannelFactory clientChannelFactory = this.clientChannelFactory;

        if (clientChannelFactory == null) {
            Executor bossExecutor = executorServiceFactory.newExecutorService("boss.client");
            NioClientBossPool bossPool = new NioClientBossPool(bossExecutor, 1);
            Executor workerExecutor = executorServiceFactory.newExecutorService("worker.client");
            NioWorkerPool workerPool = new NioWorkerPool(workerExecutor, 1);
            clientChannelFactory = new NioClientSocketChannelFactory(bossPool, workerPool);

            // unshared
            channelFactories.add(clientChannelFactory);
        }

        return new ClientBootstrap(clientChannelFactory) {
            @Override
            public ChannelFuture connect(final SocketAddress localAddress, final SocketAddress remoteAddress) {
                final InetSocketAddress localChannelAddress = toInetSocketAddress((ChannelAddress) localAddress);
                final InetSocketAddress remoteChannelAddress = toInetSocketAddress((ChannelAddress) remoteAddress);
                return super.connect(localChannelAddress, remoteChannelAddress);
            }
        };
    }
629264
@Override
	public AsyncService getAsyncService(TNonblockingTransport transport, String serviceName) throws IkasoaException {
		if (transport == null)
			throw new IllegalArgumentException("'transport' is null !");
		try {
			return StringUtil.isEmpty(serviceName)
					? new AsyncServiceClientImpl((TProtocolFactory) new TCompactProtocol.Factory(), transport)
					: new AsyncServiceClientImpl(new AsyncMultiplexedProtocolFactory(serviceName), transport);
		} catch (IOException e) {
			throw new IkasoaException(e);
		}
	}
238940
public TransportServer createServer(
      String host, int port, List<TransportServerBootstrap> bootstraps) {
    return new TransportServer(this, host, port, rpcHandler, bootstraps);
  }
587877
public ServiceDiscovery<T> build()
    {
        if ( serializer == null )
        {
            serializer(new JsonInstanceSerializer<T>(payloadClass));
        }
        if ( serviceDefinitionSerializer == null)
        {
            serializer(new FastjsonServiceDefinitionSerializer<>(payloadClass));
        }
        return new ServiceDiscoveryImpl<T>(client, basePath, serializer, serviceDefinitionSerializer, thisInstance, watchInstances);
    }
1034191
@Nullable
	public static SslProvider findSslSupport(ServerBootstrap b) {
		SslSupportConsumer ssl = BootstrapHandlers.findConfiguration(SslSupportConsumer.class, b.config().childHandler());

		if (ssl == null) {
			return null;
		}
		return ssl.sslProvider;
	}
1268688
public SinglePortRouterConfiguration build() {
        if (this.enabled) {
            try {
                validate();
            } catch (Exception e) {
                throw logger.configurationValidationError(e);
            }
            SslConfigurationBuilder sslConfigurationBuilder = new SslConfigurationBuilder(null);
            if (sslContext != null) {
                sslConfigurationBuilder.sslContext(sslContext);
            }
            else if (keystorePath != null) {
                sslConfigurationBuilder.keyStoreFileName(keystorePath).keyStorePassword(keystorePassword).enable();
            }
            AttributeSet attributes = ProtocolServerConfiguration.attributeDefinitionSet();
            attributes.attribute(ProtocolServerConfiguration.NAME).set(name);
            attributes.attribute(ProtocolServerConfiguration.HOST).set(ip.getHostName());
            attributes.attribute(ProtocolServerConfiguration.PORT).set(port);
            attributes.attribute(ProtocolServerConfiguration.IDLE_TIMEOUT).set(100);
            attributes.attribute(ProtocolServerConfiguration.RECV_BUF_SIZE).set(receiveBufferSize);
            attributes.attribute(ProtocolServerConfiguration.SEND_BUF_SIZE).set(sendBufferSize);
            return new SinglePortRouterConfiguration(attributes.protect(), sslConfigurationBuilder.create());
        }
        return null;
    }
580075
private ServerBootstrap getServerBootstrap(final boolean useSSL) {

        final CommandInvoker invoker = new CommandInvoker(pluginRepository, commandRepository, acceptParams, getExecutionContext());

        final ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(final SocketChannel ch) throws Exception {

                if (useSSL) {
                    final SSLEngine engine = getSSLEngine();
                    engine.setEnabledCipherSuites(engine.getSupportedCipherSuites());
                    engine.setUseClientMode(false);
                    engine.setNeedClientAuth(false);
                    ch.pipeline().addLast("ssl", new SslHandler(engine));
                }

                ch.pipeline()
                        .addLast(new JNRPERequestDecoder(), new JNRPEResponseEncoder(), new JNRPEServerHandler(invoker, context))
                        .addLast("idleStateHandler", new IdleStateHandler(readTimeout, writeTimeout, 0))
                        .addLast(
                                "jnrpeIdleStateHandler",
                                new JNRPEIdleStateHandler(context));
            }
        }).option(ChannelOption.SO_BACKLOG, maxAcceptedConnections).childOption(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);

        return serverBootstrap;
    }
729317
public static Bootstrap setBootstrap(Bootstrap b, SslProvider sslProvider) {
		BootstrapHandlers.updateConfiguration(b,
				NettyPipeline.SslHandler,
				new DeferredSslSupport(sslProvider));

		return b;
	}
844926
public static Cluster getCluster(ConsumerBootstrap consumerBootstrap) {
        try {
            ConsumerConfig consumerConfig = consumerBootstrap.getConsumerConfig();
            ExtensionClass<Cluster> ext = ExtensionLoaderFactory.getExtensionLoader(Cluster.class)
                .getExtensionClass(consumerConfig.getCluster());
            if (ext == null) {
                throw ExceptionUtils.buildRuntime("consumer.cluster",
                    consumerConfig.getCluster(), "Unsupported cluster of client!");
            }
            return ext.getExtInstance(new Class[] { ConsumerBootstrap.class },
                new Object[] { consumerBootstrap });
        } catch (SofaRpcRuntimeException e) {
            throw e;
        } catch (Throwable e) {
            throw new SofaRpcRuntimeException(e.getMessage(), e);
        }
    }
339016
public final HttpClient protocol(HttpProtocol... supportedProtocols) {
		return tcpConfiguration(tcpClient -> tcpClient.bootstrap(b -> HttpClientConfiguration.protocols(b, supportedProtocols)));
	}
426394
public static ChannelBindException fail(AbstractBootstrap<?, ?> bootstrap, @Nullable Throwable cause) {
		Objects.requireNonNull(bootstrap, "bootstrap");
		if (cause instanceof java.net.BindException ||
				// With epoll/kqueue transport it is
				// io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
				(cause instanceof IOException && cause.getMessage() != null &&
						cause.getMessage().contains("Address already in use"))) {
			cause = null;
		}
		if (!(bootstrap.config().localAddress() instanceof InetSocketAddress)) {
			return new ChannelBindException(bootstrap.config().localAddress().toString(), -1, cause);
		}
		InetSocketAddress address = (InetSocketAddress)bootstrap.config().localAddress();

		return new ChannelBindException(address.getHostString(), address.getPort(), cause);
	}
636984
@Override
	public TTransport getTransport() throws IkasoaException {
		updateServerInfo();
		ServerCheck serverCheck = getServerCheck();
		// 如果有配置检测实现,则在建立连接前尝试检测服务器,如果服务器不可用则尝试切换到另一台服务器,切换规则取决于负载均衡实现.
		// 需要注意,如果列表中的服务器全都不可用,则会无限循环下去,直到有可用的服务为止.
		if (serverCheck != null && !serverCheck.check(getServerHost(), getServerPort())) {
			serverCheckFailProcessor.process(this);
			return getTransport();
		}
		TTransport transport = super.getTransport(getServerHost(), getServerPort());
		loadBalance.next();
		return transport;
	}
774335
public static Client rsocket(ClientSettings clientSettings) {
    RSocketClientCodec clientCodec =
        new RSocketClientCodec(
            HeadersCodec.getInstance(clientSettings.contentType()),
            DataCodec.getInstance(clientSettings.contentType()));

    RSocketClientTransport clientTransport =
        new RSocketClientTransport(clientSettings, clientCodec, clientSettings.loopResources());

    return new Client(clientTransport, clientCodec, clientSettings.errorMapper());
  }
1330635
public static KeenClient client() {
        if (ClientSingleton.INSTANCE.client == null) {
            throw new IllegalStateException("Please call KeenClient.initialize() before requesting the client.");
        }
        return ClientSingleton.INSTANCE.client;
    }
705096
public T build() {
        C clientObject = client;
        if (clientObject == null) {
            clientObject = createClient();
        }

        return factory.create(clientObject);
    }
338757
private Client getClient() {
        Client client = hostMap.get(basePath);
        if (client!=null) return client;

        final ClientConfig clientConfig = new ClientConfig();
        clientConfig.register(MultiPartFeature.class);
        if (debug) {
            clientConfig.register(LoggingFilter.class);
        }
        client = ClientBuilder.newClient(clientConfig);

        hostMap.putIfAbsent(basePath, client);
        return hostMap.get(basePath); //be sure to use the same in case of a race condition.
    }
685883
private CompletableFuture<Void> requestBootstrapFromPeer(MemberId peer) {
    LOGGER.trace("Sending bootstrap request to {} for {}", peer, mapName);
    return clusterCommunicator.<MemberId, Void>send(
        bootstrapMessageSubject,
        localMemberId,
        serializer::encode,
        serializer::decode,
        peer)
        .whenComplete((updates, error) -> {
          if (error != null) {
            LOGGER.debug("Bootstrap request to {} failed: {}", peer, error.getMessage());
          }
        });
  }