[metacat-cvs] metacat/src/edu/ucsb/nceas/metacat MetaCatServlet.java DBQuery.java DBValidate.java

Matthew Jones jones at ecoinformatics.org
Wed Nov 16 17:27:26 PST 2005


jones       05/11/16 17:27:26

  Modified:    src/edu/ucsb/nceas/metacat MetaCatServlet.java DBQuery.java
                        DBValidate.java
  Log:
  Metacat has had problems with threading issues when accessed from ecogrid.  These problems may stem from the use of shared global variables within the servlet that are not protected against threading problems.  We used a lot of these, which I am eliminating in this commit.  Besides final variables used as constants (which are not a problem), now there are only three unprotected variables (sessionHash, logMetacat, and conn) which are harder to eliminate.  I will be discussiong this with Sid tomorrow to see how to eliminate them.
  
  Revision  Changes    Path
  1.236     +32 -74    metacat/src/edu/ucsb/nceas/metacat/MetaCatServlet.java
  
  Index: MetaCatServlet.java
  ===================================================================
  RCS file: /cvs/metacat/src/edu/ucsb/nceas/metacat/MetaCatServlet.java,v
  retrieving revision 1.235
  retrieving revision 1.236
  diff -u -r1.235 -r1.236
  --- MetaCatServlet.java	16 Nov 2005 20:38:41 -0000	1.235
  +++ MetaCatServlet.java	17 Nov 2005 01:27:26 -0000	1.236
  @@ -6,9 +6,9 @@
    *    Authors: Matt Jones, Dan Higgins, Jivka Bojilova, Chad Berkley
    *    Release: @release@
    *
  - *   '$Author: tao $'
  - *     '$Date: 2005/11/16 20:38:41 $'
  - * '$Revision: 1.235 $'
  + *   '$Author: jones $'
  + *     '$Date: 2005/11/17 01:27:26 $'
  + * '$Revision: 1.236 $'
    *
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
  @@ -44,11 +44,10 @@
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Iterator;
  -import java.util.PropertyResourceBundle;
  +import java.util.Timer;
   import java.util.Vector;
   import java.util.zip.ZipEntry;
   import java.util.zip.ZipOutputStream;
  -import java.util.Timer;
   
   import javax.servlet.ServletConfig;
   import javax.servlet.ServletContext;
  @@ -59,6 +58,8 @@
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.http.HttpSession;
   
  +import org.apache.log4j.Logger;
  +import org.apache.log4j.PropertyConfigurator;
   import org.ecoinformatics.eml.EMLParser;
   
   import com.oreilly.servlet.multipart.FilePart;
  @@ -66,9 +67,6 @@
   import com.oreilly.servlet.multipart.ParamPart;
   import com.oreilly.servlet.multipart.Part;
   
  -import org.apache.log4j.Logger;
  -import org.apache.log4j.PropertyConfigurator;
  -
   import edu.ucsb.nceas.utilities.Options;
   
   /**
  @@ -117,60 +115,23 @@
    */
   public class MetaCatServlet extends HttpServlet
   {
  -
  -    private ServletConfig config = null;
  -
  -    private ServletContext context = null;
  -
  -    private String resultStyleURL = null;
  -
  -    private String xmlcatalogfile = null;
  -
  -    private String saxparser = null;
  -
  -    private String datafilepath = null;
  -
  -    private File dataDirectory = null;
  -
  -    private String servletpath = null;
  -
  -    private String htmlpath = null;
  -
  -    private PropertyResourceBundle options = null;
  -
  -    private MetaCatUtil util = null;
  -
  -    private DBConnectionPool connPool = null;
  -
       private static Hashtable sessionHash = new Hashtable();
  -
  +    private static Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
  +    private Timer timer = null;
  +    
  +    // Constants -- these should be final in a servlet
       private static final String PROLOG = "<?xml version=\"1.0\"?>";
  -
       private static final String SUCCESS = "<success>";
  -
       private static final String SUCCESSCLOSE = "</success>";
  -
       private static final String ERROR = "<error>";
  -
       private static final String ERRORCLOSE = "</error>";
  -
       public static final String SCHEMALOCATIONKEYWORD = ":schemaLocation";
  -
       public static final String NONAMESPACELOCATION = ":noNamespaceSchemaLocation";
  -
       public static final String NAMESPACEKEYWORD = "xmlns";
  -
       public static final String EML2KEYWORD = ":eml";
  -
       public static final String XMLFORMAT = "xml";
  -
       private static final String CONFIG_DIR = "WEB-INF";
  -
  -    private static final String CONFIG_NAME = "metacat.properties";
  -     	 
  -    private static Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
  -       
  -    private Timer timer = null;
  +    private static final String CONFIG_NAME = "metacat.properties"; 
       
       /**
        * Initialize the servlet by creating appropriate database connections
  @@ -179,8 +140,7 @@
       {
           try {
               super.init(config);
  -            this.config = config;
  -            this.context = config.getServletContext();
  +            ServletContext context = config.getServletContext();
   
               // Initialize the properties file for our options
               String dirPath = context.getRealPath(CONFIG_DIR);
  @@ -199,20 +159,11 @@
                           + ioe.getMessage());
               }
   
  -            util = new MetaCatUtil();
  -
  -            //initial DBConnection pool
  -            connPool = DBConnectionPool.getInstance();
  -
  -            // Get the configuration file information
  -            resultStyleURL = MetaCatUtil.getOption("resultStyleURL");
  -            xmlcatalogfile = MetaCatUtil.getOption("xmlcatalogfile");
  -            saxparser = MetaCatUtil.getOption("saxparser");
  -            datafilepath = MetaCatUtil.getOption("datafilepath");
  -            dataDirectory = new File(datafilepath);
  -            servletpath = MetaCatUtil.getOption("servletpath");
  -            htmlpath = MetaCatUtil.getOption("htmlpath");
  +            MetaCatUtil util = new MetaCatUtil();
   
  +            //initialize DBConnection pool
  +            DBConnectionPool connPool = DBConnectionPool.getInstance();
  +            
               // Index the paths specified in the metacat.properties
               checkIndexPaths();
   
  @@ -403,10 +354,8 @@
       private void handleGetOrPost(HttpServletRequest request,
               HttpServletResponse response) throws ServletException, IOException
       {
  -
  -        if (util == null) {
  -            util = new MetaCatUtil();
  -        }
  +        MetaCatUtil util = new MetaCatUtil();
  +       
           /*
            * logMetacat.info("Connection pool size: "
            * +connPool.getSizeOfDBConnectionPool(),10);
  @@ -418,7 +367,14 @@
           DBConnectionPool.shrinkDBConnectionPoolSize();
   
           //Debug message to print out the method which have a busy DBConnection
  -        connPool.printMethodNameHavingBusyDBConnection();
  +        try {
  +            DBConnectionPool pool = DBConnectionPool.getInstance();
  +            pool.printMethodNameHavingBusyDBConnection();
  +        } catch (SQLException e) {
  +            logMetacat.error("Error in MetacatServlet.handleGetOrPost: "
  +                    + e.getMessage());
  +            e.printStackTrace();
  +        }
   
           String ctype = request.getContentType();
           if (ctype != null && ctype.startsWith("multipart/form-data")) {
  @@ -893,7 +849,7 @@
               String sessionid)
       {
           double startTime = System.currentTimeMillis() / 1000;
  -        DBQuery queryobj = new DBQuery(saxparser);
  +        DBQuery queryobj = new DBQuery();
           queryobj.findDocuments(response, out, params, user, groups, sessionid);
           double outPutTime = System.currentTimeMillis() / 1000;
           logMetacat.warn("Total search time for action 'squery': "
  @@ -919,7 +875,7 @@
           queryArray[0] = xmlquery;
           params.put("query", queryArray);
           double startTime = System.currentTimeMillis() / 1000;
  -        DBQuery queryobj = new DBQuery(saxparser);
  +        DBQuery queryobj = new DBQuery();
           queryobj.findDocuments(response, out, params, user, groups, sessionid);
           double outPutTime = System.currentTimeMillis() / 1000;
           logMetacat.warn("Total search time for action 'query': "
  @@ -958,7 +914,7 @@
                   docs = (String[]) params.get("docid");
               }
               // Create a DBuery to handle export
  -            queryObj = new DBQuery(saxparser);
  +            queryObj = new DBQuery();
               // Get the docid
               docId = docs[0];
               // Make sure the client specify docid
  @@ -2143,7 +2099,7 @@
               dbConn = DBConnectionPool
                       .getDBConnection("MetaCatServlet.handleValidateAction");
               serialNumber = dbConn.getCheckOutSerialNumber();
  -            DBValidate valobj = new DBValidate(saxparser, dbConn);
  +            DBValidate valobj = new DBValidate(dbConn);
               boolean valid = valobj.validateString(valtext);
   
               // set content type and other response header fields first
  @@ -2648,6 +2604,8 @@
                       //If document get lock data file grant
                       if (DocumentImpl.getDataFileLockGrant(docid)) {
                           // Save the data file to disk using "docid" as the name
  +                        String datafilepath = MetaCatUtil.getOption("datafilepath");
  +                        File dataDirectory = new File(datafilepath);
                           dataDirectory.mkdirs();
                           File newFile = null;
                           long size = 0;
  
  
  
  1.116     +6 -6      metacat/src/edu/ucsb/nceas/metacat/DBQuery.java
  
  Index: DBQuery.java
  ===================================================================
  RCS file: /cvs/metacat/src/edu/ucsb/nceas/metacat/DBQuery.java,v
  retrieving revision 1.115
  retrieving revision 1.116
  diff -u -r1.115 -r1.116
  --- DBQuery.java	20 Oct 2005 18:34:02 -0000	1.115
  +++ DBQuery.java	17 Nov 2005 01:27:26 -0000	1.116
  @@ -10,9 +10,9 @@
    *    Authors: Matt Jones
    *    Release: @release@
    *
  - *   '$Author: sgarg $'
  - *     '$Date: 2005/10/20 18:34:02 $'
  - * '$Revision: 1.115 $'
  + *   '$Author: jones $'
  + *     '$Date: 2005/11/17 01:27:26 $'
  + * '$Revision: 1.116 $'
    *
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
  @@ -121,8 +121,7 @@
                   double connTime = System.currentTimeMillis();
   
                   // Execute the query
  -                DBQuery queryobj = new DBQuery(MetaCatUtil
  -                        .getOption("saxparser"));
  +                DBQuery queryobj = new DBQuery();
                   FileReader xml = new FileReader(new File(xmlfile));
                   Hashtable nodelist = null;
                   //nodelist = queryobj.findDocuments(xml, null, null, useXMLIndex);
  @@ -189,9 +188,10 @@
        * @param parserName the fully qualified name of a Java class implementing
        *            the org.xml.sax.XMLReader interface
        */
  -    public DBQuery(String parserName)
  +    public DBQuery()
       {
  -       this.parserName = parserName;
  +        String parserName = MetaCatUtil.getOption("saxparser");
  +        this.parserName = parserName;
       }
   
   
  
  
  
  1.14      +9 -8      metacat/src/edu/ucsb/nceas/metacat/DBValidate.java
  
  Index: DBValidate.java
  ===================================================================
  RCS file: /cvs/metacat/src/edu/ucsb/nceas/metacat/DBValidate.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DBValidate.java	19 Dec 2002 18:34:06 -0000	1.13
  +++ DBValidate.java	17 Nov 2005 01:27:26 -0000	1.14
  @@ -9,9 +9,9 @@
    *    Authors: Dan Higgins, Matt Jones
    *    Release: @release@
    * 
  - *   '$Author: tao $'
  - *     '$Date: 2002/12/19 18:34:06 $'
  - * '$Revision: 1.13 $'
  + *   '$Author: jones $'
  + *     '$Date: 2005/11/17 01:27:26 $'
  + * '$Revision: 1.14 $'
    *
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
  @@ -67,10 +67,11 @@
     public boolean alreadyHandle = false;
       
     /** Construct a new validation object */
  -  public DBValidate(String parserName) {
  +  public DBValidate() {
       alreadyHandle = false;
       try {
         // Get an instance of the parser
  +      String parserName = MetaCatUtil.getOption("saxparser");
         parser = XMLReaderFactory.createXMLReader(parserName);
         parser.setFeature("http://xml.org/sax/features/validation",true);
         //parser.setValidationMode(true);     // Oracle
  @@ -80,8 +81,8 @@
     }
       
     /** Construct a new validation object using an OASIS catalog file */
  -  public DBValidate(String parserName, String xmlcatalogfile)  {
  -    this(parserName);
  +  public DBValidate(String xmlcatalogfile)  {
  +    this();
   
       CatalogEntityResolver cer = new CatalogEntityResolver();
       try {
  @@ -97,8 +98,8 @@
     }
   
     /** Construct a new validation object using a database entity resolver */
  -  public DBValidate(String parserName, DBConnection conn) {
  -    this(parserName);
  +  public DBValidate(DBConnection conn) {
  +    this();
   
       DBEntityResolver dbresolver = new DBEntityResolver(conn);
       parser.setEntityResolver(dbresolver);
  @@ -234,7 +235,7 @@
         conn = DBConnectionPool.getDBConnection("DBValidate.main");
         serailNumber = conn.getCheckOutSerialNumber();
     
  -      DBValidate gxv = new DBValidate(util.getOption("saxparser"), conn);
  +      DBValidate gxv = new DBValidate(conn);
         if (gxv.validate(doc)) {
           System.out.print(gxv.returnErrors());
         } else {
  
  
  


More information about the Metacat-cvs mailing list