1. Container結構
Engine: servlet引擎
Host: 虛擬主機
Context: ServletContext,對應一個web項目或war包,包含多個Wrapper
Wrapper: 對Servlet的封裝
2. 初始化
從Catalina類開始,主要涉及createStartDigester()方法,如下圖所示
addObjectCreate方法調用路徑 (加入隊列)
public void addObjectCreate(String pattern, String className, String attributeName) {
addRule(pattern, new ObjectCreateRule(className, attributeName));
}
addRule方法
public void addRule(String pattern, Rule rule) {
rule.setDigester(this);
getRules().add(pattern, rule);
}
add()方法
@Override
public void add(String pattern, Rule rule) {
// to help users who accidently add '/' to the end of their patterns
int patternLength = pattern.length();
if (patternLength>1 && pattern.endsWith("/")) {
pattern = pattern.substring(0, patternLength-1);
}
List<Rule> list = cache.get(pattern);
if (list == null) {
list = new ArrayList<>();
cache.put(pattern, list);
}
list.add(rule);
rules.add(rule);
if (this.digester != null) {
rule.setDigester(this.digester);
}
if (this.namespaceURI != null) {
rule.setNamespaceURI(this.namespaceURI);
}
}
rules和cache定義
protected ArrayList<Rule> rules = new ArrayList<>();protected HashMap<String,List<Rule>> cache = new HashMap<>();
StandardService類包含多個Connector和一個Engine
/**
* The <code>Server</code> that owns this Service, if any.
*/
private Server server = null;
protected Connector connectors[] = new Connector[0];
private final Object connectorsLock = new Object();
/**
*
*/
protected final ArrayList<Executor> executors = new ArrayList<>();
private Engine engine = null;