tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r940031 - in /tomcat/trunk/java/org/apache/catalina: core/StandardService.java startup/Catalina.java startup/Embedded.java
Date Sat, 01 May 2010 14:08:47 GMT
Author: markt
Date: Sat May  1 14:08:47 2010
New Revision: 940031

URL: http://svn.apache.org/viewvc?rev=940031&view=rev
Log:
Clean up start code. Catalina no longer implements Service. The model is now: Bootstrap sorts
out the class loaders, Catalina does the remaining plumbing and holds a reference to a Server
object which in turn contains 1 or more services etc. Still need to fix the shutdown hook.

Modified:
    tomcat/trunk/java/org/apache/catalina/core/StandardService.java
    tomcat/trunk/java/org/apache/catalina/startup/Catalina.java
    tomcat/trunk/java/org/apache/catalina/startup/Embedded.java

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardService.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardService.java?rev=940031&r1=940030&r2=940031&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardService.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardService.java Sat May  1 14:08:47 2010
@@ -504,20 +504,16 @@ public class StandardService extends Lif
             }
         }
 
-        if( oname==controller ) {
-            // we registered ourself on init().
-            // That should be the typical case - this object is just for
-            // backward compat, nobody should bother to load it explicitly
-            Registry.getRegistry(null, null).unregisterComponent(oname);
-            Executor[] executors = findExecutors();
-            for (int i = 0; i < executors.length; i++) {
-                try {
-                    ObjectName executorObjectName = 
-                        new ObjectName(domain + ":type=Executor,name=" + executors[i].getName());
-                    Registry.getRegistry(null, null).unregisterComponent(executorObjectName);
-                } catch (Exception e) {
-                    // Ignore (invalid ON, which cannot happen)
-                }
+
+        Registry.getRegistry(null, null).unregisterComponent(oname);
+        Executor[] executors = findExecutors();
+        for (int i = 0; i < executors.length; i++) {
+            try {
+                ObjectName executorObjectName = 
+                    new ObjectName(domain + ":type=Executor,name=" + executors[i].getName());
+                Registry.getRegistry(null, null).unregisterComponent(executorObjectName);
+            } catch (Exception e) {
+                // Ignore (invalid ON, which cannot happen)
             }
         }
     }
@@ -534,15 +530,8 @@ public class StandardService extends Lif
             try {
                 // Hack - Server should be deprecated...
                 Container engine=this.getContainer();
-                
-                if (engine == null) {
-                    // TODO - Get this form elsewhere
-                    domain = "Catalina";
-                } else {
-                    domain = engine.getName();
-                }
-                oname=new ObjectName(domain + ":type=Service,serviceName="+name);
-                this.controller=oname;
+                domain = engine.getName();
+                oname=new ObjectName(domain + ":type=Service");
                 Registry.getRegistry(null, null)
                     .registerComponent(this, oname, null);
                 
@@ -590,7 +579,6 @@ public class StandardService extends Lif
     protected String domain;
     protected String suffix;
     protected ObjectName oname;
-    protected ObjectName controller;
     protected MBeanServer mserver;
 
     public ObjectName getObjectName() {

Modified: tomcat/trunk/java/org/apache/catalina/startup/Catalina.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Catalina.java?rev=940031&r1=940030&r2=940031&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Catalina.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Catalina.java Sat May  1 14:08:47 2010
@@ -33,10 +33,15 @@ import java.util.logging.LogManager;
 import org.apache.catalina.Container;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleState;
+import org.apache.catalina.Server;
 import org.apache.catalina.core.StandardServer;
+import org.apache.catalina.util.LifecycleBase;
 import org.apache.juli.ClassLoaderLogManager;
+import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.digester.Digester;
 import org.apache.tomcat.util.digester.Rule;
+import org.apache.tomcat.util.log.SystemLogHandler;
+import org.apache.tomcat.util.res.StringManager;
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
 
@@ -62,11 +67,22 @@ import org.xml.sax.InputSource;
  * @version $Id$
  */
 
-public class Catalina extends Embedded {
+public class Catalina extends LifecycleBase {
+
+
+    /**
+     * The string manager for this package.
+     */
+    protected static final StringManager sm =
+        StringManager.getManager(Constants.Package);
 
 
     // ----------------------------------------------------- Instance Variables
 
+    /**
+     * Use await.
+     */
+    protected boolean await = false;
 
     /**
      * Pathname to the server configuration file.
@@ -105,6 +121,17 @@ public class Catalina extends Embedded {
     protected Thread shutdownHook = null;
 
 
+    /**
+     * The Server object for this Tomcat instance
+     */
+    protected Server server = null;
+
+    
+    /**
+     * Is naming enabled ?
+     */
+    protected boolean useNaming = true;
+
     // ------------------------------------------------------------- Properties
 
 
@@ -145,41 +172,40 @@ public class Catalina extends Embedded {
     }
 
 
-    // ----------------------------------------------------------- Main Program
+    public void setServer(Server server) {
+        this.server = server;
+    }
+
+
+    public Server getServer() {
+        return server;
+    }
+
 
     /**
-     * The application main program.
-     *
-     * @param args Command line arguments
+     * Return true if naming is enabled.
      */
-    public static void main(String args[]) {
-        (new Catalina()).process(args);
+    public boolean isUseNaming() {
+        return (this.useNaming);
     }
 
 
     /**
-     * The instance main program.
+     * Enables or disables naming support.
      *
-     * @param args Command line arguments
+     * @param useNaming The new use naming value
      */
-    public void process(String args[]) {
+    public void setUseNaming(boolean useNaming) {
+        this.useNaming = useNaming;
+    }
 
-        setAwait(true);
-        initDirs();
-        try {
-            if (arguments(args)) {
-                if (starting) {
-                    load(args);
-                    start();
-                } else if (stopping) {
-                    stopServer();
-                }
-            }
-        } catch (Exception e) {
-            e.printStackTrace(System.out);
-        }
+    public void setAwait(boolean b) {
+        await = b;
     }
 
+    public boolean isAwait() {
+        return await;
+    }
 
     // ------------------------------------------------------ Protected Methods
 
@@ -530,12 +556,9 @@ public class Catalina extends Embedded {
         }
     }
 
-    public void create() {
-
-    }
 
     @Override
-    protected void destroyInternal() {
+    protected void initInternal() {
         // NOOP
     }
 
@@ -557,7 +580,6 @@ public class Catalina extends Embedded {
         long t1 = System.nanoTime();
 
         setState(LifecycleState.STARTING);
-        lifecycle.fireLifecycleEvent(START_EVENT, null);
 
         // Start the new server
         try {
@@ -640,6 +662,11 @@ public class Catalina extends Embedded {
     }
 
 
+    @Override
+    protected void destroyInternal() {
+        // NOOP
+    }
+
     /**
      * Await and shutdown.
      */
@@ -664,6 +691,104 @@ public class Catalina extends Embedded {
     }
 
 
+    protected void initDirs() {
+
+        String catalinaHome = System.getProperty("catalina.home");
+        if (catalinaHome == null) {
+            // Backwards compatibility patch for J2EE RI 1.3
+            String j2eeHome = System.getProperty("com.sun.enterprise.home");
+            if (j2eeHome != null) {
+                catalinaHome=System.getProperty("com.sun.enterprise.home");
+            } else if (System.getProperty("catalina.base") != null) {
+                catalinaHome = System.getProperty("catalina.base");
+            } else {
+                // Use IntrospectionUtils and guess the dir
+                catalinaHome = IntrospectionUtils.guessInstall
+                    ("catalina.home", "catalina.base", "catalina.jar");
+                if (catalinaHome == null) {
+                    catalinaHome = IntrospectionUtils.guessInstall
+                        ("tomcat.install", "catalina.home", "tomcat.jar");
+                }
+            }
+        }
+        // last resort - for minimal/embedded cases. 
+        if(catalinaHome==null) {
+            catalinaHome=System.getProperty("user.dir");
+        }
+        if (catalinaHome != null) {
+            File home = new File(catalinaHome);
+            if (!home.isAbsolute()) {
+                try {
+                    catalinaHome = home.getCanonicalPath();
+                } catch (IOException e) {
+                    catalinaHome = home.getAbsolutePath();
+                }
+            }
+            System.setProperty("catalina.home", catalinaHome);
+        }
+
+        if (System.getProperty("catalina.base") == null) {
+            System.setProperty("catalina.base",
+                               catalinaHome);
+        } else {
+            String catalinaBase = System.getProperty("catalina.base");
+            File base = new File(catalinaBase);
+            if (!base.isAbsolute()) {
+                try {
+                    catalinaBase = base.getCanonicalPath();
+                } catch (IOException e) {
+                    catalinaBase = base.getAbsolutePath();
+                }
+            }
+            System.setProperty("catalina.base", catalinaBase);
+        }
+        
+        String temp = System.getProperty("java.io.tmpdir");
+        if (temp == null || (!(new File(temp)).exists())
+                || (!(new File(temp)).isDirectory())) {
+            log.error(sm.getString("embedded.notmp", temp));
+        }
+
+    }
+
+    
+    protected void initStreams() {
+        // Replace System.out and System.err with a custom PrintStream
+        SystemLogHandler systemlog = new SystemLogHandler(System.out);
+        System.setOut(systemlog);
+        System.setErr(systemlog);
+    }
+
+    
+    protected void initNaming() {
+        // Setting additional variables
+        if (!useNaming) {
+            log.info( "Catalina naming disabled");
+            System.setProperty("catalina.useNaming", "false");
+        } else {
+            System.setProperty("catalina.useNaming", "true");
+            String value = "org.apache.naming";
+            String oldValue =
+                System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);
+            if (oldValue != null) {
+                value = value + ":" + oldValue;
+            }
+            System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value);
+            if( log.isDebugEnabled() )
+                log.debug("Setting naming prefix=" + value);
+            value = System.getProperty
+                (javax.naming.Context.INITIAL_CONTEXT_FACTORY);
+            if (value == null) {
+                System.setProperty
+                    (javax.naming.Context.INITIAL_CONTEXT_FACTORY,
+                     "org.apache.naming.java.javaURLContextFactory");
+            } else {
+                log.debug( "INITIAL_CONTEXT_FACTORY alread set " + value );
+            }
+        }
+    }
+
+    
     // --------------------------------------- CatalinaShutdownHook Inner Class
 
     // XXX Should be moved to embedded !

Modified: tomcat/trunk/java/org/apache/catalina/startup/Embedded.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Embedded.java?rev=940031&r1=940030&r2=940031&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Embedded.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Embedded.java Sat May  1 14:08:47 2010
@@ -101,8 +101,11 @@ import org.apache.tomcat.util.log.System
  *
  * @author Craig R. McClanahan
  * @version $Id$
+ * 
+ * @deprecated Use {@link Tomcat} instead.
  */
 
+@Deprecated
 public class Embedded  extends StandardService {
     private static final Log log = LogFactory.getLog(Embedded.class);
 
@@ -812,7 +815,6 @@ public class Embedded  extends StandardS
         initNaming();
 
         setState(LifecycleState.STARTING);
-        lifecycle.fireLifecycleEvent(START_EVENT, null);
 
         // Start our defined Engines first
         for (int i = 0; i < engines.length; i++) {



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


Mime
View raw message