[Tomcat6.0源码]组件的初始化
来源:互联网 发布:淘宝运费险是怎么算的 编辑:程序博客网 时间:2024/05/16 04:48
1.Bootstrap.main()做的几件事:
1)daemon.init();创建Catalina对象
2)daemon.load(args);调用Catalina.load();通过解析server.xml对相关组件的实例化和初始化
3)daemon.start();调用Catalina.start()依次启动各组件
前面已经了解Catalina.load()用Digester实例化各组件的过程。接着看看各组件的初始化:
if (getServer() instanceof Lifecycle) { try { getServer().initialize(); } catch (LifecycleException e) { if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE")) throw new java.lang.Error(e); else log.error("Catalina.start", e); } }
2.getServer().initialize();调用StandardServer.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 { if (initialized) { log.info(sm.getString("standardServer.initialize.initialized")); return; } lifecycle.fireLifecycleEvent(INIT_EVENT, null); initialized = true; if( oname==null ) { try { 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 for (int i = 0; i < services.length; i++) { services[i].initialize(); } }
3.循环执行services[i].initialize();即调用与其相关的所有StandardService.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); 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 synchronized (connectors) { for (int i = 0; i < connectors.length; i++) { try { connectors[i].initialize(); } catch (Exception e) { String message = sm.getString( "standardService.connector.initFailed", connectors[i]); log.error(message, e); if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE")) throw new LifecycleException(message); } } } }
4.循环执行connectors[i].initialize();即调用与其相关的所有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 adapter = new CoyoteAdapter(this); protocolHandler.setAdapter(adapter); IntrospectionUtils.setProperty(protocolHandler, "jkHome", System.getProperty("catalina.base")); try { protocolHandler.init(); } catch (Exception e) { throw new LifecycleException (sm.getString ("coyoteConnector.protocolHandlerInitializationFailed", e)); } }
5.protocolHandler.init();调用Http11Protocol.init();
public void init() throws Exception { 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 { 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())); }
6.endpoint.init();(endpoint对象是在Http11Protocol的属性中直接new出来的和之前用Digester解析配置不一样)。调用JIoEndpoint.init():
public void init() throws Exception { if (initialized) return; // Initialize thread count defaults for acceptor if (acceptorThreadCount == 0) { acceptorThreadCount = 1; } if (serverSocketFactory == null) { serverSocketFactory = ServerSocketFactory.getDefault(); } if (serverSocket == null) { try { if (address == null) { serverSocket = serverSocketFactory.createSocket(port, backlog); } else { serverSocket = serverSocketFactory.createSocket(port, backlog, address); } } catch (BindException orig) { String msg; if (address == null) msg = orig.getMessage() + " <null>:" + port; else msg = orig.getMessage() + " " + address.toString() + ":" + port; BindException be = new BindException(msg); be.initCause(orig); throw be; } } //if( serverTimeout >= 0 ) // serverSocket.setSoTimeout( serverTimeout ); initialized = true; }
7.serverSocketFactory.createSocket()创建ServerSocket占用地址、端口开始监听请求。
初始化过程其实是初始化Connector这边的组件。StandardEngine的并没有初始化。
- [Tomcat6.0源码]组件的初始化
- [Tomcat6.0源码]组件的实例化
- [Tomcat6.0源码]组件的启动
- [Tomcat6.0源码]强大的Digester
- [Tomcat6.0源码]项目的部署
- [Tomcat6.0源码]设计模式的使用
- Tomcat6.0源码学习
- 配置tomcat6.0,tomcat5.5的admin组件教程
- tomcat6源码分析二(初始化和启动流程)
- tomcat6源码分析二(初始化和启动流程)
- [Tomcat6.0源码]从BootStrap的main开始
- [Tomcat6.0源码]请求的处理一Socket
- [Tomcat6.0源码]请求的处理二Request
- [Tomcat6.0源码]请求的处理四Pipeline、Valve、FilterChain
- [Tomcat6.0源码]请求的处理三Mapper、JMX
- COM组件的初始化
- surfaceview组件的初始化
- Tomcat源码阅读之初始化Server组件
- Android 输入法框架简介
- java多线程
- ubuntu网站
- zju 3638 Fruit Ninja
- 给盒子的贺文
- [Tomcat6.0源码]组件的初始化
- 如何解决80端口被占用的问题
- 编程能力的四种境界
- VS2010连接SQL Server 2008并执行查询操作
- JDBC
- input值改变事件兼容代码(用于做自动补全)
- KMP算法总结
- 单向链表 头尾插法
- c# FTP操作类