1 |
2384
|
costa
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Copyright: 2004 University of New Mexico and the
|
4 |
|
|
* Regents of the University of California
|
5 |
|
|
*
|
6 |
|
|
* '$Author$'
|
7 |
|
|
* '$Date$'
|
8 |
|
|
* '$Revision$'
|
9 |
|
|
*
|
10 |
|
|
* This program is free software; you can redistribute it and/or modify
|
11 |
|
|
* it under the terms of the GNU General Public License as published by
|
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
* (at your option) any later version.
|
14 |
|
|
*
|
15 |
|
|
* This program is distributed in the hope that it will be useful,
|
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
* GNU General Public License for more details.
|
19 |
|
|
*
|
20 |
|
|
* You should have received a copy of the GNU General Public License
|
21 |
|
|
* along with this program; if not, write to the Free Software
|
22 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
*/
|
24 |
|
|
|
25 |
|
|
package edu.ucsb.nceas.metacat.harvesterClient;
|
26 |
|
|
|
27 |
|
|
import javax.servlet.*;
|
28 |
|
|
import javax.servlet.http.*;
|
29 |
|
|
/**
|
30 |
|
|
* HarvesterServlet class allows Harvester to be run as a background
|
31 |
|
|
* process. This eliminates the need to run Harvester in a terminal window.
|
32 |
|
|
* To activate this servlet, uncomment the HarvesterServlet entry in the
|
33 |
|
|
* appropriate 'lib/web.xml.tomcat*' file.
|
34 |
|
|
*
|
35 |
|
|
* @author costa
|
36 |
|
|
*/
|
37 |
|
|
public class HarvesterServlet extends HttpServlet implements Runnable {
|
38 |
|
|
|
39 |
2995
|
costa
|
/*
|
40 |
|
|
* Class fields
|
41 |
|
|
*/
|
42 |
|
|
private static final String SCHEMA_DIR = "harvester";
|
43 |
|
|
private static String SCHEMA_LOCATION;
|
44 |
|
|
private static final String SCHEMA_NAME = "harvestList.xsd";
|
45 |
|
|
static final long serialVersionUID = 0; // Needed for Eclipse warning.
|
46 |
|
|
|
47 |
|
|
/*
|
48 |
|
|
* Object fields
|
49 |
|
|
*/
|
50 |
2384
|
costa
|
Thread harvesterThread; // background Harvester thread
|
51 |
|
|
|
52 |
2995
|
costa
|
|
53 |
2384
|
costa
|
/**
|
54 |
2995
|
costa
|
* When the thread is destroyed, sets the Harvester.keepRunning flag to false.
|
55 |
2384
|
costa
|
*/
|
56 |
2995
|
costa
|
public void destroy() {
|
57 |
|
|
Harvester.setKeepRunning(false);
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Initializes the servlet. Reads properties and initializes object fields.
|
63 |
|
|
*
|
64 |
|
|
* @throws ServletException
|
65 |
|
|
*/
|
66 |
|
|
public void init(ServletConfig config) throws ServletException {
|
67 |
|
|
ServletContext context = null;
|
68 |
|
|
String fileSeparator = System.getProperty("file.separator");
|
69 |
|
|
String schemaPath;
|
70 |
|
|
|
71 |
|
|
super.init(config);
|
72 |
|
|
context = config.getServletContext();
|
73 |
|
|
schemaPath = context.getRealPath(SCHEMA_DIR) + fileSeparator + SCHEMA_NAME;
|
74 |
|
|
SCHEMA_LOCATION = "eml://ecoinformatics.org/harvestList " + schemaPath;
|
75 |
2384
|
costa
|
harvesterThread = new Thread(this);
|
76 |
|
|
harvesterThread.setPriority(Thread.MIN_PRIORITY); // be a good citizen
|
77 |
|
|
harvesterThread.start();
|
78 |
|
|
}
|
79 |
|
|
|
80 |
2995
|
costa
|
|
81 |
2384
|
costa
|
/**
|
82 |
|
|
* Runs the Harvester main program in a separate thread. First sleeps for
|
83 |
|
|
* 30 seconds to give Metacat a chance to fully initialize.
|
84 |
|
|
*/
|
85 |
|
|
public void run() {
|
86 |
4999
|
costa
|
String[] args = new String[2];
|
87 |
|
|
args[0] = "false"; // Set to true if in command line mode or test mode
|
88 |
|
|
args[1] = SCHEMA_LOCATION;
|
89 |
2384
|
costa
|
|
90 |
|
|
try {
|
91 |
|
|
Thread.sleep(30000); // Sleep 30 seconds before starting Harvester
|
92 |
|
|
}
|
93 |
|
|
catch (InterruptedException e) {
|
94 |
|
|
System.err.println("InterruptedException: " + e.getMessage());
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
Harvester.main(args);
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
}
|