Project

General

Profile

« Previous | Next » 

Revision 2384

Implement a new HarvesterServlet for running Harvester as a servlet. This eliminates the need to run Harvester in a terminal window. By default, the HarvesterServlet is commented out in lib/web.xml.tomcat(3,4,5). The user documentation will be modified to instruct Harvester administrators to uncomment the HarvesterServlet entry.

View differences:

src/edu/ucsb/nceas/metacat/harvesterClient/Harvester.java
27 27
import com.oreilly.servlet.MailMessage;
28 28
import edu.ucsb.nceas.utilities.Options;
29 29
import java.io.File;
30
import java.io.FileInputStream;
31 30
import java.io.IOException;
32 31
import java.io.PrintStream;
33 32
import java.sql.Connection;
......
63 62
  public static final String marker =
64 63
"*****************************************************************************";
65 64
  public static Options options = null;
65
  private static String schemaLocation = null;
66 66
   
67 67

  
68 68
  /* 
......
118 118
    Integer p;                               // Used in determining the period
119 119
    long startTime;                          // time that a harvest run starts
120 120
    boolean test = false;                    // Passed to loadOption()
121
    
122
    if (args[0] != null) {
123
      schemaLocation = args[0];
124
    }
121 125

  
122 126
    System.out.println(marker);
123 127
    System.out.println("Starting Harvester");
......
525 529

  
526 530
    for (int i = 0; i < harvestSiteScheduleList.size(); i++) {
527 531
      harvestSiteSchedule = (HarvestSiteSchedule)harvestSiteScheduleList.get(i);
532
      
533
      if (Harvester.schemaLocation != null) {
534
        harvestSiteSchedule.setSchemaLocation(Harvester.schemaLocation);
535
      }
536
      
528 537
      harvestSiteSchedule.harvestDocumentList();
529 538
    }
530 539
  }
src/edu/ucsb/nceas/metacat/harvesterClient/HarvesterServlet.java
1
/**
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
/**
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
}
0 83

  

Also available in: Unified diff