Allow to stop currently running warc import (stop button)

pull/93/merge
reger 7 years ago
parent 6cec2cdcb5
commit 51a4e03c93

@ -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%#

@ -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) {

@ -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

Loading…
Cancel
Save