-
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
yihui
committed
Jul 7, 2017
1 parent
9b7e7f3
commit a30aaf0
Showing
9 changed files
with
327 additions
and
85 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
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
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
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
77 changes: 77 additions & 0 deletions
77
core/src/main/java/com/quick/hui/crawler/core/fetcher/JobCount.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,77 @@ | ||
package com.quick.hui.crawler.core.fetcher; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* Created by yihui on 2017/7/6. | ||
*/ | ||
@Getter | ||
public class JobCount { | ||
|
||
/** | ||
* 种子对应的id | ||
*/ | ||
public static int SEED_ID = 1; | ||
|
||
public static AtomicInteger idGen = new AtomicInteger(0); | ||
|
||
|
||
public static int genId() { | ||
return idGen.addAndGet(1); | ||
} | ||
|
||
|
||
/** | ||
* 该Job对应的唯一ID | ||
*/ | ||
private int id; | ||
|
||
|
||
/** | ||
* 该job对应父job的id | ||
*/ | ||
private int parentId; | ||
|
||
|
||
/** | ||
* 当前的层数 | ||
*/ | ||
private int currentDepth; | ||
|
||
|
||
/** | ||
* 该job对应的网页中,子Job的数量 | ||
*/ | ||
private AtomicInteger jobCount = new AtomicInteger(0); | ||
|
||
|
||
/** | ||
* 该Job对应的网页中, 子Job完成的数量 | ||
*/ | ||
private AtomicInteger finishCount = new AtomicInteger(0); | ||
|
||
|
||
public boolean fetchOver() { | ||
return jobCount.get() == finishCount.get(); | ||
} | ||
|
||
|
||
/** | ||
* 爬取完成一个子任务 | ||
*/ | ||
public synchronized boolean finishJob() { | ||
finishCount.addAndGet(1); | ||
return fetchOver(); | ||
} | ||
|
||
|
||
public JobCount(int id, int parentId, int currentDepth, int jobCount, int finishCount) { | ||
this.id = id; | ||
this.parentId = parentId; | ||
this.currentDepth = currentDepth; | ||
this.jobCount.set(jobCount); | ||
this.finishCount.set(finishCount); | ||
} | ||
} |
Oops, something went wrong.