StandarServer.java 所在包package org.apache.catalina.core;
public final class StandardServer
implements Lifecycle, Server, MBeanRegistration
从上节分析可以看到,Catalina.java主要执行了。
server.initialize();
server.start();
我们来看看
server.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();
}
}
注:从源码分析,初始化过程,也就是设置一些属性.
我们再来看看.
server.start();
-----------------------------------------------------------------
/**
* Prepare for the beginning of active use of the public methods of this
* component. This method should be called before any of the public
* methods of this component are utilized. It should also send a
* LifecycleEvent of type START_EVENT to any registered listeners.
*
* @exception LifecycleException if this component detects a fatal error
* that prevents this component from being used
*/
public void start() throws LifecycleException {
// Validate and update our current component state
if (started) {
log.debug(sm.getString("standardServer.start.started"));
return;
}
// Notify our interested LifecycleListeners
//通知我们相关的生命周期事件监听器,在启动前
lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
//通知我们相关的生命周期事件监听器,在启动中
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
// Start our defined Services
//开始启动我们定义的服务器。
synchronized (services) {
for (int i = 0; i < services.length; i++) {
if (services[i] instanceof Lifecycle)
((Lifecycle) services[i]).start(); //启其它服务哭。
}
}
// Notify our interested LifecycleListeners
//通知我们相关的生命周期事件监听器,在启动后
lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
}
注:
1)如果已初始化,将生成日志,说明服务已初始化.
2)通知我们相关的生命周期事件监听器,在启动前
3)通知我们相关的生命周期事件监听器,在启动中
4)启动其它服务器.
5)通知我们相关的生命周期事件监听器,在启动后
从上面代码来看,就是在服务器启动前中后,发送消息给管理生命周期的事件监听器,因此这里关键的问题应是监听器做了什么了.
这里LifecycleListener是一个接口,目前所知道实现类为:
public class AprLifecycleListener
implements LifecycleListener {
位于包:org.apache.catalina.core
如此可以看tomcat的一些核心代码在org.apache.catalina.core,
而org.apache.catalina多是一些接口.
public final class StandardServer
implements Lifecycle, Server, MBeanRegistration
从上节分析可以看到,Catalina.java主要执行了。
server.initialize();
server.start();
我们来看看
server.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();
}
}
注:从源码分析,初始化过程,也就是设置一些属性.
我们再来看看.
server.start();
-----------------------------------------------------------------
/**
* Prepare for the beginning of active use of the public methods of this
* component. This method should be called before any of the public
* methods of this component are utilized. It should also send a
* LifecycleEvent of type START_EVENT to any registered listeners.
*
* @exception LifecycleException if this component detects a fatal error
* that prevents this component from being used
*/
public void start() throws LifecycleException {
// Validate and update our current component state
if (started) {
log.debug(sm.getString("standardServer.start.started"));
return;
}
// Notify our interested LifecycleListeners
//通知我们相关的生命周期事件监听器,在启动前
lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
//通知我们相关的生命周期事件监听器,在启动中
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
// Start our defined Services
//开始启动我们定义的服务器。
synchronized (services) {
for (int i = 0; i < services.length; i++) {
if (services[i] instanceof Lifecycle)
((Lifecycle) services[i]).start(); //启其它服务哭。
}
}
// Notify our interested LifecycleListeners
//通知我们相关的生命周期事件监听器,在启动后
lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
}
注:
1)如果已初始化,将生成日志,说明服务已初始化.
2)通知我们相关的生命周期事件监听器,在启动前
3)通知我们相关的生命周期事件监听器,在启动中
4)启动其它服务器.
5)通知我们相关的生命周期事件监听器,在启动后
从上面代码来看,就是在服务器启动前中后,发送消息给管理生命周期的事件监听器,因此这里关键的问题应是监听器做了什么了.
这里LifecycleListener是一个接口,目前所知道实现类为:
public class AprLifecycleListener
implements LifecycleListener {
位于包:org.apache.catalina.core
如此可以看tomcat的一些核心代码在org.apache.catalina.core,
而org.apache.catalina多是一些接口.