-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
134 changed files
with
10,016 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.jackson.bean; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* Created by Jackson on 2017/1/17. | ||
*/ | ||
public class Bundle { | ||
|
||
private static Logger logger = LogManager.getLogger(Bundle.class.getName()); | ||
HashMap<String, Object> mMap = null; | ||
|
||
|
||
private Bundle(){ | ||
mMap = new HashMap<>(); | ||
} | ||
|
||
public static Bundle newInstance(){ | ||
return new Bundle(); | ||
} | ||
|
||
|
||
|
||
public void put(String key,Object obj){ | ||
mMap.put(key, obj); | ||
} | ||
|
||
public Object get(String key,Object defaultValue){ | ||
Object o = mMap.get(key); | ||
if (o == null) { | ||
return defaultValue; | ||
} | ||
try { | ||
return o; | ||
} catch (ClassCastException e) { | ||
logger.warn("key{},Type{},defaultValue{},Exception{}",key,"Object",defaultValue,e); | ||
return defaultValue; | ||
} | ||
} | ||
|
||
|
||
|
||
public void putBoolean(String key,int value){ | ||
mMap.put(key,value); | ||
} | ||
|
||
public boolean getBoolean(String key,boolean defaultValue){ | ||
Object o = mMap.get(key); | ||
if (o == null) { | ||
return defaultValue; | ||
} | ||
try { | ||
return (boolean) o; | ||
} catch (ClassCastException e) { | ||
logger.warn("key{},Type{},defaultValue{},Exception{}",key,"boolean",defaultValue,e); | ||
return defaultValue; | ||
} | ||
} | ||
|
||
public void putInt(String key,int value){ | ||
mMap.put(key,value); | ||
} | ||
|
||
public int getInt(String key,int defaultValue){ | ||
Object o = mMap.get(key); | ||
if (o == null) { | ||
return defaultValue; | ||
} | ||
try { | ||
return (int) o; | ||
} catch (ClassCastException e) { | ||
logger.warn("key{},Type{},defaultValue{},Exception{}",key,"int",defaultValue,e); | ||
return defaultValue; | ||
} | ||
} | ||
|
||
public void putString(String key,String value){ | ||
mMap.put(key,value); | ||
} | ||
|
||
public String getString(String key,String defaultValue){ | ||
Object o = mMap.get(key); | ||
if (o == null) { | ||
return defaultValue; | ||
} | ||
try { | ||
return (String) o; | ||
} catch (ClassCastException e) { | ||
logger.warn("key{},Type{},defaultValue{},Exception{}",key,"String",defaultValue,e); | ||
return defaultValue; | ||
} | ||
} | ||
|
||
public void putLong(String key,long value){ | ||
mMap.put(key,value); | ||
} | ||
|
||
public long getLong(String key,long defaultValue){ | ||
Object o = mMap.get(key); | ||
if (o == null) { | ||
return defaultValue; | ||
} | ||
try { | ||
return (long) o; | ||
} catch (ClassCastException e) { | ||
logger.warn("key{},Type{},defaultValue{},Exception{}",key,"long",defaultValue,e); | ||
return defaultValue; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.jackson.bean; | ||
|
||
import com.jackson.db.po.Account; | ||
import com.jackson.db.po.Ip; | ||
import com.jackson.db.po.Proxy; | ||
import org.apache.http.client.protocol.HttpClientContext; | ||
import org.apache.http.impl.client.BasicCookieStore; | ||
import org.apache.http.protocol.HttpContext; | ||
|
||
|
||
/** | ||
* Created by Jackson on 2017/1/6. | ||
* 请求相关对象上下文 | ||
*/ | ||
public class ContextSrc { | ||
private Account account; | ||
private HttpClientContext httpContext ; | ||
private String userAgent; | ||
private Proxy proxy; | ||
|
||
public ContextSrc(){ | ||
httpContext = HttpClientContext.create(); | ||
httpContext.setCookieStore(new BasicCookieStore()); | ||
} | ||
|
||
public Account getAccount() { | ||
return account; | ||
} | ||
|
||
public ContextSrc setAccount(Account account) { | ||
this.account = account; | ||
return this; | ||
} | ||
|
||
public HttpClientContext getHttpContext() { | ||
return httpContext; | ||
} | ||
|
||
public ContextSrc setHttpContext(HttpClientContext httpContext) { | ||
this.httpContext = httpContext; | ||
return this; | ||
} | ||
|
||
public String getUserAgent() { | ||
return userAgent; | ||
} | ||
|
||
public ContextSrc setUserAgent(String userAgent) { | ||
this.userAgent = userAgent; | ||
return this; | ||
} | ||
|
||
public Proxy getProxy() { | ||
return proxy; | ||
} | ||
|
||
public ContextSrc setProxy(Proxy proxy) { | ||
this.proxy = proxy; | ||
return this; | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
SpiderJackson/src/com/jackson/common/control/ControlConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.jackson.common.control; | ||
|
||
/** | ||
* Created by Jackson on 2016/12/26. | ||
*/ | ||
public class ControlConfig { | ||
//线程数 | ||
private int corePoolSize; | ||
//线程池中的最大任务数 | ||
private int maxTaskCache; | ||
//线程池中的最小任务数,当小于这个数时,开始添加任务 | ||
private int minTaskCache; | ||
//url池中最小缓存数 | ||
private int minServiceCatch; | ||
//每次从数据库中获取的url数量 | ||
private int getServiceCatchSize; | ||
|
||
private ControlConfig(int corePoolSize, int maxTaskCache, int minTaskCache, int minServiceCatch, int getServiceCatchSize) { | ||
this.corePoolSize = corePoolSize; | ||
this.maxTaskCache = maxTaskCache; | ||
this.minTaskCache = minTaskCache; | ||
this.minServiceCatch = minServiceCatch; | ||
this.getServiceCatchSize = getServiceCatchSize; | ||
} | ||
|
||
public int getCorePoolSize() { | ||
return corePoolSize; | ||
} | ||
|
||
public int getMaxTaskCache() { | ||
return maxTaskCache; | ||
} | ||
|
||
public int getMinTaskCache() { | ||
return minTaskCache; | ||
} | ||
|
||
public int getMinServiceCatch() { | ||
return minServiceCatch; | ||
} | ||
|
||
public int getGetServiceCatchSize() { | ||
return getServiceCatchSize; | ||
} | ||
|
||
public static Builder builder(){ | ||
return new Builder(); | ||
} | ||
|
||
|
||
public static class Builder{ | ||
private Builder(){} | ||
|
||
private int corePoolSize = 10; | ||
private int maxTaskCache = 80; | ||
private int minTaskCache = 20; | ||
private int minServiceCatch = 10; | ||
private int getServiceCatchSize = 100; | ||
|
||
public Builder setCorePoolSize(int corePoolSize) { | ||
this.corePoolSize = corePoolSize; | ||
return this; | ||
} | ||
|
||
public Builder setMaxTaskCache(int maxTaskCache) { | ||
this.maxTaskCache = maxTaskCache; | ||
return this; | ||
} | ||
|
||
public Builder setMinTaskCache(int minTaskCache) { | ||
this.minTaskCache = minTaskCache; | ||
return this; | ||
} | ||
|
||
public Builder setMinServiceCatch(int minServiceCatch) { | ||
this.minServiceCatch = minServiceCatch; | ||
return this; | ||
} | ||
|
||
public Builder setGetServiceCatchSize(int getServiceCatchSize) { | ||
this.getServiceCatchSize = getServiceCatchSize; | ||
return this; | ||
} | ||
|
||
public ControlConfig build(){ | ||
return new ControlConfig(this.corePoolSize,this.maxTaskCache,this.minTaskCache,this.minServiceCatch,this.getServiceCatchSize); | ||
} | ||
} | ||
} |
Oops, something went wrong.