Commit ed3f3583 authored by yihua.huang's avatar yihua.huang

downloader refactor

parent a37f40e6
...@@ -63,14 +63,14 @@ public class HttpClientDownloader implements Downloader { ...@@ -63,14 +63,14 @@ public class HttpClientDownloader implements Downloader {
private CloseableHttpClient getHttpClient(Site site) { private CloseableHttpClient getHttpClient(Site site) {
if (site == null) { if (site == null) {
return new HttpClientPool(poolSize).getClient(null); return new HttpClientGenerator(poolSize).getClient(null);
} }
String domain = site.getDomain(); String domain = site.getDomain();
CloseableHttpClient httpClient = httpClients.get(domain); CloseableHttpClient httpClient = httpClients.get(domain);
if (httpClient == null) { if (httpClient == null) {
synchronized (this) { synchronized (this) {
if (httpClient == null) { if (httpClient == null) {
httpClient = new HttpClientPool(poolSize).getClient(site); httpClient = new HttpClientGenerator(poolSize).getClient(site);
httpClients.put(domain, httpClient); httpClients.put(domain, httpClient);
} }
} }
......
...@@ -21,11 +21,11 @@ import java.util.Map; ...@@ -21,11 +21,11 @@ import java.util.Map;
* @author code4crafter@gmail.com <br> * @author code4crafter@gmail.com <br>
* @since 0.3.3 * @since 0.3.3
*/ */
public class HttpClientPool { public class HttpClientGenerator {
private PoolingHttpClientConnectionManager connectionManager; private PoolingHttpClientConnectionManager connectionManager;
public HttpClientPool(int poolSize) { public HttpClientGenerator(int poolSize) {
Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory>create() Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE) .register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", SSLConnectionSocketFactory.getSocketFactory()) .register("https", SSLConnectionSocketFactory.getSocketFactory())
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<date-generated>Sat Aug 17 14:14:45 CST 2013</date-generated> <date-generated>Sat Aug 17 14:14:45 CST 2013</date-generated>
</meta> </meta>
<comment> <comment>
<key><![CDATA[us.codecraft.webmagic.downloader.HttpClientPool]]></key> <key><![CDATA[us.codecraft.webmagic.downloader.HttpClientGenerator]]></key>
<data><![CDATA[ @author code4crafter@gmail.com <br> <data><![CDATA[ @author code4crafter@gmail.com <br>
Date: 13-4-21 Date: 13-4-21
Time: 下午12:29 Time: 下午12:29
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment