zoukankan      html  css  js  c++  java
  • Tomcat中的Listener源码片段解读

      @Override
        public <T extends EventListener> void addListener(T t) {
            if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
                throw new IllegalStateException(
                        sm.getString("applicationContext.addListener.ise",
                                getContextPath()));
            }
    
            boolean match = false;
            if (t instanceof ServletContextAttributeListener ||
                    t instanceof ServletRequestListener ||
                    t instanceof ServletRequestAttributeListener ||
                    t instanceof HttpSessionIdListener ||
                    t instanceof HttpSessionAttributeListener) {
                context.addApplicationEventListener(t);
                match = true;
            }
    
            if (t instanceof HttpSessionListener
                    || (t instanceof ServletContextListener &&
                            newServletContextListenerAllowed)) {
                // Add listener directly to the list of instances rather than to
                // the list of class names.
                context.addApplicationLifecycleListener(t);
                match = true;
            }
    
            if (match) return;
    
            if (t instanceof ServletContextListener) {
                throw new IllegalArgumentException(sm.getString(
                        "applicationContext.addListener.iae.sclNotAllowed",
                        t.getClass().getName()));
            } else {
                throw new IllegalArgumentException(sm.getString(
                        "applicationContext.addListener.iae.wrongType",
                        t.getClass().getName()));
            }
        }

    这段原代码,可以看到Listener一定要继承EventListener,然后conext,到底什么是上下文,监听器是其一部分。

  • 相关阅读:
    #1015 : KMP算法
    #1014 Trie树
    Type.IsContextful 说明
    判断.net中在windows系统下的字节序
    Python3 循环语句
    adb 脚本
    如何使用 adb 命令实现自动化测试
    python 字符串的方法和注释
    Android使用Fiddler模拟弱网络环境测试
    Android定位元素与操作
  • 原文地址:https://www.cnblogs.com/Robin008/p/10205211.html
Copyright © 2011-2022 走看看