分享
 
 
 

Tomcat源代码学习日记(2004-09-30 05:52)

王朝system·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

类的load过程

在Catalina中

public static void main(String args[]) {

(new Catalina()).process(args);

}

1.public class Catalina extends Embedded

2.public class Embedded extends StandardService implements Lifecycle

2.1 public class StandardService implements Lifecycle, Service, MBeanRegistration

2.2 public interface Lifecycle

2.3 public Embedded(Logger logger, Realm realm) {

super();

setLogger(logger);

setRealm(realm);

setSecurityProtection();

}

3.1 public interface Lifecycle

3.2 public interface Service

3.3 abstract public interface javax.management.MBeanRegistration extends java.lang.Object

3.4 public void setLogger(Logger logger) {

Logger oldLogger = this.logger;

this.logger = logger;

support.firePropertyChange("logger", oldLogger, this.logger);

}

3.4 public void setRealm(Realm realm) {

Realm oldRealm = this.realm;

this.realm = realm;

support.firePropertyChange("realm", oldRealm, this.realm);

}

3.5 protected void setSecurityProtection(){

SecurityConfig securityConfig = SecurityConfig.newInstance();

securityConfig.setPackageDefinition();

securityConfig.setPackageAccess();

}

4.1 protected PropertyChangeSupport support = new PropertyChangeSupport(this);

4.2 protected PropertyChangeSupport support = new PropertyChangeSupport(this);

4.3 public final class SecurityConfig

初始化

方法调用

在catalina

public static void main(String args[]) {

(new Catalina()).process(args);

}

public void process(String args[]) {

setAwait(true);

setCatalinaHome();

setCatalinaBase();

try {

if (arguments(args)) {

if (starting) {

load(args);

start();

} else if (stopping) {

stopServer();

}

}

} catch (Exception e) {

e.printStackTrace(System.out);

}

}

public void setAwait(boolean b) {

await = b;

}

类的load过程

在Catalina中

public static void main(String args[]) {

(new Catalina()).process(args);

}

1.public class Catalina extends Embedded

2.public class Embedded extends StandardService implements Lifecycle

2.1 public class StandardService implements Lifecycle, Service, MBeanRegistration

2.2 public interface Lifecycle

2.3 public Embedded(Logger logger, Realm realm) {

super();

setLogger(logger);

setRealm(realm);

setSecurityProtection();

}

3.1 public interface Lifecycle

3.2 public interface Service

3.3 abstract public interface javax.management.MBeanRegistration extends java.lang.Object

3.4 public void setLogger(Logger logger) {

Logger oldLogger = this.logger;

this.logger = logger;

support.firePropertyChange("logger", oldLogger, this.logger);

}

3.4 public void setRealm(Realm realm) {

Realm oldRealm = this.realm;

this.realm = realm;

support.firePropertyChange("realm", oldRealm, this.realm);

}

3.5 protected void setSecurityProtection(){

SecurityConfig securityConfig = SecurityConfig.newInstance();

securityConfig.setPackageDefinition();

securityConfig.setPackageAccess();

}

4.1 protected PropertyChangeSupport support = new PropertyChangeSupport(this);

4.2 protected PropertyChangeSupport support = new PropertyChangeSupport(this);

4.3 public final class SecurityConfig

初始化

方法调用

在catalina

public static void main(String args[]) {

(new Catalina()).process(args);

}

public void process(String args[]) {

setAwait(true);

setCatalinaHome();

setCatalinaBase();

try {

if (arguments(args)) {

if (starting) {

load(args);

start();

} else if (stopping) {

stopServer();

}

}

} catch (Exception e) {

e.printStackTrace(System.out);

}

}

public void setAwait(boolean b) {

await = b;

}

public void setCatalinaHome() {

initDirs();

}

protected void initDirs() {

String catalinaHome = System.getProperty("catalina.home");

if (catalinaHome == null) {

// Backwards compatibility patch for J2EE RI 1.3

String j2eeHome = System.getProperty("com.sun.enterprise.home");

if (j2eeHome != null) {

catalinaHome=System.getProperty("com.sun.enterprise.home");

} else if (System.getProperty("catalina.base") != null) {

catalinaHome = System.getProperty("catalina.base");

} else {

// Use IntrospectionUtils and guess the dir

catalinaHome = IntrospectionUtils.guessInstall

("catalina.home", "catalina.base", "catalina.jar");

if (catalinaHome == null) {

catalinaHome = IntrospectionUtils.guessInstall

("tomcat.install", "catalina.home", "tomcat.jar");

}

}

}

if (catalinaHome != null) {

File home = new File(catalinaHome);

if (!home.isAbsolute()) {

try {

catalinaHome = home.getCanonicalPath();

} catch (IOException e) {

catalinaHome = home.getAbsolutePath();

}

}

System.setProperty("catalina.home", catalinaHome);

}

if (System.getProperty("catalina.base") == null) {

System.setProperty("catalina.base",

System.getProperty("catalina.home"));

} else {

String catalinaBase = System.getProperty("catalina.base");

File base = new File(catalinaBase);

if (!base.isAbsolute()) {

try {

catalinaBase = base.getCanonicalPath();

} catch (IOException e) {

catalinaBase = base.getAbsolutePath();

}

}

System.setProperty("catalina.base", catalinaBase);

}

}

protected boolean arguments(String args[]) {

boolean isConfig = false;

if (args.length < 1) {

usage();

return (false);

}

for (int i = 0; i < args.length; i++) {

if (isConfig) {

configFile = args[i];

isConfig = false;

} else if (args[i].equals("-config")) {

isConfig = true;

} else if (args[i].equals("-debug")) {

debug = 1;

} else if (args[i].equals("-nonaming")) {

setUseNaming( false );

} else if (args[i].equals("-help")) {

usage();

return (false);

} else if (args[i].equals("start")) {

starting = true;

stopping = false;

} else if (args[i].equals("stop")) {

starting = false;

stopping = true;

} else {

usage();

return (false);

}

}

return (true);

}

public void load(String args[]) {

setCatalinaHome();

setCatalinaBase();

try {

if (arguments(args))

load();

} catch (Exception e) {

e.printStackTrace(System.out);

}

}

public void load() {

initDirs();

initNaming();

Digester digester = createStartDigester();

long t1 = System.currentTimeMillis();

Exception ex = null;

InputSource inputSource = null;

InputStream inputStream = null;

try {

File file = configFile();

inputStream = new FileInputStream(file);

inputSource = new InputSource("file://" + file.getAbsolutePath());

} catch (Exception e) {

;

}

if (inputStream == null) {

try {

inputStream = getClass().getClassLoader()

.getResourceAsStream(getConfigFile());

inputSource = new InputSource

(getClass().getClassLoader()

.getResource(getConfigFile()).toString());

} catch (Exception e) {

;

}

}

if (inputStream == null) {

System.out.println("Can't load server.xml");

return;

}

try {

inputSource.setByteStream(inputStream);

digester.push(this);

digester.parse(inputSource);

inputStream.close();

} catch (Exception e) {

System.out.println("Catalina.start: " + e);

e.printStackTrace(System.out);

return;

}

SystemLogHandler systemlog = new SystemLogHandler(System.out);

System.setOut(systemlog);

System.setErr(systemlog);

if (server instanceof Lifecycle) {

try {

server.initialize();

} catch (LifecycleException e) {

log.error("Catalina.start", e);

}

}

long t2 = System.currentTimeMillis();

log.info("Initialization processed in " + (t2 - t1) + " ms");

}

protected void initNaming() {

// Setting additional variables

if (!useNaming) {

log.info( "Catalina naming disabled");

System.setProperty("catalina.useNaming", "false");

} else {

System.setProperty("catalina.useNaming", "true");

String value = "org.apache.naming";

String oldValue =

System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);

if (oldValue != null) {

value = value + ":" + oldValue;

}

System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value);

if( log.isDebugEnabled() )

log.debug("Setting naming prefix=" + value);

value = System.getProperty

(javax.naming.Context.INITIAL_CONTEXT_FACTORY);

if (value == null) {

System.setProperty

(javax.naming.Context.INITIAL_CONTEXT_FACTORY,

"org.apache.naming.java.javaURLContextFactory");

} else {

log.debug( "INITIAL_CONTEXT_FACTORY alread set " + value );

}

}

}

protected Digester createStartDigester() {

long t1=System.currentTimeMillis();

// Initialize the digester

Digester digester = new CatalinaDigester();

digester.setValidating(false);

digester.setClassLoader(StandardServer.class.getClassLoader());

// Configure the actions we will be using

digester.addObjectCreate("Server",

"org.apache.catalina.core.StandardServer",

"className");

digester.addSetProperties("Server");

digester.addSetNext("Server",

"setServer",

"org.apache.catalina.Server");

digester.addObjectCreate("Server/GlobalNamingResources",

"org.apache.catalina.deploy.NamingResources");

digester.addSetProperties("Server/GlobalNamingResources");

digester.addSetNext("Server/GlobalNamingResources",

"setGlobalNamingResources",

"org.apache.catalina.deploy.NamingResources");

digester.addObjectCreate("Server/Listener",

null, // MUST be specified in the element

"className");

digester.addSetProperties("Server/Listener");

digester.addSetNext("Server/Listener",

"addLifecycleListener",

"org.apache.catalina.LifecycleListener");

digester.addObjectCreate("Server/Service",

"org.apache.catalina.core.StandardService",

"className");

digester.addSetProperties("Server/Service");

digester.addSetNext("Server/Service",

"addService",

"org.apache.catalina.Service");

digester.addObjectCreate("Server/Service/Listener",

null, // MUST be specified in the element

"className");

digester.addSetProperties("Server/Service/Listener");

digester.addSetNext("Server/Service/Listener",

"addLifecycleListener",

"org.apache.catalina.LifecycleListener");

digester.addObjectCreate("Server/Service/Connector",

"org.apache.coyote.tomcat5.CoyoteConnector",

"className");

digester.addRule("Server/Service/Connector",

new SetAllPropertiesRule());

digester.addSetNext("Server/Service/Connector",

"addConnector",

"org.apache.catalina.Connector");

digester.addObjectCreate("Server/Service/Connector/Factory",

"org.apache.coyote.tomcat5.CoyoteServerSocketFactory",

"className");

digester.addSetProperties("Server/Service/Connector/Factory");

digester.addSetNext("Server/Service/Connector/Factory",

"setFactory",

"org.apache.catalina.net.ServerSocketFactory");

digester.addObjectCreate("Server/Service/Connector/Listener",

null, // MUST be specified in the element

"className");

digester.addSetProperties("Server/Service/Connector/Listener");

digester.addSetNext("Server/Service/Connector/Listener",

"addLifecycleListener",

"org.apache.catalina.LifecycleListener");

// Add RuleSets for nested elements

digester.addRuleSet(new NamingRuleSet("Server/GlobalNamingResources/"));

digester.addRuleSet(new EngineRuleSet("Server/Service/"));

digester.addRuleSet(new HostRuleSet("Server/Service/Engine/"));

digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Default"));

digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/DefaultContext/"));

digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/Default"));

digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/DefaultContext/"));

digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/"));

digester.addRuleSet(new ClusterRuleSet("Server/Service/Engine/Host/Cluster/"));

digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/Context/"));

// When the 'engine' is found, set the parentClassLoader.

digester.addRule("Server/Service/Engine",

new SetParentClassLoaderRule(parentClassLoader));

long t2=System.currentTimeMillis();

log.debug("Digester for server.xml created " + ( t2-t1 ));

return (digester);

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有