0

Lets consider one of the latest (4.2.x) releases of HttpComponents.

Please explain how generally an instance of HttpClient is related to instance of HttpConnection (such as ManagedClientConnectionImpl) and also ClientConnectionManager. Who knows about who ?

I will refer to them below ommiting [Http] prefix. So, HttpClient -> Client

I understand that Client keeps reference to ClientConnectionManager. Does that mean that Client also has reference to underlying Connection object ?

Does ConnectionManager knows about all Clients linked to it ?

How HttpGet, which is used by HttpClient to perform execute, knows about stream, exposed thru response's Entity ? (which it does, because we can close the stream by calling .abort() on HttpGet object.) Is HttpGet instance also linked to Connection object ?

I am confused and would appreciate detailed overview answering the questions above. To give examples, you could use any specific implementations, such as DefaultHttpClient, ManagedClientConnectionImpl, BasicClientConnectionManager, if it would make understanding easier.

4

1 回答 1

3

HttpClient是请求执行管道的外观。执行管道的确切组成取决于HttpClient实例的配置。将其视为具有多个选项卡的浏览器。

多个HttpClient实例之一可以依赖于一个ClientConnectionManager共享底层持久连接池的实例。ClientConnectionManager实例不知道HttpClient依赖于它们的实例。他们只是将连接租给任何请求他们的实体。

每个请求都在特定的HttpContext. HttpContextinstance 是执行实际 HTTP 交换所涉及的所有有状态对象的集合。HttpContext实例不是线程安全的,不能被多个工作线程共享。

启动 HTTP 交换时,会从与之关联的实例中HttpClient租用一个ManagedClientConnection实例。ClientConnectionManager它将请求消息序列化并传输到对端端点,接收响应头,并将底层连接绑定到响应HttpEntity实例(如果可用)而不读取响应内容。这使 HttpResponse 实例的消费者能够在没有中间内存缓冲的情况下流式传输响应内容。这也使得消费者有必要确保正确释放ManagedClientConnection与响应相关的资源(特别是 )。

于 2013-05-26T11:17:56.343 回答