From 51a4e03c938364628d8813aa7d66e618cddf0a85 Mon Sep 17 00:00:00 2001 From: reger Date: Sun, 20 Aug 2017 22:17:27 +0200 Subject: [PATCH] Allow to stop currently running warc import (stop button) --- htroot/IndexImportWarc_p.html | 23 +++++++++++-------- htroot/IndexImportWarc_p.java | 3 +++ .../yacy/document/importer/WarcImporter.java | 12 ++++++++-- 3 files changed, 26 insertions(+), 12 deletions(-) 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 @@
:: -
Import Process -
-
Thread:
#[thread]#
-
Warc File:
#[warcfile]#
-
Processed:
#[count]# Entries
-
Speed:
#[speed]# pages per second
-
Running Time:
#[runningHours]# hours, #[runningMinutes]# minutes
-
Remaining Time:
#[remainingHours]# hours, #[remainingMinutes]# minutes
-
-
+
+
Import Process +
+
Thread:
#[thread]#
+
Warc File:
#[warcfile]#
+
Processed:
#[count]# Entries
+
Speed:
#[speed]# pages per second
+
Running Time:
#[runningHours]# hours, #[runningMinutes]# minutes
+
Remaining Time:
#[remainingHours]# hours, #[remainingMinutes]# minutes
+
+
+ +
#(/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