YiBoRequestDirector.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:yibo-library 作者:
/**
 * Establish connection either directly or through a tunnel and retry in case of
 * a recoverable I/O failure
 */
private void tryConnect(
        final RoutedRequest req, final HttpContext context) throws HttpException, IOException {
    HttpRoute route = req.getRoute();

    int connectCount = 0;
    for (;;) {
        // Increment connect count
        connectCount++;
        try {
            if (!managedConn.isOpen()) {
                managedConn.open(route, context, params);
            } else {
                managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));
            }
            establishRoute(route, context);
            break;
        } catch (IOException ex) {
            try {
                managedConn.close();
            } catch (IOException ignore) {
            }
            if (retryHandler.retryRequest(ex, connectCount, context)) {
                if (Constants.DEBUG) {
                    logger.debug("I/O exception ({}) caught when connecting to the target host: {}",
                            ex.getClass().getName(), ex.getMessage());
                    logger.debug(ex.getMessage(), ex);
                    logger.debug("Retrying connect");
                }
            } else {
                throw ex;
            }
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号