1. 程式人生 > >Tomcat 系統架構與設計模式,第 1 部分: 工作原理圖 1.Tomcat 的總體結構

Tomcat 系統架構與設計模式,第 1 部分: 工作原理圖 1.Tomcat 的總體結構

public synchronized void start() throwsLifecycleException {

   ………

   if( !initialized ) {

       try {

           init();

       } catch( Exception ex ) {

            throw newLifecycleException("Error initializaing ", ex);

       }

   }

        ………

   lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);

   setAvailable(false);

   setConfigured(false);

   boolean ok = true;

   File configBase = getConfigBase();

   if (configBase != null) {

       if (getConfigFile() == null) {

           File file = new File(configBase, getDefaultConfigFile());

           setConfigFile(file.getPath());

           try {

                File appBaseFile = new File(getAppBase());

                if (!appBaseFile.isAbsolute()){

                    appBaseFile = newFile(engineBase(), getAppBase());

                }

                String appBase =appBaseFile.getCanonicalPath();

                String basePath =

                    (newFile(getBasePath())).getCanonicalPath();

                if(!basePath.startsWith(appBase)) {

                    Server server =ServerFactory.getServer();

                    ((StandardServer)server).storeContext(this);

               }

           } catch (Exception e) {

                log.warn("Error storingconfig file", e);

           }

       } else {

           try {

                String canConfigFile =  (newFile(getConfigFile())).getCanonicalPath();

                if (!canConfigFile.startsWith(configBase.getCanonicalPath())) {

                    File file = newFile(configBase, getDefaultConfigFile());

                    if (copy(newFile(canConfigFile), file)) {

                       setConfigFile(file.getPath());

                    }

                }

           } catch (Exception e) {

                log.warn("Error settingconfig file", e);

           }

       }

   }

   ………

   Container children[] = findChildren();

   for (int i = 0; i < children.length; i++) {

       if (children[i] instanceof Lifecycle)

           ((Lifecycle) children[i]).start();

   }

        if(pipeline instanceof Lifecycle)

       ((Lifecycle) pipeline).start();

   ………

}