Tomcat8.x 上下文(StandardServer)中命名上下文(NamingContext)的创建

来源:互联网 发布:数据库管理第三版答案 编辑:程序博客网 时间:2024/05/21 00:46

(StandardServer)中命名上下文(NamingContext)的创建


// 命名上下文的创建---------1class org.apache.catalina.core.StandardServer{// 构造函数public StandardServer() {// “命名资源”globalNamingResources = new NamingResourcesImpl();globalNamingResources.setContainer(this);// 创建“命名上下文”监听器            namingContextListener = new NamingContextListener();            addLifecycleListener(namingContextListener);}protected void startInternal() throws LifecycleException {// 触发监听器// org.apache.catalina.core.NamingContextListener.lifecycleEvent(...)fireLifecycleEvent(CONFIGURE_START_EVENT, null); // "configure_start" 事件//  org.apache.catalina.deploy.NamingResourcesImplglobalNamingResources.start();}}// "命名资源"class org.apache.catalina.deploy.NamingResourcesImpl{ protected void startInternal() throws LifecycleException {        fireLifecycleEvent(CONFIGURE_START_EVENT, null);        setState(LifecycleState.STARTING);    }}// "命名上下文"监听器class org.apache.catalina.core.NamingContextListener{ // 事件处理器,创建"命名上下文" public void lifecycleEvent(LifecycleEvent event) {        container = event.getLifecycle();                namingResources = ((Server) container).getGlobalNamingResources();        if (Lifecycle.CONFIGURE_START_EVENT.equals(event.getType())) {                Hashtable<String, Object> contextEnv = new Hashtable<>();                namingContext = new NamingContext(contextEnv, getName()); // 创建"命名上下文"文----------                ContextAccessController.setSecurityToken(getName(), token);                ContextAccessController.setSecurityToken(container, token);                ContextBindings.bindContext(container, namingContext, token);                    createNamingContext(); // 创建“名称上下文”        } }  // 创建"命名上下文" private void createNamingContext()        throws NamingException {    // container === org.apache.catalina.core.StandardServer        if (container instanceof Server) { // 走这里            compCtx = namingContext; // org.apache.naming.NamingContext            envCtx = namingContext;        } else {            compCtx = namingContext.createSubcontext("comp");            envCtx = compCtx.createSubcontext("env");        }        // Resources        ContextResource[] resources = namingResources.findResources();        for (i = 0; i < resources.length; i++) {            addResource(resources[i]);        } }}



0 0
原创粉丝点击