Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

Allow to stop currently running warc import (stop button)

reger51a4e03c9383
diff --git a/htroot/IndexImportWarc_p.html b/htroot/IndexImportWarc_p.html
index 0d490eb9e..2a79d1fc4 100644
--- a/htroot/IndexImportWarc_p.html
+++ b/htroot/IndexImportWarc_p.html
@@ -37,16 +37,19 @@
<br />
::
- <form><fieldset><legend>Import Process</legend>
- <dl>
- <dt>Thread:</dt><dd>#[thread]#</dd>
- <dt>Warc File:</dt><dd>#[warcfile]#</dd>
- <dt>Processed:</dt><dd>#[count]# Entries</dd>
- <dt>Speed:</dt><dd>#[speed]# pages per second</dd>
- <dt>Running Time:</dt><dd>#[runningHours]# hours, #[runningMinutes]# minutes</dd>
- <dt>Remaining Time:</dt><dd>#[remainingHours]# hours, #[remainingMinutes]# minutes</dd>
- </dl>
- </fieldset></form>
+ <form>
+ <fieldset><legend>Import Process</legend>
+ <dl>
+ <dt>Thread:</dt><dd>#[thread]#</dd>
+ <dt>Warc File:</dt><dd>#[warcfile]#</dd>
+ <dt>Processed:</dt><dd>#[count]# Entries</dd>
+ <dt>Speed:</dt><dd>#[speed]# pages per second</dd>
+ <dt>Running Time:</dt><dd>#[runningHours]# hours, #[runningMinutes]# minutes</dd>
+ <dt>Remaining Time:</dt><dd>#[remainingHours]# hours, #[remainingMinutes]# minutes</dd>
+ </dl>
+ </fieldset>
+ <input name="abort" type="submit" class="btn btn-danger" value="Stop"/>
+ </form>
#(/import)#
#%env/templates/footer.template%#
diff --git a/htroot/IndexImportWarc_p.java b/htroot/IndexImportWarc_p.java
index 6a3127952..ff88a5fc9 100644
--- a/htroot/IndexImportWarc_p.java
+++ b/htroot/IndexImportWarc_p.java
@@ -46,6 +46,9 @@ public class IndexImportWarc_p {
prop.put("import_runningMinutes", (WarcImporter.job.runningTime() / 60) % 60);
prop.put("import_remainingHours", (WarcImporter.job.remainingTime() / 60) / 60);
prop.put("import_remainingMinutes", (WarcImporter.job.remainingTime() / 60) % 60);
+ if (post != null && post.containsKey("abort")) {
+ WarcImporter.job.quit();
+ }
} else {
prop.put("import", 0);
if (post != null) {
diff --git a/source/net/yacy/document/importer/WarcImporter.java b/source/net/yacy/document/importer/WarcImporter.java
index 99bc18e74..5b3cb2c49 100644
--- a/source/net/yacy/document/importer/WarcImporter.java
+++ b/source/net/yacy/document/importer/WarcImporter.java
@@ -58,7 +58,7 @@ import org.jwat.warc.WarcRecord;
*/
public class WarcImporter extends Thread implements Importer {
- static public Importer job; // static object to assure only one importer is running (if started from a servlet, this object is used to store the thread)
+ static public WarcImporter job; // static object to assure only one importer is running (if started from a servlet, this object is used to store the thread)
private final InputStream source; // current input warc archive
private String name; // file name of input source
@@ -67,6 +67,7 @@ public class WarcImporter extends Thread implements Importer {
private long startTime; // (for statistic)
private final long sourceSize; // length of the input source (for statistic)
private long consumed; // bytes consumed from input source (for statistic)
+ private boolean abort = false; // flag to signal stop of import
public WarcImporter(InputStream f) {
source = f;
@@ -107,7 +108,7 @@ public class WarcImporter extends Thread implements Importer {
WarcReader localwarcReader = WarcReaderFactory.getReader(f);
WarcRecord wrec = localwarcReader.getNextRecord();
- while (wrec != null) {
+ while (wrec != null && !abort) {
HeaderLine hl = wrec.getHeader(WarcConstants.FN_WARC_TYPE);
if (hl != null && hl.value.equals(WarcConstants.RT_RESPONSE)) { // filter responses
@@ -185,6 +186,13 @@ public class WarcImporter extends Thread implements Importer {
ConcurrentLog.info("WarcImporter", ex.getMessage());
}
}
+
+ /**
+ * Set the flag to stop import
+ */
+ public void quit() {
+ this.abort = true;
+ }
/**
* Filename of the input source