Allow to stop currently running warc import (stop button)

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

@ -37,16 +37,19 @@
<br /> <br />
:: ::
<form><fieldset><legend>Import Process</legend> <form>
<dl> <fieldset><legend>Import Process</legend>
<dt>Thread:</dt><dd>#[thread]#</dd> <dl>
<dt>Warc File:</dt><dd>#[warcfile]#</dd> <dt>Thread:</dt><dd>#[thread]#</dd>
<dt>Processed:</dt><dd>#[count]# Entries</dd> <dt>Warc File:</dt><dd>#[warcfile]#</dd>
<dt>Speed:</dt><dd>#[speed]# pages per second</dd> <dt>Processed:</dt><dd>#[count]# Entries</dd>
<dt>Running Time:</dt><dd>#[runningHours]# hours, #[runningMinutes]# minutes</dd> <dt>Speed:</dt><dd>#[speed]# pages per second</dd>
<dt>Remaining Time:</dt><dd>#[remainingHours]# hours, #[remainingMinutes]# minutes</dd> <dt>Running Time:</dt><dd>#[runningHours]# hours, #[runningMinutes]# minutes</dd>
</dl> <dt>Remaining Time:</dt><dd>#[remainingHours]# hours, #[remainingMinutes]# minutes</dd>
</fieldset></form> </dl>
</fieldset>
<input name="abort" type="submit" class="btn btn-danger" value="Stop"/>
</form>
#(/import)# #(/import)#
#%env/templates/footer.template%# #%env/templates/footer.template%#

@ -46,6 +46,9 @@ public class IndexImportWarc_p {
prop.put("import_runningMinutes", (WarcImporter.job.runningTime() / 60) % 60); prop.put("import_runningMinutes", (WarcImporter.job.runningTime() / 60) % 60);
prop.put("import_remainingHours", (WarcImporter.job.remainingTime() / 60) / 60); prop.put("import_remainingHours", (WarcImporter.job.remainingTime() / 60) / 60);
prop.put("import_remainingMinutes", (WarcImporter.job.remainingTime() / 60) % 60); prop.put("import_remainingMinutes", (WarcImporter.job.remainingTime() / 60) % 60);
if (post != null && post.containsKey("abort")) {
WarcImporter.job.quit();
}
} else { } else {
prop.put("import", 0); prop.put("import", 0);
if (post != null) { if (post != null) {

@ -58,7 +58,7 @@ import org.jwat.warc.WarcRecord;
*/ */
public class WarcImporter extends Thread implements Importer { 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 final InputStream source; // current input warc archive
private String name; // file name of input source 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 long startTime; // (for statistic)
private final long sourceSize; // length of the input source (for statistic) private final long sourceSize; // length of the input source (for statistic)
private long consumed; // bytes consumed from 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) { public WarcImporter(InputStream f) {
source = f; source = f;
@ -107,7 +108,7 @@ public class WarcImporter extends Thread implements Importer {
WarcReader localwarcReader = WarcReaderFactory.getReader(f); WarcReader localwarcReader = WarcReaderFactory.getReader(f);
WarcRecord wrec = localwarcReader.getNextRecord(); WarcRecord wrec = localwarcReader.getNextRecord();
while (wrec != null) { while (wrec != null && !abort) {
HeaderLine hl = wrec.getHeader(WarcConstants.FN_WARC_TYPE); HeaderLine hl = wrec.getHeader(WarcConstants.FN_WARC_TYPE);
if (hl != null && hl.value.equals(WarcConstants.RT_RESPONSE)) { // filter responses 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()); ConcurrentLog.info("WarcImporter", ex.getMessage());
} }
} }
/**
* Set the flag to stop import
*/
public void quit() {
this.abort = true;
}
/** /**
* Filename of the input source * Filename of the input source

Loading…
Cancel
Save