tomcat(3)之StandardServer.java

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多是一些接口.
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@b7838a9] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.startup.Tomcat.start(Tomcat.java:459)
最新发布
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值