update comments of spider

master
yihua.huang 2013-08-17 21:15:36 +08:00
parent 5f1f4cbc46
commit d01c0eb8ce
2 changed files with 84 additions and 26 deletions

View File

@ -74,9 +74,9 @@ public class Spider implements Runnable, Task {
protected final static int STAT_STOPPED = 2; protected final static int STAT_STOPPED = 2;
/** /**
* 使Spider * create a spider with pageProcessor.
* *
* @param pageProcessor * @param pageProcessor
*/ */
public Spider(PageProcessor pageProcessor) { public Spider(PageProcessor pageProcessor) {
this.pageProcessor = pageProcessor; this.pageProcessor = pageProcessor;
@ -85,17 +85,19 @@ public class Spider implements Runnable, Task {
} }
/** /**
* 使Spider * create a spider with pageProcessor.
* *
* @param pageProcessor * @param pageProcessor
* @return Spider * @return new spider
* @see PageProcessor
*/ */
public static Spider create(PageProcessor pageProcessor) { public static Spider create(PageProcessor pageProcessor) {
return new Spider(pageProcessor); return new Spider(pageProcessor);
} }
/** /**
* startUrlsSitestartUrls * Set startUrls of Spider.<br>
* Prior to startUrls of Site.
* *
* @param startUrls * @param startUrls
* @return this * @return this
@ -107,9 +109,10 @@ public class Spider implements Runnable, Task {
} }
/** /**
* ID使domainuuiddomainID * Set an uuid for spider.<br>
* Default uuid is domain of site.<br>
* *
* @param uuid ID * @param uuid
* @return this * @return this
*/ */
public Spider setUUID(String uuid) { public Spider setUUID(String uuid) {
@ -118,30 +121,86 @@ public class Spider implements Runnable, Task {
} }
/** /**
* URL使 * set scheduler for Spider
* *
* @param scheduler * @param scheduler
* @return this * @return this
* @Deprecated
* @see #setScheduler(us.codecraft.webmagic.scheduler.Scheduler)
*/ */
public Spider scheduler(Scheduler scheduler) { public Spider scheduler(Scheduler scheduler) {
return setScheduler(scheduler);
}
/**
* set scheduler for Spider
*
* @param scheduler
* @return this
* @since 0.2.1
* @see Scheduler
*/
public Spider setScheduler(Scheduler scheduler) {
checkIfNotRunning(); checkIfNotRunning();
this.scheduler = scheduler; this.scheduler = scheduler;
return this; return this;
} }
/** /**
* * add a pipeline for Spider
* *
* @param pipeline * @param pipeline
* @return this * @return this
* @deprecated
* @see #setPipeline(us.codecraft.webmagic.pipeline.Pipeline)
*/ */
public Spider pipeline(Pipeline pipeline) { public Spider pipeline(Pipeline pipeline) {
return addPipeline(pipeline);
}
/**
* add a pipeline for Spider
*
* @param pipeline
* @return this
* @since 0.2.1
* @see Pipeline
*/
public Spider addPipeline(Pipeline pipeline) {
checkIfNotRunning(); checkIfNotRunning();
this.pipelines.add(pipeline); this.pipelines.add(pipeline);
return this; return this;
} }
/**
* clear the pipelines set
*
* @return this
*/
public Spider clearPipeline() {
pipelines = new ArrayList<Pipeline>();
return this;
}
/**
* set the downloader of spider
*
* @param downloader
* @return this
* @deprecated
* @see #setDownloader(us.codecraft.webmagic.downloader.Downloader)
*/
public Spider downloader(Downloader downloader) { public Spider downloader(Downloader downloader) {
return setDownloader(downloader);
}
/**
* set the downloader of spider
* @see Downloader
* @param downloader
* @return this
*/
public Spider setDownloader(Downloader downloader) {
checkIfNotRunning(); checkIfNotRunning();
this.downloader = downloader; this.downloader = downloader;
return this; return this;
@ -226,9 +285,9 @@ public class Spider implements Runnable, Task {
} }
/** /**
* URL * Process specific urls without url discovering.
* *
* @param urls url * @param urls urls to process
*/ */
public void test(String... urls) { public void test(String... urls) {
checkComponent(); checkComponent();
@ -284,9 +343,9 @@ public class Spider implements Runnable, Task {
} }
/** /**
* 线 * start with more than one threads
* *
* @param threadNum 线 * @param threadNum
* @return this * @return this
*/ */
public Spider thread(int threadNum) { public Spider thread(int threadNum) {
@ -304,11 +363,6 @@ public class Spider implements Runnable, Task {
return this; return this;
} }
public Spider clearPipeline() {
pipelines = new ArrayList<Pipeline>();
return this;
}
@Override @Override
public String getUUID() { public String getUUID() {
if (uuid != null) { if (uuid != null) {

View File

@ -1,21 +1,25 @@
package us.codecraft.webmagic; package us.codecraft.webmagic;
/** /**
* <br> * Interface for identifying different tasks.<br>
*
* @author code4crafter@gmail.com <br> * @author code4crafter@gmail.com <br>
* Date: 13-6-18 * @since 0.1.0
* Time: 2:57 * @see us.codecraft.webmagic.scheduler.Scheduler
* @see us.codecraft.webmagic.pipeline.Pipeline
*/ */
public interface Task { public interface Task {
/** /**
* * unique id for a task.
*
* @return uuid * @return uuid
*/ */
public String getUUID(); public String getUUID();
/** /**
* * site of a task
*
* @return site * @return site
*/ */
public Site getSite(); public Site getSite();