vgritsenko    2003/12/14 10:20:58

  Modified:    java/src/org/apache/xindice/server XindiceServlet.java
  Log:
  Close couple of TODOs in servlet
  
  Revision  Changes    Path
  1.25      +19 -23    
xml-xindice/java/src/org/apache/xindice/server/XindiceServlet.java
  
  Index: XindiceServlet.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/server/XindiceServlet.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- XindiceServlet.java       13 Dec 2003 00:24:14 -0000      1.24
  +++ XindiceServlet.java       14 Dec 2003 18:20:58 -0000      1.25
  @@ -101,17 +101,17 @@
   
       public void destroy() {
           try {
  -            // When the servlet engine goes down we need to close the
  -            // database instance.
  -            // TODO: make sure we're handling threads properly in this case.
  -            if (database != null) {
  -                database.close();
  +            // When the servlet engine goes down we need to close the 
database instance.
  +            // By the time destroy() is called, no more client requests can 
come in,
  +            // so no need to worry about multithreading.
  +            if (this.database != null) {
  +                this.database.close();
  +                log.info("Database successfully closed");
               }
  -
  -            log.info("Database successfully closed");
           } catch (Exception e) {
  -            log.error("Error in destroy", e);
  +            log.error("Error closing database", e);
           }
  +        this.database = null;
       }
   
       /**
  @@ -135,8 +135,7 @@
       }
   
       /**
  -     * TODO: verify that if is an error occured, the database will be closed
  -     * propertly
  +     * Initializes database
        */
       public void init(ServletConfig servletConfig) throws ServletException {
   
  @@ -168,8 +167,8 @@
                   //
                   if (!new File(dbRoot).isAbsolute()) {
   
  -                    // Stupid hack but spec compliant.
  -                    //        If getRealPath() returns null the war archive 
has not been unpacked.
  +                    // Stupid hack but spec compliant:
  +                    // If getRealPath() returns null the war archive has not 
been unpacked.
                       String realPath = 
servletConfig.getServletContext().getRealPath("/WEB-INF");
   
                       // Let's see if the property was specified.
  @@ -197,7 +196,7 @@
   
                   //
                   // We need to use this method to be consistent between 
deployments (embed, standalone, etc)
  -                //     and let the Database object maintain the set of 
Databases.
  +                // and let the Database object maintain the set of Databases.
                   //
                   this.database = 
Database.getDatabase(rootCollectionConfiguration);
               }
  @@ -244,15 +243,10 @@
               }
   
               log.info("Database successfully started");
  -        } catch (RuntimeException e) {
  -            if (log.isFatalEnabled()) {
  -                log.fatal("ignored exception", e);
  -            }
  -            throw new ServletException("Error while handling the 
configuration", e);
           } catch (Exception e) {
  -            if (log.isFatalEnabled()) {
  -                log.fatal("ignored exception", e);
  -            }
  +            log.fatal("Failed to initialize database, throwing 
ServletException", e);
  +            // Make sure to close database if it was opened already.
  +            destroy();
               throw new ServletException("Error while handling the 
configuration", e);
           }
       }
  @@ -264,6 +258,8 @@
        * configuration file</li>
        * <li>use the default configuration stored in the <tt>Xindice</tt> 
class</li>
        * </ul>
  +     *
  +     * <br/>
        * TODO: we should probably try to load from the file system if we can't 
load it this way.
        */
       public Configuration loadConfiguration(ServletConfig servletConfig) {
  
  
  

Reply via email to