• neohope
    2019-07-23
    最后的问题,应该是这样的:

    protected void doStart() throws Exception
    {
        try{
            _outerScope=__outerScope.get();
            if (_outerScope==null){
               //本次处理的第一个scope handler
               //告知后续scope handler,_outerScope选我
                __outerScope.set(this);
            }
            super.doStart();
            _nextScope= getChildHandlerByClass(ScopedHandler.class);
        }
        finally
        {
            if (_outerScope==null){
               //本次处理结束
               //为了下次同一个线程处理是,
               //还能正常的设置第一个scope handler
               //必须把threadlocal变量设为null
                __outerScope.set(null);
            }
        }
    }


    此外,这一节里有一个non scoped handler X,一开始没太看懂调阅顺序。
    后来发现是这样的:

    public final void nextHandle(String target...)...
    {
        if (_nextScope!=null && _nextScope==_handler){
            //上面条件可以保证下一个handler是scope handler
            _nextScope.doHandle(target,baseRequest,request, response);
        }
        else if (_handler!=null){
            //non scpoe handler调用下一个handler的
            super.handle(target,baseRequest,request,response);
        }
    }

    感觉类成员的命名不太合适,
    比如__outerScope和_outerScope
    比如_handler其实一直指向的是下一个handler,是不是该为_nextHandler更好一些?
    展开

    作者回复: 给你的钻研精神点赞👍

    
     3
  • despacito
    2019-07-16
    ScopedHandler 会有不同的实现类,而__outerScope 是ScopedHandler里static的变量,如果不设置为null,那么不同的子类实例执行doStrat()方法的时候,会有问题
    
     3
  • 往事随风,顺其自然
    2019-07-16
    可以重新处理下一次请求
    
     2
  • nightmare
    2019-07-16
    每一次请求的请求链互不影响
    
     2
  • 帽子丨影
    2019-09-26
    感觉jetty的源码写的好混乱,经常没有注释,一个类也通常扩展3/4个接口功能,还各种循环嵌套。好难懂。。。
    
     1
我们在线,来聊聊吧