Server的继承关系
Lifecycle:通用接口组件生命周期方法
LifecycleBase:Lifecycle接口的基本实现,实现start和stop的状态转换规则。
LifecycleMBeanBase:主要实现JmxEnabled的方法
StandardServer:Server接口的标准实现,当Catalina是deploying和starting时使用(但不是必须)
StandardServer源码分析
1、StandardServer.initInternal
@Override
protected void initInternal() throws LifecycleException {
super.initInternal();
/*
注册全局的String缓存
注意:缓存虽然是全局,但如果有多个Servers存在jvm中,同样的缓存会用多个名字注册
*/
onameStringCache = register(new StringCache(), "type=StringCache");
// Register the MBeanFactory
MBeanFactory factory = new MBeanFactory();
factory.setContainer(this);
onameMBeanFactory = register(factory, "type=MBeanFactory");
// Register the naming resources
globalNamingResources.init();
//从common和shared类加载器填充jar包的扩展校验器
// Populate the extension validator with JARs from common and shared
// class loaders
if (getCatalina() != null) {
ClassLoader cl = getCatalina().getParentClassLoader();
// Walk the class loader hierarchy. Stop at the system class loader.
// This will add the shared (if present) and common class loaders
while (cl != null && cl != ClassLoader.getSystemClassLoader()) {
if (cl instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader) cl).getURLs();
for (URL url : urls) {
if (url.getProtocol().equals("file")) {
try {
File f = new File (url.toURI());
if (f.isFile() &&
f.getName().endsWith(".jar")) {
ExtensionValidator.addSystemResource(f);
}
} catch (URISyntaxException e) {
// Ignore
} catch (IOException e) {
// Ignore
}
}
}
}
cl = cl.getParent();
}
}
//初始化Services
// Initialize our defined Services
for (int i = 0; i < services.length; i++) {
services[i].init();
}
}
2、StandardServer.startInternal
@Override
protected void startInternal() throws LifecycleException {
fireLifecycleEvent(CONFIGURE_START_EVENT, null);
setState(LifecycleState.STARTING);
globalNamingResources.start();
// 启动Services
synchronized (services) {
for (int i = 0; i < services.length; i++) {
services[i].start();
}
}
}
3、StandardServer.await
启动监听关闭命令的8005端口