/
DomainIngester.java
100 lines (89 loc) · 3.12 KB
/
DomainIngester.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* #%L
* Netarchivesuite - harvester
* %%
* Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library,
* the National Library of France and the Austrian National Library.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package dk.netarkivet.harvester.webinterface;
import java.io.File;
import java.util.Locale;
import javax.servlet.jsp.JspWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import dk.netarkivet.common.exceptions.ArgumentNotValid;
import dk.netarkivet.harvester.datamodel.IngestDomainList;
/**
* This class manages a thread that ingests (i.e. creates) new domains.
*/
public class DomainIngester extends Thread {
/** The log. */
private static final Logger log = LoggerFactory.getLogger(DomainIngester.class);
/** Whether or not the ingesting process is finished yet. */
private boolean done = false;
/** If an exception is thrown during ingest, it gets stored here. */
private Exception e;
/** The file containg a list of domains to ingest. */
private File ingestFile;
/** The JspWriter. */
private JspWriter out;
/** The locale used in forwarding errormessages to the user. */
private Locale l;
/**
* Create a new ingester for a given session and output, reading domains from a file.
*
* @param out The writer that goes into HTML output
* @param ingestFile The file with a list of domains to ingest.
* @param l the given locale
*/
public DomainIngester(JspWriter out, File ingestFile, Locale l) {
ArgumentNotValid.checkNotNull(ingestFile, "File ingestFile");
ArgumentNotValid.checkNotNull(l, "Locale l");
this.out = out;
this.ingestFile = ingestFile;
this.l = l;
}
/**
* Starts the ingesting thread. When 'done' is set to true, the thread is finished, and any exceptions are found in
* 'e'.
*/
public void run() {
try {
new IngestDomainList().updateDomainInfo(ingestFile, out, l);
} catch (Exception ex) {
this.e = ex;
log.warn("Update domains failed", ex);
} finally {
done = true;
}
}
/**
* Check whether or not the DomainIngester is finished.
*
* @return true if finished; false otherwise
*/
public boolean isDone() {
return done;
}
/**
* @return any exception caught during ingest
*/
public Exception getException() {
return e;
}
}