tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hari...@hyperreal.org
Subject cvs commit: jakarta-tomcat/src/shell ant tomcat.sh
Date Sun, 28 Nov 1999 23:52:33 GMT
harishp     99/11/28 15:52:33

  Modified:    .        build.sh
               src/share/org/apache/tomcat/core ServletClassLoader.java
               src/share/org/apache/tomcat/util NetworkClassLoader.java
               src/shell ant tomcat.sh
  Added:       src/share/org/apache/tomcat/util URLResourceReader.java
  Log:
  1. Changed -start/-stop options of tomcat.sh to start/stop.
  2. Modified a few scripts that take command line arguments to use $@
     instead of $*. ($* messes if commandline arg has " ")
  3. Enhanced the performance of NetworkClassLoader.
  
  Revision  Changes    Path
  1.3       +2 -2      jakarta-tomcat/build.sh
  
  Index: build.sh
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/build.sh,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- build.sh	1999/11/25 20:42:10	1.2
  +++ build.sh	1999/11/28 23:52:29	1.3
  @@ -1,9 +1,9 @@
   #! /bin/sh
   
  -# $Id: build.sh,v 1.2 1999/11/25 20:42:10 harishp Exp $
  +# $Id: build.sh,v 1.3 1999/11/28 23:52:29 harishp Exp $
   
   cp=../jakarta-tools/ant.jar:../jakarta-tools/projectx-tr2.jar:../build/tomcat/classes
   
  -java -classpath $cp:$CLASSPATH org.apache.tools.ant.Main $*
  +java -classpath $cp:$CLASSPATH org.apache.tools.ant.Main "$@"
   
   chmod +x `find ../build -name "*.sh"`
  
  
  
  1.2       +6 -7      jakarta-tomcat/src/share/org/apache/tomcat/core/ServletClassLoader.java
  
  Index: ServletClassLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletClassLoader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletClassLoader.java	1999/11/26 09:03:43	1.1
  +++ ServletClassLoader.java	1999/11/28 23:52:30	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletClassLoader.java,v
1.1 1999/11/26 09:03:43 harishp Exp $
  - * $Revision: 1.1 $
  - * $Date: 1999/11/26 09:03:43 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletClassLoader.java,v
1.2 1999/11/28 23:52:30 harishp Exp $
  + * $Revision: 1.2 $
  + * $Date: 1999/11/28 23:52:30 $
    *
    * ====================================================================
    *
  @@ -151,13 +151,12 @@
       }
   
       String getClassPath() {
  -        URL[] urls = getURLs();
           String separator = System.getProperty("path.separator", ":");
  -
           String cpath = "";
   
  -        for(int i=0; i < urls.length; ++i) {
  -            cpath = cpath + separator + urls[i].getFile();
  +        for(Enumeration e = getURLs(); e.hasMoreElements(); ) {
  +            URL url = (URL) e.nextElement();
  +            cpath = cpath + separator + url.getFile();
           }
   
           return cpath;
  
  
  
  1.4       +40 -60    jakarta-tomcat/src/share/org/apache/tomcat/util/NetworkClassLoader.java
  
  Index: NetworkClassLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/NetworkClassLoader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NetworkClassLoader.java	1999/11/27 21:45:35	1.3
  +++ NetworkClassLoader.java	1999/11/28 23:52:31	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/NetworkClassLoader.java,v
1.3 1999/11/27 21:45:35 harishp Exp $
  - * $Revision: 1.3 $
  - * $Date: 1999/11/27 21:45:35 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/NetworkClassLoader.java,v
1.4 1999/11/28 23:52:31 harishp Exp $
  + * $Revision: 1.4 $
  + * $Date: 1999/11/28 23:52:31 $
    *
    * ====================================================================
    *
  @@ -81,14 +81,18 @@
    * still open. IMHO, it does make sense to close the jar file
    * after you are done reading the class data. But this approach may not
    * get you the performance of the URLClassLoader, but it works in all
  - * cases and also runs on JDK1.1
  + * cases and also runs on JDK1.1. I have enhanced this class loader
  + * to read all the zip/jar entries once & cache the data, so that
  + * there is no overhead of opening/closing jar file to pick up
  + * each entry.
    *
  + *
    * @author Harish Prabandham
    */
   public class NetworkClassLoader extends ClassLoader {
       private ClassLoader parent = null; // parent classloader
       private Hashtable classCache = new Hashtable();
  -    private Vector urlset = new Vector();
  +    private Hashtable urlset = new Hashtable();
   
       /**
        * Creates a new instance of the class loader.
  @@ -109,65 +113,53 @@
       /**
        * Adds the given URL to this class loader. If the URL
        * ends with "/", then it is assumed to be a directory
  -     * otherwise, it is assumed to be a zip/jar file.
  +     * otherwise, it is assumed to be a zip/jar file. If the
  +     * same URL is added again, the URL is re-opened and this
  +     * zip/jar file is used for serving any future class requests.
        * @param URL where to look for the classes.
        */
  -    public void addURL(URL url) {
  +    public synchronized void addURL(URL url) {
           // System.out.println("Adding url: " + url);
  -        if(!urlset.contains(url)) {
  -            urlset.addElement(url);
  +        if(!urlset.containsKey(url)) {
  +            try {
  +                urlset.put(url, new URLResourceReader(url));
  +            }catch(IOException ioe){
  +                // Probably a bad url...
  +            }
  +        } else {
  +            // remove the old one & add a new one...
  +            try{
  +                URLResourceReader newu = new URLResourceReader(url);
  +                URLResourceReader oldu = (URLResourceReader) urlset.get(url);
  +                oldu.close();
  +                urlset.remove(url);
  +                urlset.put(url, newu);
  +            } catch (IOException ioe) {
  +            }
           }
       }
   
       /**
  -     * @return The URLs where this class loader looks for classes.
  +     * @return An enumeration of  URLs where this class loader
  +     * looks for classes.
        */
  -    public URL[] getURLs() {
  -        URL[] urls = new URL[urlset.size()];
  -        urlset.copyInto(urls);
  -        return urls;
  +    public Enumeration getURLs() {
  +        return urlset.keys();
       }
   
       private byte[] loadResource(URL url, String resourceName)
  -        throws MalformedURLException, IOException {
  -        byte[] bytes = null;
  -
  -        if(url.getFile().endsWith("/")) {
  -            // It is a directory 
  -            URL realURL = new URL(url.getProtocol(), url.getHost(),
  -                                  url.getFile() + resourceName);
  -
  -            InputStream istream = realURL.openStream();
  -            bytes = getBytes(istream);
  -            try{istream.close();}catch(Exception e){}
  -            
  -        } else {
  -            // It is a zip/jar file.
  -            InputStream istream = url.openStream();
  -            ZipInputStream zstream = new ZipInputStream(istream);
  -            ZipEntry entry = null;
  -
  -            while( (entry = zstream.getNextEntry()) != null) {
  -                System.out.println("Entry=" + entry.getName());
  -                if(!entry.isDirectory() &&
  -                   entry.getName().equals(resourceName)) {
  -                    bytes = getBytes(zstream);
  -                    zstream.close();
  -                    break;
  -                }
  -
  -                zstream.closeEntry();
  -            }
  -
  -            try{istream.close();}catch(Exception e){}
  +        throws IOException {
  +        URLResourceReader urr = (URLResourceReader) urlset.get(url);
  +        if(urr != null) {
  +            return urr.getResource(resourceName);
           }
   
  -        return bytes;
  +        return null;
       }
   
       private byte[] loadResource(String resource) {
           byte[] barray = null;
  -        for(Enumeration e = urlset.elements(); e.hasMoreElements();) {
  +        for(Enumeration e = urlset.keys(); e.hasMoreElements();) {
               URL url = (URL) e.nextElement();
   
               try {
  @@ -182,18 +174,6 @@
           return barray;
       }
   
  -    private byte[] getBytes(InputStream istream) throws IOException {
  -        byte[] buf = new byte[1024];
  -        int num = 0;
  -        ByteArrayOutputStream bout = new ByteArrayOutputStream();
  -
  -        while( (num = istream.read(buf)) != -1) {
  -            bout.write(buf, 0, num);
  -        }
  -
  -        return bout.toByteArray();
  -    }
  -
       private byte[] loadClassData(String classname) {
           String resourceName = classname.replace('.', '/') + ".class";
           return loadResource(resourceName);
  @@ -307,7 +287,7 @@
        * removes all the URLs and classes in this class loader cache. 
        */
       protected final void clear() {
  -        urlset.removeAllElements();
  +        urlset.clear();
           classCache.clear();
       }
   
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/util/URLResourceReader.java
  
  Index: URLResourceReader.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/URLResourceReader.java,v
1.1 1999/11/28 23:52:31 harishp Exp $
   * $Revision: 1.1 $
   * $Date: 1999/11/28 23:52:31 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.tomcat.util;
  
  import java.util.zip.*;
  import java.net.*;
  import java.util.*;
  import java.io.*;
  
  public class URLResourceReader  {
      private Hashtable resourceCache = new Hashtable();
      private boolean iszip = true;
      private URL url = null;
  
      /**
       * Creates a new URLResourceReader object. You can either give
       * the URL of the zip/jar file or a base url where to
       * look for additional resources. If the url ends with
       * "/" then it is assumed to be  a Base URL. 
       *
       */
      public URLResourceReader(URL url) throws IOException {
          this.url = url;
          this.iszip = !url.getFile().endsWith("/"); 
          initialize();
      }
  
      /**
       * Creates a new URLResourceReader object with the given
       * input stream. The stream is assumed to be a zip/jar
       * stream.
       */
      public URLResourceReader(InputStream is) throws IOException {
          init(is);
      }
  
      private void initialize() throws IOException {
          if(iszip) {
              InputStream is = url.openStream();
              init(is);
              is.close();
          }
      }
  
      private byte[] readFully(InputStream is) throws IOException {
          byte[] buf = new byte[1024];
          int num = 0;
          ByteArrayOutputStream bout = new ByteArrayOutputStream();
  
          while( (num = is.read(buf)) != -1) {
              bout.write(buf, 0, num);
          }
  
          return bout.toByteArray();
      }
  
      private void init(InputStream is) throws IOException {
          ZipInputStream zstream = new ZipInputStream(is);
          ZipEntry entry;
          
          while( (entry = zstream.getNextEntry()) != null) {
              byte[] entryData = readFully(zstream);
              resourceCache.put(entry.getName(), entryData);
              zstream.closeEntry();
          }
          
          zstream.close();
      }
  
      /**
       * Returns an Enumeration of all "known" resource names.
       */
      public Enumeration getResourceNames() {
          return resourceCache.keys();
      }
  
      /**
       * Returns an array of bytes read for this resource if the
       * resource exists. This method blocks until the resource
       * has been fully read. If the resource does not exist,
       * this method returns null.
       */
      public byte[] getResource(String  resource) {
          // lookup the data in the cache...
          byte[] data = (byte[]) resourceCache.get(resource);
          if(data != null) {
              return data;
          }
  
          // if the data was to come from a zip file that we
          // already read fully, then it is probably not there.
          if(iszip) {
              return null;
          }
  
          // Now the only choice left is to make a url connection.
          try {
              URL realURL = new URL(url.getProtocol(), url.getHost(),
                                    url.getFile() + resource);
              data = readFully(realURL.openStream());
              // add it to cache..
              resourceCache.put(resource, data);
              return data;
          } catch(Exception e) {
              return null;
          }
      }
  
      public void close() {
          resourceCache.clear();
          resourceCache = null;
      }
  
      public static void main(String[] args) {
          try {
              URL url = new URL("http://www.professionals.com/~harish/xml.jar");
              URLResourceReader urdr = new URLResourceReader(url);
  
              for(Enumeration e=urdr.getResourceNames(); e.hasMoreElements();) {
                  System.out.println(e.nextElement());
              }
              System.out.println("length=" + urdr.getResource("Main.class"));
          } catch(Exception e) {
              e.printStackTrace();
          }
      }
  }
  
  
  
  
  
  
  
  
  
  
  
  1.2       +1 -1      jakarta-tomcat/src/shell/ant
  
  Index: ant
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/shell/ant,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ant	1999/11/12 23:24:33	1.1
  +++ ant	1999/11/28 23:52:32	1.2
  @@ -6,4 +6,4 @@
   
   CLASSPATH=$CLASSPATH:${TOOLS_HOME}/ant.jar:${TOOLS_HOME}/projectx-tr2.jar
   
  -java org.apache.tools.ant.Main $*
  +java org.apache.tools.ant.Main "$@"
  
  
  
  1.2       +7 -7      jakarta-tomcat/src/shell/tomcat.sh
  
  Index: tomcat.sh
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/shell/tomcat.sh,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- tomcat.sh	1999/11/25 20:42:21	1.1
  +++ tomcat.sh	1999/11/28 23:52:32	1.2
  @@ -1,6 +1,6 @@
   #!/bin/sh
   #
  -# $Id: tomcat.sh,v 1.1 1999/11/25 20:42:21 harishp Exp $
  +# $Id: tomcat.sh,v 1.2 1999/11/28 23:52:32 harishp Exp $
   
   # Shell script to start and stop the server
   
  @@ -42,21 +42,21 @@
   
   # We start the server up in the background for a couple of reasons:
   #   1) It frees up your command window
  -#   2) You should use `-stop` option instead of ^C to bring down the server
  +#   2) You should use `stop` option instead of ^C to bring down the server
   
  -if test "$1" = "-start" 
  +if test "$1" = "start" 
   then 
   shift 
   echo Using classpath: ${CLASSPATH}
  -java org.apache.tomcat.shell.Startup $* &
  -elif test "$1" = "-stop"
  +java org.apache.tomcat.shell.Startup "$@" &
  +elif test "$1" = "stop"
   then 
   shift 
   echo Using classpath: ${CLASSPATH}
  -java org.apache.tomcat.shell.Shutdown $*
  +java org.apache.tomcat.shell.Shutdown "$@"
   else
   echo "Usage:"
  -echo "tomcat [-start|-stop]"
  +echo "tomcat [start|stop]"
   exit 0
   fi
   
  
  
  

Mime
View raw message