Skip to content

Commit

Permalink
Merge branch 'release/0.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sutra committed Nov 23, 2022
2 parents f45a8ff + 7d091de commit 43ce1a0
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 21 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>us.codecraft</groupId>
<version>0.7.6</version>
<version>0.8.0</version>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<properties>
Expand All @@ -14,14 +14,14 @@
<commons-collections4.version>4.4</commons-collections4.version>
<commons-io.version>2.11.0</commons-io.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<fastjson.version>2.0.14.graal</fastjson.version>
<fastjson.version>2.0.19.graal</fastjson.version>
<groovy-all.version>3.0.13</groovy-all.version>
<guava.version>31.1-jre</guava.version>
<htmlcleaner.version>2.26</htmlcleaner.version>
<httpclient.version>4.5.13</httpclient.version>
<httpcore.version>4.4.15</httpcore.version>
<jedis.version>3.7.1</jedis.version>
<jruby.version>9.3.8.0</jruby.version>
<jruby.version>9.3.9.0</jruby.version>
<json-path.version>2.7.0</json-path.version>
<junit.version>4.13.2</junit.version>
<jython.version>2.7.3</jython.version>
Expand All @@ -31,7 +31,7 @@
<phantomjsdriver.version>1.2.0</phantomjsdriver.version>
<saxon-he.version>11.4</saxon-he.version>
<selenium-java.version>3.141.59</selenium-java.version>
<slf4j.version>2.0.3</slf4j.version>
<slf4j.version>2.0.4</slf4j.version>
<spring-version>4.0.0.RELEASE</spring-version>
<xsoup.version>0.3.5</xsoup.version>
</properties>
Expand Down Expand Up @@ -232,7 +232,7 @@
<configuration>
<rules>
<requireMavenVersion>
<version>3.3.9</version>
<version>3.5.0</version>
</requireMavenVersion>
</rules>
</configuration>
Expand Down
2 changes: 1 addition & 1 deletion webmagic-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>us.codecraft</groupId>
<artifactId>webmagic-parent</artifactId>
<version>0.7.6</version>
<version>0.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
9 changes: 6 additions & 3 deletions webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,10 @@ public void run() {
}
} else {
// wait until new url added,
if (waitNewUrl())
//if interrupted
if (waitNewUrl()) {
//if interrupted
break;
}
continue;
}
}
Expand Down Expand Up @@ -805,11 +806,13 @@ public Scheduler getScheduler() {
* Set wait time when no url is polled.<br><br>
*
* @param emptySleepTime In MILLISECONDS.
* @return this
*/
public void setEmptySleepTime(long emptySleepTime) {
public Spider setEmptySleepTime(long emptySleepTime) {
if(emptySleepTime<=0){
throw new IllegalArgumentException("emptySleepTime should be more than zero!");
}
this.emptySleepTime = emptySleepTime;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ public Page download(Request request, Task task) {
try {
httpResponse = httpClient.execute(requestContext.getHttpUriRequest(), requestContext.getHttpClientContext());
page = handleResponse(request, request.getCharset() != null ? request.getCharset() : task.getSite().getCharset(), httpResponse, task);

onSuccess(request, task);
logger.info("downloading page success {}", request.getUrl());

return page;
} catch (IOException e) {
logger.warn("download page {} error", request.getUrl(), e);

onError(request, task, e);
logger.info("download page {} error", request.getUrl(), e);

return page;
} finally {
if (httpResponse != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,51 @@
package us.codecraft.webmagic.scheduler;

import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Task;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Task;

/**
* Basic Scheduler implementation.<br>
* Store urls to fetch in LinkedBlockingQueue and remove duplicate urls by HashMap.
*
* Note: if you use this {@link QueueScheduler}
* with {@link Site#getCycleRetryTimes()} enabled, you may encountered dead-lock
* when the queue is full.
*
* @author [email protected] <br>
* @since 0.1.0
*/
public class QueueScheduler extends DuplicateRemovedScheduler implements MonitorableScheduler {

private BlockingQueue<Request> queue = new LinkedBlockingQueue<Request>();
private final BlockingQueue<Request> queue;

public QueueScheduler() {
this.queue = new LinkedBlockingQueue<>();
}

/**
* Creates a {@code QueueScheduler} with the given (fixed) capacity.
*
* @param capacity the capacity of this queue,
* see {@link LinkedBlockingQueue#LinkedBlockingQueue(int)}
* @since 0.8.0
*/
public QueueScheduler(int capacity) {
this.queue = new LinkedBlockingQueue<>(capacity);
}

@Override
public void pushWhenNoDuplicate(Request request, Task task) {
queue.add(request);
logger.trace("Remaining capacity: {}", this.queue.remainingCapacity());

try {
queue.put(request);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion webmagic-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>us.codecraft</groupId>
<artifactId>webmagic-parent</artifactId>
<version>0.7.6</version>
<version>0.8.0</version>
</parent>

<artifactId>webmagic-coverage</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion webmagic-extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>us.codecraft</groupId>
<artifactId>webmagic-parent</artifactId>
<version>0.7.6</version>
<version>0.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion webmagic-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>webmagic-parent</artifactId>
<groupId>us.codecraft</groupId>
<version>0.7.6</version>
<version>0.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion webmagic-saxon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>webmagic-parent</artifactId>
<groupId>us.codecraft</groupId>
<version>0.7.6</version>
<version>0.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion webmagic-scripts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>webmagic-parent</artifactId>
<groupId>us.codecraft</groupId>
<version>0.7.6</version>
<version>0.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion webmagic-selenium/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>webmagic-parent</artifactId>
<groupId>us.codecraft</groupId>
<version>0.7.6</version>
<version>0.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down

0 comments on commit 43ce1a0

Please sign in to comment.