Tomcat 5 source code --- initialize the container

1, the above article, as well as the completion of loading of server.xml parsing is now mainly done is defined by the right inside the container to initialize the work.

View org.apache.catalina.startup.Catalina # load ()

  1. / / StandarServer begin instantiated
  2. server.initialize ();

By default, the initialization is org.apache.catalina.core.StandardServer # initialize ....

 public void initialize()
        throws LifecycleException
    {
        if (initialized) {
                log.info(sm.getString("standardServer.initialize.initialized"));
            return;
        }
        // The notifications container cycle, here used  Adapter,Observer Mode, the following article on detailed
        lifecycle.fireLifecycleEvent(INIT_EVENT, null);
        // Already initialized
        initialized = true;

        if( oname==null ) {
            try {
                // Use the JMX object management
                oname=new ObjectName( "Catalina:type=Server");
                Registry.getRegistry(null, null)
                    .registerComponent(this, oname, null );
            } catch (Exception e) {
                log.error("Error registering ",e);
            }
        }

        // Register global String cache
        try {
            ObjectName oname2 =
                new ObjectName(oname.getDomain() + ":type=StringCache");
            Registry.getRegistry(null, null)
                .registerComponent(new StringCache(), oname2, null );
        } catch (Exception e) {
            log.error("Error registering ",e);
        }

        // Initialize our defined Services
        // According to the process in server.xml  , After you have finished initializing and then initialize server  StandardService
        for (int i = 0; i < services.length; i++) {
            services[i].initialize();
        }
    }

/ / org.apache.catalina.core.StandardService # initialize () initialize


    /**
     * Invoke a pre-startup initialization. This is used to allow connectors
     * to bind to restricted ports under Unix operating environments.
     */
    public void initialize()
            throws LifecycleException
    {
        // Service shouldn't be used with embeded, so it doesn't matter
        if (initialized) {
            if(log.isInfoEnabled())
                log.info(sm.getString("standardService.initialize.initialized"));
            return;
        }
        initialized = true;

        if( oname==null ) {
            try {
                // Hack - Server should be deprecated...
                Container engine=this.getContainer();
                domain=engine.getName();
                oname=new ObjectName(domain + ":type=Service,serviceName="+name);
                this.controller=oname;
                Registry.getRegistry(null, null)
                    .registerComponent(this, oname, null);

                // To initialize the thread pool, in messaging  , If you have set up in server.xml  , To override the default settings
                Executor[] executors = findExecutors();
                for (int i = 0; i < executors.length; i++) {
                    ObjectName executorObjectName =
                        new ObjectName(domain + ":type=Executor,name=" + executors[i].getName());
                    Registry.getRegistry(null, null)
                        .registerComponent(executors[i], executorObjectName, null);
                }

            } catch (Exception e) {
                log.error(sm.getString("standardService.register.failed",domain),e);
            }

        }
        if( server==null ) {
            // Register with the server
            // HACK: ServerFactory should be removed...

            ServerFactory.getServer().addService(this);
        }

        // Initialize our defined Connectors
        // To the next level of the initialization is two connector    If  8080 8009
        synchronized (connectors) {
                for (int i = 0; i < connectors.length; i++) {
                    connectors[i].initialize();
                }
        }
    }

Now enter the org.apache.catalina.connector # initialize

 /**
     * Initialize this connector (create ServerSocket here!)
     */
    public void initialize()
        throws LifecycleException
    {
        if (initialized) {
            if(log.isInfoEnabled())
                log.info(sm.getString("coyoteConnector.alreadyInitialized"));
           return;
        }

        this.initialized = true;

        if( oname == null && (container instanceof StandardEngine)) {
            try {
                // we are loaded directly, via API - and no name was given to us
                StandardEngine cb=(StandardEngine)container;
                oname = createObjectName(cb.getName(), "Connector");
                Registry.getRegistry(null, null)
                    .registerComponent(this, oname, null);
                controller=oname;
            } catch (Exception e) {
                log.error( "Error registering connector ", e);
            }
            if(log.isDebugEnabled())
                log.debug("Creating name for connector " + oname);
        }

        // Initializa adapter
        // On the Adapter initialization  , The connector settings in
        adapter = new CoyoteAdapter(this);
        // The following object in the constructor has been instantiated, the  adapter Set in
        protocolHandler.setAdapter(adapter);

        IntrospectionUtils.setProperty(protocolHandler, "jkHome",
                                       System.getProperty("catalina.base"));

        try {
            // Continue to the next step in the implementation of the
            protocolHandler.init();
        } catch (Exception e) {
            throw new LifecycleException
                (sm.getString
                 ("coyoteConnector.protocolHandlerInitializationFailed", e));
        }
    }

org.apache.coyote.http11. Http11Protocol (implements ProtocolHandler) # init

 public void init() throws Exception {
        //JIoEndpoint In the global variable has been instantiated, the following to set appropriate values
        endpoint.setName(getName());
        endpoint.setHandler(cHandler);

        // Verify the validity of the configured socket factory
        try {
            if (isSSLEnabled()) {
                sslImplementation =
                    SSLImplementation.getInstance(sslImplementationName);

                socketFactory = sslImplementation.getServerSocketFactory();
                endpoint.setServerSocketFactory(socketFactory);
            } else if (socketFactoryName != null) {
                socketFactory = (ServerSocketFactory) Class.forName(socketFactoryName).newInstance();
                endpoint.setServerSocketFactory(socketFactory);
            }
        } catch (Exception ex) {
            log.error(sm.getString("http11protocol.socketfactory.initerror"),
                      ex);
            throw ex;
        }

        if (socketFactory!=null) {
            Iterator<String> attE = attributes.keySet().iterator();
            while( attE.hasNext() ) {
                String key = attE.next();
                Object v=attributes.get(key);
                socketFactory.setAttribute(key, v);
            }
        }

        try {
            // There is no more than an if statement by executing  , Directly to the  JIoEndpoint
            endpoint.init();
        } catch (Exception ex) {
            log.error(sm.getString("http11protocol.endpoint.initerror"), ex);
            throw ex;
        }
        if (log.isInfoEnabled())
            log.info(sm.getString("http11protocol.init", getName()));

    }

org.apache.tomcat.util.net.JIoEndpoint # init of the Socket class which was set up, for every subsequent communication from the beginning from this class

public void init()
        throws Exception {

        if (initialized)
            return;

        // Initialize thread count defaults for acceptor
        if (acceptorThreadCount == 0) {
            acceptorThreadCount = 1;
        }
        if (serverSocketFactory == null) {
            //serverSocketFacotry The creation of  ( The factory pattern  )
            serverSocketFactory = ServerSocketFactory.getDefault();
        }
        if (serverSocket == null) {
            try {
                if (address == null) {
                    // Create  serverSocket
                    serverSocket = serverSocketFactory.createSocket(port, backlog);
                } else {
                    serverSocket = serverSocketFactory.createSocket(port, backlog, address);
                }
            } catch (BindException be) {
                if (address == null)
                    throw new BindException(be.getMessage() + "<null>:" + port);
                else
                    throw new BindException(be.getMessage() + " " +
                            address.toString() + ":" + port);
            }
        }
        //if( serverTimeout >= 0 )
        //    serverSocket.setSoTimeout( serverTimeout );

        initialized = true;

    }

Here the initialization of tomcat has been basically completed, and then start processing the container accordingly

分类:Java 时间:2010-03-22 人气:192
分享到:
blog comments powered by Disqus

相关文章

  • --- Start the Tomcat source code. Initialized (loaded class package) analysis of three 2010-03-19

    1, start Tomcat is org.apache.catalina.startup.Bootstrap # main () started. Code is as follows: public static void main(String args[]) { if (daemon == null) { daemon = new Bootstrap(); try { daemon.init(); } catch (Throwable t) { t.printStackTrace();

  • Tomcat 5.5.26 source code analysis - start the process (2) 2010-03-25

    init method Catalina_Home and Catalina_Base Initialize the system class loader Tomcat's class loader system initClassLoaders code Two questions Catalina Object load method Catalina class command-line arguments Loading process start Method await state

  • tomcat source code installation and commissioning (1) 2009-07-27

    References: http://tomcat.apache.org/tomcat-6.0-doc/building.html http://blog.csdn.net/huxin1/archive/2008/04/13/2289140.aspx This is installed on a myeclipse8.0, JDK1.5. tomcat source code is to use subversion management, we must first install the s

  • Tomcat source code --- request processing 3 2010-03-25

    1, this section of the main stresses request and response through the piping, valves, inter-operation in various containers 1, connector.getContainer (). GetPipeline (). GetFirst (). Invoke (request, response); This step is StandardEngine to filter a

  • android camera source code analysis (based on application) 2010-10-26

    Here are introduced mainly for Ophone, of course, a combination of android's source code (there are android2.2 the following source code.) Ophone is also first in class by android.hardware.Camera to control the camera equipment, to use only by androi

  • Tomcat6 source code analysis 2011-04-19

    As a Java programmer, if you do not come into contact with open source software, project, or framework, I am afraid some weird. Vigorous open source movement originated in the Linux operating system, Apache Foundation, which played a crucial role, th

  • Hibernate in SchemaExport, SchemaUpdate source code analysis tools 2009-09-18

    package org.hibernate.tool.hbm2ddl; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.i

  • JForum source code analysis notes 2010-02-12

    My development environment: JForum2.1.8 tomcat5.X JDK 1.6X Routines can not be refined in order to start. From the beginning web.xml web.xml includes a filter, a listener, and two servlet, not much content. Wrote Can see that inside there is listener

  • Heritrix source code analysis (m) Heritrix control center (brain) CrawlController (b) 2010-11-04

    Transfer from: http://guoyunsky.javaeye.com/blog/650744 1.Heritrix initialization: /** * Initialization CrawlController * @param sH Profile (order.xml) Object * @throws InitializationException Initialization exception */ public void initialize(Settin

  • Heritrix source code of the processing chain 2010-11-09

    heritrix source really is not an ordinary complex, but little by little to understand or resolve, then the processing chain is heritrix inside one of the most important, the operation of the page to complete through the processing chain, the flexibil

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.585 (s). 12 q(s)