4.4 入口是SolrDispatchFilter,整个流程如流程图所示
从上面的流程图可以看出,solr采用filter的模式(如struts2,springmvc使用servlet模式),然后以容器的方式来封装各种Handler,Handler负责处理各种请求,终调用的是lucene的底层实现。
注意:solr没有使用lucene本身的QueryParser,而是自己重写了这个组件。
4.4.1 SolrDispatchFilter入口
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain, boolean retry) throwsIOException, ServletException { if (!(request instanceof HttpServletRequest)) return; try{ if (cores == null ||cores.isShutDown()) { try{ init.await(); } catch (InterruptedException e) { //well, no wait then} final String msg = "Error processing the request. CoreContainer is either not initialized or shutting down."; if (cores == null ||cores.isShutDown()) { log.error(msg); throw newUnavailableException(msg); } } AtomicReference wrappedRequest = new AtomicReference
(); if (!authenticateRequest(request, response, wrappedRequest)) { // the response and status code have already been // sent return; } if (wrappedRequest.get() != null) { request =wrappedRequest.get(); } request =closeShield(request, retry); response =closeShield(response, retry); if (cores.getAuthenticationPlugin() != null) { log.debug("User principal: {}", ((HttpServletRequest) request).getUserPrincipal()); } // No need to even create the HttpSolrCall object if this path is excluded. if (excludePatterns != null) { String requestPath =((HttpServletRequest) request).getServletPath(); String extraPath =((HttpServletRequest) request).getPathInfo(); if (extraPath != null) { // In embedded mode, servlet path is empty - include all post-context path here for // testing requestPath +=extraPath; } for(Pattern p : excludePatterns) { Matcher matcher =p.matcher(requestPath); if(matcher.lookingAt()) { chain.doFilter(request, response); return; } } } HttpSolrCall call =getHttpSolrCall((HttpServletRequest) request, (HttpServletResponse) response, retry); ExecutorUtil.setServerThreadFlag(Boolean.TRUE); try{ Action result = call.call(); //1 switch(result) { casePASSTHROUGH: chain.doFilter(request, response); break; caseRETRY: doFilter(request, response, chain, true); break; caseFORWARD: request.getRequestDispatcher(call.getPath()).forward(request, response); break; } } finally{ call.destroy(); ExecutorUtil.setServerThreadFlag(null); } } finally {
consumeInputFully((HttpServletRequest) request);
}
}