forked from code4craft/webmagic
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
3a666fc
commit 17e95f2
Showing
3 changed files
with
5 additions
and
21 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* Thread pool for workers.<br></br> | ||
* Use {@link java.util.concurrent.ExecutorService} as inner implement. <br></br> | ||
* New feature: <br></br> | ||
* 1. Block when thread pool is full to avoid poll many urls but not process. <br></br> | ||
* 1. Block when thread pool is full to avoid poll many urls without process. <br></br> | ||
* 2. Count of thread alive for monitor. | ||
* | ||
* @author [email protected] | ||
|
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 |
---|---|---|
|
@@ -3,12 +3,14 @@ | |
import us.codecraft.webmagic.Page; | ||
import us.codecraft.webmagic.Site; | ||
import us.codecraft.webmagic.processor.PageProcessor; | ||
import us.codecraft.webmagic.utils.Experimental; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author [email protected] <br> | ||
*/ | ||
@Experimental | ||
public class ConfigurablePageProcessor implements PageProcessor { | ||
|
||
private Site site; | ||
|
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 |
---|---|---|
|
@@ -5,8 +5,7 @@ | |
import us.codecraft.webmagic.Request; | ||
import us.codecraft.webmagic.Spider; | ||
import us.codecraft.webmagic.SpiderListener; | ||
import us.codecraft.webmagic.processor.example.GithubRepoPageProcessor; | ||
import us.codecraft.webmagic.processor.example.OschinaBlogPageProcessor; | ||
import us.codecraft.webmagic.utils.Experimental; | ||
import us.codecraft.webmagic.utils.IPUtils; | ||
|
||
import javax.management.JMException; | ||
|
@@ -30,6 +29,7 @@ | |
* @author [email protected] | ||
* @since 0.5.0 | ||
*/ | ||
@Experimental | ||
public class SpiderMonitor { | ||
|
||
private enum Type { | ||
|
@@ -226,22 +226,4 @@ public SpiderMonitor jmxStart(String jndiServer, int rmiPort) throws IOException | |
return this; | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
Spider oschinaSpider = Spider.create(new OschinaBlogPageProcessor()) | ||
.addUrl("http://my.oschina.net/flashsword/blog").thread(2); | ||
Spider githubSpider = Spider.create(new GithubRepoPageProcessor()) | ||
.addUrl("https://github.com/code4craft"); | ||
|
||
SpiderMonitor spiderMonitor = new SpiderMonitor(); | ||
spiderMonitor.register(oschinaSpider, githubSpider); | ||
//If you want to connect it from remote, use spiderMonitor.server().jmxStart(); | ||
//ONLY ONE server can start for a machine. | ||
//Others will be registered | ||
spiderMonitor.server().jmxStart(); | ||
oschinaSpider.start(); | ||
githubSpider.thread(10).start(); | ||
|
||
} | ||
|
||
} |