tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/loader WebappLoader.java
Date Thu, 22 Aug 2002 17:02:12 GMT
costin      2002/08/22 10:02:12

  Modified:    catalina/src/share/org/apache/catalina/loader
                        WebappLoader.java
  Log:
  Switch to commons-logging.
  
  While looking at the code, it seems one thread per webapp is used to
  find updates - that doesn't scale very well. A single thread should
  be used for all webapps.
  
  Also looking at the code, the MANIFEST stuff is interesting but it
  would be nice to make it more generic. I'm planning to try to merge
  some of this code into discovery, and allow more flexibility in
  finding jars and resolving dependencies. The code would be perfect
  for ant and other projects.
  
  I added a bit of code to support the case when the parent loader
  is not a URLClassLoader - i.e. if we start from ant. Any classloader
  that has a getClassPath method can be used. Now compiling jsps when
  started from ant should work/
  
  Revision  Changes    Path
  1.2       +68 -33    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/loader/WebappLoader.java
  
  Index: WebappLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/loader/WebappLoader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WebappLoader.java	18 Jul 2002 16:48:03 -0000	1.1
  +++ WebappLoader.java	22 Aug 2002 17:02:12 -0000	1.2
  @@ -75,6 +75,7 @@
   import java.io.FilePermission;
   import java.io.OutputStream;
   import java.lang.reflect.Constructor;
  +import java.lang.reflect.Method;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.net.URLClassLoader;
  @@ -146,11 +147,8 @@
        * @param parent The parent class loader
        */
       public WebappLoader(ClassLoader parent) {
  -
  -
           super();
           this.parentClassLoader = parent;
  -
       }
   
   
  @@ -483,8 +481,8 @@
        */
       public void addRepository(String repository) {
   
  -        if (debug >= 1)
  -            log(sm.getString("webappLoader.addRepository", repository));
  +        if (log.isDebugEnabled())
  +            log.debug(sm.getString("webappLoader.addRepository", repository));
   
           for (int i = 0; i < repositories.length; i++) {
               if (repository.equals(repositories[i]))
  @@ -601,8 +599,8 @@
           if (started)
               throw new LifecycleException
                   (sm.getString("webappLoader.alreadyStarted"));
  -        if (debug >= 1)
  -            log(sm.getString("webappLoader.starting"));
  +        if (log.isDebugEnabled())
  +            log.debug(sm.getString("webappLoader.starting"));
           lifecycle.fireLifecycleEvent(START_EVENT, null);
           started = true;
   
  @@ -644,6 +642,7 @@
                   ((ClassLoader) classLoader, this.container.getResources());
   
           } catch (Throwable t) {
  +            log.error( "LifecycleException ", t );
               throw new LifecycleException("start: ", t);
           }
   
  @@ -652,7 +651,7 @@
   
           // Start our background thread if we are reloadable
           if (reloadable) {
  -            log(sm.getString("webappLoader.reloading"));
  +            log.info(sm.getString("webappLoader.reloading"));
               try {
                   threadStart();
               } catch (IllegalStateException e) {
  @@ -674,8 +673,8 @@
           if (!started)
               throw new LifecycleException
                   (sm.getString("webappLoader.notStarted"));
  -        if (debug >= 1)
  -            log(sm.getString("webappLoader.stopping"));
  +        if (log.isDebugEnabled())
  +            log.debug(sm.getString("webappLoader.stopping"));
           lifecycle.fireLifecycleEvent(STOP_EVENT, null);
           started = false;
   
  @@ -720,7 +719,7 @@
                   setReloadable
                       ( ((Boolean) event.getNewValue()).booleanValue() );
               } catch (NumberFormatException e) {
  -                log(sm.getString("webappLoader.reloadable",
  +                log.error(sm.getString("webappLoader.reloadable",
                                    event.getNewValue().toString()));
               }
           }
  @@ -743,6 +742,7 @@
           if (parentClassLoader == null) {
               // Will cause a ClassCast is the class does not extend WCL, but
               // this is on purpose (the exception will be caught and rethrown)
  +            log.info( "Creating loader with no parent ");
               classLoader = (WebappClassLoader) clazz.newInstance();
           } else {
               Class[] argTypes = { ClassLoader.class };
  @@ -941,7 +941,8 @@
           if (workDir == null)
               return;
   
  -        log(sm.getString("webappLoader.deploy", workDir.getAbsolutePath()));
  +        if( log.isDebugEnabled()) 
  +            log.debug(sm.getString("webappLoader.deploy", workDir.getAbsolutePath()));
   
           DirContext resources = container.getResources();
   
  @@ -979,7 +980,8 @@
   
               }
   
  -            log(sm.getString("webappLoader.classDeploy", classesPath,
  +            if(log.isDebugEnabled())
  +                log.debug(sm.getString("webappLoader.classDeploy", classesPath,
                                classRepository.getAbsolutePath()));
   
   
  @@ -1035,7 +1037,8 @@
                       // impossible to update it or remove it at runtime)
                       File destFile = new File(destDir, binding.getName());
   
  -                    log(sm.getString("webappLoader.jarDeploy", filename,
  +                    if( log.isDebugEnabled())
  +                    log.debug(sm.getString("webappLoader.jarDeploy", filename,
                                        destFile.getAbsolutePath()));
   
                       Resource jarResource = (Resource) binding.getObject();
  @@ -1082,8 +1085,20 @@
           int layers = 0;
           int n = 0;
           while ((layers < 3) && (loader != null)) {
  -            if (!(loader instanceof URLClassLoader))
  +            if (!(loader instanceof URLClassLoader)) {
  +                String cp=getClasspath( loader );
  +                if( cp==null ) {
  +                    log.info( "Unknown loader " + loader + " " + loader.getClass());
  +                    break;
  +                } else {
  +                    if (n > 0) 
  +                        classpath.append(File.pathSeparator);
  +                    classpath.append(cp);
  +                    n++;
  +                }
                   break;
  +                //continue;
  +            }
               URL repositories[] =
                   ((URLClassLoader) loader).getURLs();
               for (int i = 0; i < repositories.length; i++) {
  @@ -1114,6 +1129,24 @@
   
       }
   
  +    // try to extract the classpath from a loader that is not URLClassLoader
  +    private String getClasspath( ClassLoader loader ) {
  +        try {
  +            Method m=loader.getClass().getMethod("getClasspath", new Class[] {});
  +            if( log.isTraceEnabled())
  +                log.trace("getClasspath " + m );
  +            if( m==null ) return null;
  +            Object o=m.invoke( loader, new Object[] {} );
  +            if( log.isDebugEnabled() )
  +                log.debug("gotClasspath " + o);
  +            if( o instanceof String )
  +                return (String)o;
  +            return null;
  +        } catch( Exception ex ) {
  +            log.info("getClasspath ", ex);
  +        }
  +        return null;
  +    }
   
       /**
        * Copy directory.
  @@ -1217,8 +1250,9 @@
                   (sm.getString("webappLoader.notContext"));
   
           // Start the background thread
  -        if (debug >= 1)
  -            log(" Starting background thread");
  +        if (log.isDebugEnabled())
  +            log.debug(" Starting background thread");
  +        // XXX ONE TREAD PER WEBAPP IS _WRONG_ - IT DOESN'T SCALE
           threadDone = false;
           threadName = "WebappLoader[" + container.getName() + "]";
           thread = new Thread(this, threadName);
  @@ -1237,8 +1271,8 @@
           if (thread == null)
               return;
   
  -        if (debug >= 1)
  -            log(" Stopping background thread");
  +        if (log.isDebugEnabled())
  +            log.debug(" Stopping background thread");
           threadDone = true;
           thread.interrupt();
           try {
  @@ -1267,14 +1301,14 @@
                   ((WebappClassLoader) classLoader).findAvailable();
               Extension required[] =
                   ((WebappClassLoader) classLoader).findRequired();
  -            if (debug >= 1)
  -                log("Optional Packages:  available=" +
  +            if (log.isDebugEnabled())
  +                log.debug("Optional Packages:  available=" +
                       available.length + ", required=" +
                       required.length);
   
               for (int i = 0; i < required.length; i++) {
  -                if (debug >= 1)
  -                    log("Checking for required package " + required[i]);
  +                if (log.isDebugEnabled())
  +                    log.debug("Checking for required package " + required[i]);
                   boolean found = false;
                   for (int j = 0; j < available.length; j++) {
                       if (available[j].isCompatibleWith(required[i])) {
  @@ -1300,8 +1334,8 @@
        */
       public void run() {
   
  -        if (debug >= 1)
  -            log("BACKGROUND THREAD Starting");
  +        if (log.isDebugEnabled())
  +            log.debug("BACKGROUND THREAD Starting");
   
           // Loop until the termination semaphore is set
           while (!threadDone) {
  @@ -1317,7 +1351,7 @@
                   if (!classLoader.modified())
                       continue;
               } catch (Exception e) {
  -                log(sm.getString("webappLoader.failModifiedCheck"), e);
  +                log.error(sm.getString("webappLoader.failModifiedCheck"), e);
                   continue;
               }
   
  @@ -1327,8 +1361,8 @@
   
           }
   
  -        if (debug >= 1)
  -            log("BACKGROUND THREAD Stopping");
  +        if (log.isDebugEnabled())
  +            log.debug("BACKGROUND THREAD Stopping");
   
       }
   
  @@ -1355,7 +1389,8 @@
   
       }
   
  -
  +    private static org.apache.commons.logging.Log log=
  +        org.apache.commons.logging.LogFactory.getLog( WebappLoader.class );
   }
   
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message