您的位置:首页 > 运维架构 > Tomcat

The study of Tomcat Source Code -- Party II

2012-12-04 13:00 453 查看
Tomcat is a big 'box'.

When we want this box work as a server, We had to start all of its contained small box and stuff(its components, such as contexts , wrappers, loaders, contexts' mappers,contexts'pipelines, wrappers' pipelines etc. )

It could be an annoy job to remember and to start all these components one by one. So as to 'stop'.  Is there some effective way to get work done?

We know these components are hierarchical. If we start the biggest, and let the biggest to start its children. And then let children start grandson.
It could be perfect.

If children could be started and stopped by its father, it should get its 'start' and 'stop' method. Well, components implement the 'LifeCycle' interface whose methods include 'start' and 'stop'. Besides these two methods, if a component implements the 'LifeCycle',
it must be allowed to be added 'LifeCycleListener' to be listened when it take some action(So there is a method 'addLifeCycleListener' in LifeCycle interface).

It comes to reality that bigger containers can start its components when they implement 'LifeCycle' interface. But just as above said, components which implement the 'LifeCycle' interface could trigger event when it is added 'LifeCycleListener'. Well, here
comes anther problem: where the listener is stored and when relevant event is triggered, how listener take action to response. So 'LifeCycleSupport' come to life. 'LifeCycleSupport' class has 4 methods: addLifeCycleListener, removeLifeCycleListener,fireLifeCycleListener,
find LifeCycleListener. it has 1 arraylist of 'LifeListener'(interface) to hold to listeners. When it is called fireLifeCycleListener, this mehod enumerate the list of listener to check if the trigger and the event the trigger fit with the listener, if yes
do something.(check ... do something is the very method in LifeCycleListener interface) 

   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: