Author: j16sdiz
Date: 2009-04-07 00:18:01 +0000 (Tue, 07 Apr 2009)
New Revision: 26583
Modified:
trunk/plugins/XMLSpider/db/Config.java
trunk/plugins/XMLSpider/web/ConfigPage.java
Log:
"Working period" patch from Artefact2
Editified to remove whitespace changes
Modified: trunk/plugins/XMLSpider/db/Config.java
===================================================================
--- trunk/plugins/XMLSpider/db/Config.java 2009-04-07 00:09:10 UTC (rev 26582)
+++ trunk/plugins/XMLSpider/db/Config.java 2009-04-07 00:18:01 UTC (rev 26583)
@@ -8,6 +8,8 @@
import freenet.node.RequestStarter;
import freenet.support.Logger;
+import java.util.Calendar;
+
public class Config extends Persistent implements Cloneable {
/**
* Directory where the generated indices are stored
@@ -21,7 +23,10 @@
private String indexOwnerEmail;
private int maxShownURIs;
- private int maxParallelRequests;
+ private int maxParallelRequestsWorking;
+ private int maxParallelRequestsNonWorking;
+ private int beginWorkingPeriod; // Between 0 and 23
+ private int endWorkingPeriod; // Between 0 and 23
private String[] badlistedExtensions;
private short requestPriority;
@@ -41,7 +46,10 @@
maxShownURIs = 15;
- maxParallelRequests = 100;
+ maxParallelRequestsWorking = 100;
+ maxParallelRequestsNonWorking = 100;
+ beginWorkingPeriod = 23;
+ endWorkingPeriod = 7;
badlistedExtensions = new String[] { //
".ico", ".bmp", ".png", ".jpg", ".jpeg", ".gif", // image
@@ -132,15 +140,65 @@
return indexOwnerEmail;
}
- public synchronized void setMaxParallelRequests(int maxParallelRequests) {
+ public synchronized void setMaxParallelRequestsWorking(int maxParallelRequests) {
assert !isPersistent();
- this.maxParallelRequests = maxParallelRequests;
+ this.maxParallelRequestsWorking = maxParallelRequests;
}
+ public synchronized int getMaxParallelRequestsWorking() {
+ return maxParallelRequestsWorking;
+ }
+
+ public synchronized void setMaxParallelRequestsNonWorking(int maxParallelRequests) {
+ assert !isPersistent();
+ this.maxParallelRequestsNonWorking = maxParallelRequests;
+ }
+
+ public synchronized int getMaxParallelRequestsNonWorking() {
+ return maxParallelRequestsNonWorking;
+ }
+
public synchronized int getMaxParallelRequests() {
- return maxParallelRequests;
+ int actualHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
+ Boolean isWorking = true;
+
+ if(this.getBeginWorkingPeriod() < this.getEndWorkingPeriod()) {
+ // Midnight isn't in the interval.
+ // m M
+ // 0 -----|############|----- 24
+ isWorking = (actualHour > this.getBeginWorkingPeriod() && actualHour < this.getEndWorkingPeriod());
+ } else {
+ // Midnight is in the interval.
+ // M m
+ // 0 #####|------------|##### 24
+ isWorking = (actualHour > this.getBeginWorkingPeriod() || actualHour < this.getEndWorkingPeriod());
+ }
+
+ if(isWorking) {
+ return this.getMaxParallelRequestsWorking();
+ } else {
+ return this.getMaxParallelRequestsNonWorking();
+ }
}
+ public synchronized void setBeginWorkingPeriod(int beginWorkingPeriod) {
+ assert !isPersistent();
+ this.beginWorkingPeriod = beginWorkingPeriod;
+ }
+
+ public synchronized int getBeginWorkingPeriod() {
+ return beginWorkingPeriod;
+ }
+
+ public synchronized void setEndWorkingPeriod(int endWorkingPeriod) {
+ assert !isPersistent();
+ this.endWorkingPeriod = endWorkingPeriod;
+ }
+
+ public synchronized int getEndWorkingPeriod() {
+ return endWorkingPeriod;
+ }
+
public synchronized void setBadlistedExtensions(String[] badlistedExtensions) {
assert !isPersistent();
this.badlistedExtensions = badlistedExtensions;
Modified: trunk/plugins/XMLSpider/web/ConfigPage.java
===================================================================
--- trunk/plugins/XMLSpider/web/ConfigPage.java 2009-04-07 00:09:10 UTC (rev 26582)
+++ trunk/plugins/XMLSpider/web/ConfigPage.java 2009-04-07 00:18:01 UTC (rev 26583)
@@ -34,10 +34,22 @@
public synchronized void processPostRequest(HTTPRequest request, HTMLNode contentNode) {
config = xmlSpider.getConfig().clone();
- if (request.isPartSet("maxParallelRequests")) {
- int v = request.getIntPart("maxParallelRequests", config.getMaxParallelRequests());
- config.setMaxParallelRequests(v);
+ if (request.isPartSet("maxParallelRequestsWorking")) {
+ int v = request.getIntPart("maxParallelRequestsWorking", config.getMaxParallelRequestsWorking());
+ config.setMaxParallelRequestsWorking(v);
}
+ if (request.isPartSet("maxParallelRequestsNonWorking")) {
+ int v = request.getIntPart("maxParallelRequestsNonWorking", config.getMaxParallelRequestsNonWorking());
+ config.setMaxParallelRequestsNonWorking(v);
+ }
+ if (request.isPartSet("beginWorkingPeriod")) {
+ int v = request.getIntPart("beginWorkingPeriod", config.getBeginWorkingPeriod());
+ config.setBeginWorkingPeriod(v);
+ }
+ if (request.isPartSet("endWorkingPeriod")) {
+ int v = request.getIntPart("endWorkingPeriod", config.getEndWorkingPeriod());
+ config.setEndWorkingPeriod(v);
+ }
if (request.isPartSet("indexMaxEntries")) {
int v = request.getIntPart("indexMaxEntries", config.getIndexMaxEntries());
config.setIndexMaxEntries(v);
@@ -100,11 +112,30 @@
HTMLNode spiderConfig = configForm.addChild("ul", "class", "config");
addConfig(spiderConfig, //
- "Max Parallel Requests", "Maximum number of parallel requests.", //
- "maxParallelRequests", //
+ "Max Parallel Requests (Working)", "Maximum number of parallel requests if we are in the working period.", //
+ "maxParallelRequestsWorking", //
new String[] { "0", "10", "50", "100", "250", "500" }, //
- Integer.toString(config.getMaxParallelRequests()));
+ Integer.toString(config.getMaxParallelRequestsWorking()));
addConfig(spiderConfig, //
+ "Max Parallel Requests (Non-Working)", "Maximum number of parallel requests if we are not in the working period.", //
+ "maxParallelRequestsNonWorking", //
+ new String[] { "0", "10", "50", "100", "250", "500" }, //
+ Integer.toString(config.getMaxParallelRequestsNonWorking()));
+
+ addConfig(spiderConfig, //
+ "Working period beginning hour", "Beginning hour of the Working period.", //
+ "beginWorkingPeriod", //
+ new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
+ "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" }, //
+ Integer.toString(config.getBeginWorkingPeriod()));
+ addConfig(spiderConfig, //
+ "Working period ending hour", "Ending hour of the Working period.", //
+ "endWorkingPeriod", //
+ new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
+ "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" }, //
+ Integer.toString(config.getEndWorkingPeriod()));
+
+ addConfig(spiderConfig, //
"Bad Listed Extensions", "Comma seprated list of banned URI suffix.", //
"badListedExtensions", //
config.getBadlistedExtensions());
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.