zoukankan      html  css  js  c++  java
  • Tomcat 7 Connector 精读(2) CoyoteAdapter

    这个适配器类只讲2个方法,构造方法中我们看到一个适配器对象有自己关联的连接器类。

    其中Service的重要任务就是讲客户端端请求交给容器。

    public void service(org.apache.coyote.Request req,
                            org.apache.coyote.Response res)
            throws Exception {
    
            Request request = (Request) req.getNote(ADAPTER_NOTES);
            Response response = (Response) res.getNote(ADAPTER_NOTES);
    
            if (request == null) {
    
                // Create objects
                request = connector.createRequest();
                request.setCoyoteRequest(req);
                response = connector.createResponse();
                response.setCoyoteResponse(res);
    
                // Link objects
                request.setResponse(response);
                response.setRequest(request);
    
                // Set as notes
                req.setNote(ADAPTER_NOTES, request);
                res.setNote(ADAPTER_NOTES, response);
    
                // Set query string encoding
                req.getParameters().setQueryStringEncoding
                    (connector.getURIEncoding());
    
            }
    
           
    
                    connector.getService().getContainer().getPipeline().getFirst().invoke(request, response);
    //最终的方法,获得连接器-->服务--》容器-》管道---》第一个value
                   
                    }
    
                }
                AsyncContextImpl asyncConImpl = (AsyncContextImpl)request.getAsyncContext();
                if (asyncConImpl != null) {
                    async = true;
                    ReadListener readListener = req.getReadListener();
                    if (readListener != null && request.isFinished()) {
                        // Possible the all data may have been read during service()
                        // method so this needs to be checked here
                        ClassLoader oldCL =
                                Thread.currentThread().getContextClassLoader();
                        ClassLoader newCL =
                                request.getContext().getLoader().getClassLoader();
                        try {
                            Thread.currentThread().setContextClassLoader(newCL);
                            if (req.sendAllDataReadEvent()) {
                                req.getReadListener().onAllDataRead();
                            }
                        } finally {
                            Thread.currentThread().setContextClassLoader(oldCL);
                        }
                    }
                } else if (!comet) {
                    request.finishRequest();
                    response.finishResponse();
                    if (postParseSuccess &&
                            request.getMappingData().context != null) {
                        // Log only if processing was invoked.
                        // If postParseRequest() failed, it has already logged it.
                        // If context is null this was the start of a comet request
                        // that failed and has already been logged.
                        request.getMappingData().context.logAccess(
                                request, response,
                                System.currentTimeMillis() - req.getStartTime(),
                                false);
                    }
                }
    
            } catch (IOException e) {
                // Ignore
            } finally {
                req.getRequestProcessor().setWorkerThreadName(null);
                AtomicBoolean error = new AtomicBoolean(false);
                res.action(ActionCode.IS_ERROR, error);
                // Recycle the wrapper request and response
                if (!comet && !async || error.get()) {
                    request.recycle();
                    response.recycle();
                } else {
                    // Clear converters so that the minimum amount of memory
                    // is used by this processor
                    request.clearEncoders();
                    response.clearEncoders();
                }
            }
    
        }
  • 相关阅读:
    晨读,难道只是为了完成任务而读的吗?
    集合还有这么优雅的运算法?
    Java中的TreeSet集合会自动将元素升序排序
    CSS3的几个变形案例……
    “老师,请您多关注一下我吧!!!”
    jsp中使用cookie时报错……
    为什么要有周考?周考是用来干什么的?
    今天,我们就来抽个奖!
    今天 ,给大家变个魔术!!!
    Google Maps Api 多坐标分类标记,在地图上显示海量坐标,并分组显示。
  • 原文地址:https://www.cnblogs.com/hansongjiang/p/4229772.html
Copyright © 2011-2022 走看看