Huawei Api Client 连接回调
@param rst 结果码
@param client HuaweiApiClient 实例
351743
@Override
    public void onConnect(int rst, HuaweiApiClient client) {

        HMSAgentLog.d("onConnect:" + rst);

        if (client == null || !ApiClientMgr.INST.isConnect(client)) {
            HMSAgentLog.e("client not connted");
            onPMSPayEnd(rst, null);
            return;
        }

        // 调用HMS-SDK pay 接口
        PendingResult<PayResult> payResult = HuaweiPay.HuaweiPayApi.productPay(client, payReq);
        payResult.setResultCallback(new ResultCallback<PayResult>() {
            @Override
            public void onResult(PayResult result) {

                if (result == null) {
                    HMSAgentLog.e("result is null");
                    onPMSPayEnd(HMSAgent.AgentResultCode.RESULT_IS_NULL, null);
                    return;
                }

                Status status = result.getStatus();
                if (status == null) {
                    HMSAgentLog.e("status is null");
                    onPMSPayEnd(HMSAgent.AgentResultCode.STATUS_IS_NULL, null);
                    return;
                }

                int rstCode = status.getStatusCode();
                HMSAgentLog.d("status=" + status);
                // 需要重试的错误码，并且可以重试
                if ((rstCode == CommonCode.ErrorCode.SESSION_INVALID
                        || rstCode == CommonCode.ErrorCode.CLIENT_API_INVALID) && retryTimes > 0) {
                    retryTimes--;
                    connect();
                } else if (rstCode == PayStatusCodes.PAY_STATE_SUCCESS) {
                    // 支付校验完成，取当前activity进行后续支付操作
                    Activity curActivity = ActivityMgr.INST.getLastActivity();
                    if (curActivity == null) {
                        HMSAgentLog.e("activity is null");
                        onPMSPayEnd(HMSAgent.AgentResultCode.NO_ACTIVITY_FOR_USE, null);
                        return;
                    }

                    if (statusForPay != null) {
                        HMSAgentLog.e("has already a pay to dispose");
                        onPMSPayEnd(HMSAgent.AgentResultCode.REQUEST_REPEATED, null);
                        return;
                    }

                    //启动支付流程
                    try {
                        statusForPay = status;
                        Intent intent = new Intent(curActivity, HMSPMSPayAgentActivity.class);
                        intent.putExtra(BaseAgentActivity.EXTRA_IS_FULLSCREEN, UIUtils.isActivityFullscreen(curActivity));
                        curActivity.startActivity(intent);
                    } catch (Exception e) {
                        HMSAgentLog.e("start HMSPayAgentActivity error:" + e.getMessage());
                        onPMSPayEnd(HMSAgent.AgentResultCode.START_ACTIVITY_ERROR, null);
                    }
                }else {
                    onPMSPayEnd(rstCode, null);
                }
            }
        });
    }
938851
@Override
    public ResourceSet<Service> read(final TwilioRestClient client) {
        return new ResourceSet<>(this, client, firstPage(client));
    }
1209688
@Override
    public ResourceSet<Fleet> read(final TwilioRestClient client) {
        return new ResourceSet<>(this, client, firstPage(client));
    }
1177274
private void startConnect() {

        // 触发一次连接将重试次数减1
        curLeftResolveTimes--;

        HMSAgentLog.d("start thread to connect");
        ThreadUtil.INST.excute(new Runnable() {
            @Override
            public void run() {
                HuaweiApiClient client =  getApiClient();

                if (client != null) {
                    HMSAgentLog.d("connect");
                    Activity curActivity = ActivityMgr.INST.getLastActivity();

                    // 考虑到有cp后台需要调用接口，HMSSDK去掉了activity不能为空的判断。这里只是取当前activity，可能为空
                    timeoutHandler.sendEmptyMessageDelayed(APICLIENT_TIMEOUT_HANDLE_MSG, APICLIENT_CONNECT_TIMEOUT);
                    client.connect(curActivity);
                } else {
                    HMSAgentLog.d("client is generate error");
                    onConnectEnd(HMSAgent.AgentResultCode.RESULT_IS_NULL);
                }
            }
        });
    }
1287665
@Override
    public void onAfterSent(ChannelContext channelContext, Packet packet, boolean isSentSuccess) throws Exception {
        log.debug("消息包发送之后触发onAfterSent");
    }
1111488
@Override
    public ResourceSet<SyncList> read(final TwilioRestClient client) {
        return new ResourceSet<>(this, client, firstPage(client));
    }
63437
public static void serverReceived(NettyHttpRequest request) {
        try {
            SofaRequest sofaRequest = new SofaRequest();

            HttpHeaders headers = request.getHttpHeaders();
            String rpcTraceContext = headers.getHeaderString(RemotingConstants.NEW_RPC_TRACE_NAME);
            if (StringUtils.isNotBlank(rpcTraceContext)) {
                // 新格式
                sofaRequest.addRequestProp(RemotingConstants.NEW_RPC_TRACE_NAME, rpcTraceContext);
            } else {
                String traceIdKey = headers.getHeaderString(RemotingConstants.HTTP_HEADER_TRACE_ID_KEY);
                String rpcIdKey = headers.getHeaderString(RemotingConstants.HTTP_HEADER_RPC_ID_KEY);
                if (StringUtils.isEmpty(rpcIdKey)) {
                    rpcIdKey = request.getUri().getQueryParameters().getFirst(RemotingConstants.RPC_ID_KEY);
                }
                if (StringUtils.isEmpty(traceIdKey)) {
                    traceIdKey = request.getUri().getQueryParameters().getFirst(RemotingConstants.TRACE_ID_KEY);
                }

                if (StringUtils.isNotEmpty(traceIdKey) && StringUtils.isNotEmpty(rpcIdKey)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put(RemotingConstants.TRACE_ID_KEY, traceIdKey);
                    map.put(RemotingConstants.RPC_ID_KEY, rpcIdKey);
                    String penAttrs = headers.getHeaderString(RemotingConstants.PEN_ATTRS_KEY);
                    map.put(RemotingConstants.PEN_ATTRS_KEY, penAttrs);
                    sofaRequest.addRequestProp(RemotingConstants.RPC_TRACE_NAME, map);
                }
            }
            Tracers.serverReceived(sofaRequest);
        } catch (Throwable t) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("the process of rest tracer server receive occur error ", t);
            }
        }
    }
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());
  }
992270
@Override
    public Connection getConnection(RpcClient rpcClient, ClientTransportConfig transportConfig, Url url) {
        if (rpcClient == null || transportConfig == null || url == null) {
            return null;
        }
        Connection connection = urlConnectionMap.get(transportConfig);
        if (connection != null && !connection.isFine()) {
            closeConnection(rpcClient, transportConfig, url);
            connection = null;
        }
        if (connection == null) {
            try {
                connection = rpcClient.getConnection(url, url.getConnectTimeout());
            } catch (Exception e) {
                LOGGER.warn("get connection failed in url," + url);
            }
            if (connection == null) {
                return null;
            }
            // 保存唯一长连接
            Connection oldConnection = urlConnectionMap.putIfAbsent(transportConfig, connection);
            if (oldConnection != null) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.warn("Multiple threads init ClientTransport with same key:" + url);
                }
                //only if new connection is not equals old connection,we can close it
                if (connection != oldConnection) {
                    rpcClient.closeStandaloneConnection(connection); //如果同时有人插入，则使用第一个
                    connection = oldConnection;
                }
            } else {

                // 增加计数器
                AtomicInteger counter = connectionRefCounter.get(connection);
                if (counter == null) {
                    counter = new AtomicInteger(0);
                    AtomicInteger oldCounter = connectionRefCounter.putIfAbsent(connection, counter);
                    if (oldCounter != null) {
                        counter = oldCounter;
                    }
                }
                int currentCount = counter.incrementAndGet();
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Bolt client transport {} of {}, current ref count is: {}", url.toString(),
                        NetUtils.channelToString(connection.getLocalAddress(), connection.getRemoteAddress()),
                        currentCount);
                }
            }
        }
        return connection;
    }
1336861
public ListenableFuture<ResourceSet<T>> readAsync(final TwilioRestClient client) {
        return Twilio.getExecutorService().submit(new Callable<ResourceSet<T>>() {
            public ResourceSet<T> call() {
                return read(client);
            }
        });
    }
388001
@Override
    public ResourceSet<Mobile> read(final TwilioRestClient client) {
        return new ResourceSet<>(this, client, firstPage(client));
    }
811316
@Override
    public ResourceSet<Function> read(final TwilioRestClient client) {
        return new ResourceSet<>(this, client, firstPage(client));
    }
1270147
@Override
    public ResourceSet<Activity> read(final TwilioRestClient client) {
        return new ResourceSet<>(this, client, firstPage(client));
    }
1313840
@Override
    public ResourceSet<SyncMapItem> read(final TwilioRestClient client) {
        return new ResourceSet<>(this, client, firstPage(client));
    }
982058
public static long getMBRss(Client client) {
        assert(client != null);
        long rssMax = 0;
        try {
            ClientResponse r = client.callProcedure("@Statistics", "MEMORY", 0);
            VoltTable stats = r.getResults()[0];
            stats.resetRowPosition();
            while (stats.advanceRow()) {
                long rss = stats.getLong("RSS") / 1024;
                if (rss > rssMax) {
                    rssMax = rss;
                }
            }
            return rssMax;
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
            return 0;
        }
    }
353373
@Override
    public RetryingHttpClient build(Client<HttpRequest, HttpResponse> delegate) {
        if (needsContentInStrategy) {
            return new RetryingHttpClient(delegate, retryStrategyWithContent(), maxTotalAttempts(),
                                          responseTimeoutMillisForEachAttempt(), useRetryAfter,
                                          contentPreviewLength);
        }

        return new RetryingHttpClient(delegate, retryStrategy(), maxTotalAttempts(),
                                      responseTimeoutMillisForEachAttempt(), useRetryAfter);
    }
337247
public static void createAsync(final TemplateBasedViewBuilderClient client) {
        GWT.runAsync(new RunAsyncCallback() {
            public void onFailure(Throwable err) {
                client.onUnavailable();
                throw new IllegalStateException(err);
            }

            public void onSuccess() {
                GWTVizPlot.createAsync(new GWTVizPlot.GWTVizPlotClient() {
                    @Override
                    public void onSuccess(GWTVizPlot gwtVizPlot) {
                        if (instance == null) {
                            instance = new TemplateBasedViewBuilder(gwtVizPlot);
                        }
                        client.onSuccess(instance);
                    }

                    @Override
                    public void onUnavailable() {
                        throw new IllegalStateException("unable to load plotter");
                    }
                });


            }
        });
    }