Project

General

Profile

« Previous | Next » 

Revision 2995

Added by Duane Costa over 18 years ago

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:

src/edu/ucsb/nceas/metacat/harvesterClient/Harvester.java
59 59
  private static final String CONFIG_DIR_TEST = "./build/war/WEB-INF";
60 60
  private static final String CONFIG_NAME = "metacat.properties";
61 61
  public static final String filler = "*";
62
  private static boolean keepRunning = true;
62 63
  public static final String marker =
63 64
"*****************************************************************************";
64 65
  public static Options options = null;
......
121 122
    
122 123
    if (args.length > 0) {
123 124
      schemaLocation = args[0];
125
      System.err.println("schemaLocation: " + schemaLocation);
126
      
127
      try {
128
        Thread.sleep(10000);
129
      } 
130
      catch (InterruptedException e) {
131
        e.printStackTrace();
132
      }
124 133
    }
125 134

  
126 135
    System.out.println(marker);
......
186 195
    // Subtract delta from the time period so 
187 196
    // that each harvest will start at a fixed interval.
188 197
    //
189
    while ((nHarvests < maxHarvests) || (maxHarvests <= 0)) {
198
    while (keepRunning && ((nHarvests < maxHarvests) || (maxHarvests <= 0))) {
190 199
      nHarvests++;
191 200
      startTime = System.currentTimeMillis();
192 201
      harvester = new Harvester();                // New object for this harvest
......
210 219
      }
211 220
    }
212 221
  }
222
  
223
  
224
  /**
225
   * Set the keepRunning flag. If set to false, the main program will end
226
   * the while loop that keeps harvester running every period number of hours.
227
   * The static method is intended to be called from the HarvesterServlet class
228
   * which creates a thread to run Harvester. When the thread is destroyed, the
229
   * thread's destroy() method calls Harvester.setKeepRunning(false).
230
   * 
231
   * @param keepRunning
232
   */
233
  static void setKeepRunning(boolean keepRunning) {
234
    Harvester.keepRunning = keepRunning;
235
  }
213 236

  
214

  
237
  
215 238
  /*
216 239
   * Object fields
217 240
   */
src/edu/ucsb/nceas/metacat/harvesterClient/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