Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter责任链模式改造 #5

Closed
Tracked by #1
cybertheye opened this issue Nov 8, 2023 · 0 comments
Closed
Tracked by #1

filter责任链模式改造 #5

cybertheye opened this issue Nov 8, 2023 · 0 comments
Assignees
Labels
O(3) 事情复杂度 等级3 Priority L2 优先级等级2 tomcat tomcat模块 VIP L3 重要程度等级3 开发工作 迭代 功能开发,多线程开发,新特性开发,改造等

Comments

@cybertheye
Copy link
Owner

目前的责任链开启的方式是

    @Override
    public void start(MTRequest request, MTResponse response) {

        FilterNode traveler = head.getNext();
        try {
            while (traveler != null && traveler.exec(request, response)) {
                traveler=traveler.next;
            }

            targetServlet.service(request,response);

        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }

这里实现的启动 责任链 并不是 Tomcat 中的实现模式,

从方法栈角度来看,这里是来一个方法,执行完,然后出栈,执行下一个。

Tomcat

@Override  
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {  
	  
	System.out.println("filter before"); 
    
    chain.doFilter(request, response);  
  
    System.out.println("filter after");

他是 以 chain.doFilter(request, response); 请求过来执行这句代码上方的代码
请求返回的时候去执行这句代码下方的代码

从方法栈角度来看,方法栈是没有出栈的,类似递归,最后递归回来。

todo 这里迭代修改实现模式

@cybertheye cybertheye added tomcat tomcat模块 迭代 功能开发,多线程开发,新特性开发,改造等 开发工作 VIP L3 重要程度等级3 Priority L2 优先级等级2 O(3) 事情复杂度 等级3 labels Nov 8, 2023
@cybertheye cybertheye self-assigned this Nov 8, 2023
Terrdi added a commit to Terrdi/evolution-from-netty-to-springboot that referenced this issue Nov 16, 2023
通过成员变量实现逐个Filter访问
cybertheye added a commit that referenced this issue Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O(3) 事情复杂度 等级3 Priority L2 优先级等级2 tomcat tomcat模块 VIP L3 重要程度等级3 开发工作 迭代 功能开发,多线程开发,新特性开发,改造等
Projects
Status: Done ✅
Development

No branches or pull requests

1 participant