Project

General

Profile

« Previous | Next » 

Revision 2995

Two changes to Metacat Harvester implementation:

(1) Removed call to deprecated Thread.stop() method. Added boolean class variable, Harvester.keepRunning. When the thread is destroyed, set Harvester.keepRunning to false.

(2) Access the harvestList.xsd schema file by finding it locally in the web application rather than via a URL to cvs.ecoinformatics.org.

View differences:

HarvesterServlet.java
24 24

  
25 25
package edu.ucsb.nceas.metacat.harvesterClient;
26 26

  
27
import java.io.File;
28
import java.io.IOException;
29

  
27 30
import javax.servlet.*;
28 31
import javax.servlet.http.*;
29 32

  
33
import edu.ucsb.nceas.utilities.Options;
34

  
30 35
/**
31 36
 * HarvesterServlet class allows Harvester to be run as a background
32 37
 * process. This eliminates the need to run Harvester in a terminal window.
......
37 42
 */
38 43
public class HarvesterServlet extends HttpServlet implements Runnable {
39 44

  
45
  /*
46
   * Class fields
47
   */
48
  private static final String SCHEMA_DIR = "harvester";
49
  private static String SCHEMA_LOCATION;
50
  private static final String SCHEMA_NAME = "harvestList.xsd";
51
  static final long serialVersionUID = 0;  // Needed for Eclipse warning.
52

  
53
  /*
54
   * Object fields
55
   */  
40 56
  Thread harvesterThread;                // background Harvester thread
41 57

  
58

  
42 59
  /**
43
   * Initializes the servlet by starting a separate thread in which to
44
   * run the Harvester main program.
60
   * When the thread is destroyed, sets the Harvester.keepRunning flag to false.
45 61
   */
46
  public void init() throws ServletException {
62
  public void destroy() {
63
    Harvester.setKeepRunning(false);
64
  }
65
  
66

  
67
  /**
68
   * Initializes the servlet. Reads properties and initializes object fields.
69
   * 
70
   * @throws ServletException
71
   */
72
  public void init(ServletConfig config) throws ServletException {
73
    ServletContext context = null;
74
    String fileSeparator = System.getProperty("file.separator");
75
    String schemaPath;
76

  
77
    super.init(config);
78
    context = config.getServletContext();
79
    schemaPath = context.getRealPath(SCHEMA_DIR) + fileSeparator + SCHEMA_NAME;
80
    SCHEMA_LOCATION = "eml://ecoinformatics.org/harvestList " + schemaPath;
47 81
    harvesterThread = new Thread(this);
48 82
    harvesterThread.setPriority(Thread.MIN_PRIORITY);  // be a good citizen
49 83
    harvesterThread.start();
50 84
  }
51 85

  
52
  
86

  
53 87
  /**
54 88
   * Runs the Harvester main program in a separate thread. First sleeps for
55 89
   * 30 seconds to give Metacat a chance to fully initialize.
56 90
   */
57 91
  public void run() {
58 92
      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;
93
      args[0] = SCHEMA_LOCATION;
64 94

  
65 95
      try {
66 96
        Thread.sleep(30000);    // Sleep 30 seconds before starting Harvester
......
72 102
      Harvester.main(args);
73 103
  }
74 104

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

Also available in: Unified diff