downloader refactor

pull/88/head^2
yihua.huang 11 years ago
parent a37f40e6e6
commit ed3f3583cc

@ -63,14 +63,14 @@ public class HttpClientDownloader implements Downloader {
private CloseableHttpClient getHttpClient(Site site) {
if (site == null) {
return new HttpClientPool(poolSize).getClient(null);
return new HttpClientGenerator(poolSize).getClient(null);
}
String domain = site.getDomain();
CloseableHttpClient httpClient = httpClients.get(domain);
if (httpClient == null) {
synchronized (this) {
if (httpClient == null) {
httpClient = new HttpClientPool(poolSize).getClient(site);
httpClient = new HttpClientGenerator(poolSize).getClient(site);
httpClients.put(domain, httpClient);
}
}

@ -21,11 +21,11 @@ import java.util.Map;
* @author code4crafter@gmail.com <br>
* @since 0.3.3
*/
public class HttpClientPool {
public class HttpClientGenerator {
private PoolingHttpClientConnectionManager connectionManager;
public HttpClientPool(int poolSize) {
public HttpClientGenerator(int poolSize) {
Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", SSLConnectionSocketFactory.getSocketFactory())

@ -4,7 +4,7 @@
<date-generated>Sat Aug 17 14:14:45 CST 2013</date-generated>
</meta>
<comment>
<key><![CDATA[us.codecraft.webmagic.downloader.HttpClientPool]]></key>
<key><![CDATA[us.codecraft.webmagic.downloader.HttpClientGenerator]]></key>
<data><![CDATA[ @author code4crafter@gmail.com <br>
Date: 13-4-21
Time: 下午12:29

Loading…
Cancel
Save