FiberHttpClient Basic
2017-03-02 00:00
99 查看
摘要: FiberHttpClient is the fiber async transform of apache httpClient.
FiberAsync
Fiber Async Transform
将任意同步操作换成Fiber AsyncFiberAsync
FiberHttpClient
@Override @Suspendable protected final CloseableHttpResponse doExecute(final HttpHost target, final HttpRequest request, final HttpContext context) throws IOException, ClientProtocolException { try { for (int executionCount = 0;; executionCount++) { try { final HttpResponse response = new AsyncHttpReq() { @Override protected void requestAsync() { //所有的代码就是在这里把 sync 转化为fiber async client.execute(target, request, context, this); } }.run(); return new CloseableHttpResponseWrapper(response); } ........ 这里省略 }
Configuration
值得一提的是,FiberHttpClient,其实是用的 CloseableHttpAsyncClient来进行IO操作,只是一开始调用的线程换成了fiber,可以执行更多的请求(比线程轻量),和执行其它的操作(fiber.get() or channel.receive() )。public class FiberHttpClient extends CloseableHttpClient { private final Log log = LogFactory.getLog(getClass()); private final CloseableHttpAsyncClient client; private final HttpRequestRetryHandler httpRequestRetryHandler; private DefaultConnectingIOReactor ioreactor; public FiberHttpClient(CloseableHttpAsyncClient client) { this(client, null, null); } public FiberHttpClient(CloseableHttpAsyncClient client, IOReactor ioreactor) { this(client, null, ioreactor); } public FiberHttpClient(CloseableHttpAsyncClient client, HttpRequestRetryHandler httpRequestRetryHandler) { this(client, httpRequestRetryHandler, null); } public FiberHttpClient(CloseableHttpAsyncClient client, HttpRequestRetryHandler httpRequestRetryHandler, IOReactor ioreactor) { this.client = client; this.httpRequestRetryHandler = httpRequestRetryHandler; if (ioreactor != null && ioreactor instanceof DefaultConnectingIOReactor) this.ioreactor = (DefaultConnectingIOReactor) ioreactor; if (!client.isRunning()) client.start(); }
相关文章推荐
- Java HttpClient Basic Credential 认证
- HttpPost设置请求超时的2种方法:DefaultHttpClient与BasicHttpParams
- HttpClient Basic Authentication
- HttpClient--BasicNameValuePair
- httpclient basic认证
- httpclient结合http报文查看工具的一个实例
- WP添加请求链接来路 WP7/8(Windows Phone) and Http-Referer and WebClient-referer
- httpclient通过POST来上传文件,而不是通过流的形式,并在服务端进行解析(通过httpmime.jar来操作)
- HttpClient 的使用
- 解决 httpclient 返回乱码
- WCF HttpBinding 安全解析 (5)Basic验证(IIS宿主)
- httpClient 实现微信公众号消息群发
- WS BasicHttpBinding 安全解析(7)Certificate验证(IIS宿主)
- AsyncHttpClient放在子线程执行时抛出异常的解决方法
- asynctask_httpclient
- HttpClient使用详解
- Java 服务器端与服务器端的通信之httpclient
- 【Ts 5】Httpclient的应用和封装
- 使用CURL封装HttpClient
- AndroidHttp通信 HTTP Client与HttpURLConnection的区别