Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 University of New Mexico and the 
4
 *             Regents of the University of California
5
 *
6
 *   '$Author: costa $'
7
 *     '$Date: 2005-01-25 13:57:02 -0800 (Tue, 25 Jan 2005) $'
8
 * '$Revision: 2384 $'
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
/**
31
 * HarvesterServlet class allows Harvester to be run as a background
32
 * process. This eliminates the need to run Harvester in a terminal window.
33
 * To activate this servlet, uncomment the HarvesterServlet entry in the
34
 * appropriate 'lib/web.xml.tomcat*' file.
35
 * 
36
 * @author costa
37
 */
38
public class HarvesterServlet extends HttpServlet implements Runnable {
39

    
40
  Thread harvesterThread;                // background Harvester thread
41

    
42
  /**
43
   * Initializes the servlet by starting a separate thread in which to
44
   * run the Harvester main program.
45
   */
46
  public void init() throws ServletException {
47
    harvesterThread = new Thread(this);
48
    harvesterThread.setPriority(Thread.MIN_PRIORITY);  // be a good citizen
49
    harvesterThread.start();
50
  }
51

    
52
  
53
  /**
54
   * Runs the Harvester main program in a separate thread. First sleeps for
55
   * 30 seconds to give Metacat a chance to fully initialize.
56
   */
57
  public void run() {
58
      String[] args = new String[1];
59
      String schemaLocation = "eml://ecoinformatics.org/harvestList " +
60
       "http://cvs.ecoinformatics.org/cvs/cvsweb.cgi/~checkout~" +
61
       "/metacat/lib/harvester/harvestList.xsd?rev=1.1&content-type=text" +
62
       "/plain&only_with_tag=HEAD";
63
      args[0] = schemaLocation;
64

    
65
      try {
66
        Thread.sleep(30000);    // Sleep 30 seconds before starting Harvester
67
      }
68
      catch (InterruptedException e) {
69
        System.err.println("InterruptedException: " + e.getMessage());
70
      }
71

    
72
      Harvester.main(args);
73
  }
74

    
75
  
76
  /**
77
   * Stops the Harvester thread when the servlet shuts down.
78
   */
79
  public void destroy() {
80
    harvesterThread.stop();
81
  }
82
}
(9-9/11)