1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      StandardEngine分析-tomcat6.x源碼閱讀

      StandardEngine是什么

      創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),松桃企業(yè)網(wǎng)站建設(shè),松桃品牌網(wǎng)站建設(shè),網(wǎng)站定制,松桃網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,松桃網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。

      standardEngine是org.apache.catalina.Engine接口的標(biāo)準(zhǔn)實現(xiàn),繼承自ContainerBase,具備容器的功能。Engine的上級領(lǐng)導(dǎo)是Service,角色是負(fù)責(zé)管理虛擬主機,一個Engine就是一個Servlet容器,能夠完成處理請求的任務(wù),Engine從Connector連接器接收請求,然后分發(fā)到響應(yīng)的虛擬主機處理。當(dāng)需要tomcat需要使用多個虛擬機(配置jvmRoute)來實現(xiàn)負(fù)載均衡時,就需要用到Engine。在tomcat中,Engine不是必須的,但是tomcat都會啟用Engine組件。Engine的功能:從Connector連接中接收請求,為請求選擇虛擬機,分發(fā)到虛擬主機中處理請求。

      StandardEngine()
      StandardEngine在默認(rèn)構(gòu)造器中準(zhǔn)備所需資源的常量配置。調(diào)用super()方式初始化父類,也即ContainerBase;然后為pipeline閥門鏈(類似FilterChain)設(shè)置基準(zhǔn)Valve,再者設(shè)置jvmRoute虛擬機路由,最后設(shè)置Engine后臺處理線程的時間間隔。StandardEngine需要使用到這些內(nèi)容來完成Engine的功能。

      /** * Create a new StandardEngine component with the default basic Valve. */ public StandardEngine() { super(); pipeline.setBasic(new StandardEngineValve()); /* Set the jmvRoute using the system property jvmRoute */ try { //虛擬機路由,集群使用 setJvmRoute(System.getProperty("jvmRoute")); } catch (Exception ex) { } // By default, the engine will hold the reloading thread backgroundProcessorDelay = 10; }

      ContainerBase是tomcat的基容器,實現(xiàn)Container容器接口,具有容器的特點和功能。StandardEngine繼承了ContainerBase,Engine是容器,具備容器所具備的功能,Engine的父容器是Service,子容器是Host。

      StandardEngineValve
      Valve在tomcat中蠻重要的,因為所有的請求和響應(yīng)都必需通過它來過濾,負(fù)責(zé)傳遞請求和響應(yīng)信息,多個Valve組成Pipeline Valve鏈,每個容器都具有一個Pipeline鏈,同時有一個BasicValve,BasicValve的作用非常重要,BasicValve在Pipeline鏈的尾部,負(fù)責(zé)調(diào)用傳遞請求信息,將控制轉(zhuǎn)到子容器中的Pipeline中。每個容器都有自己的BasicValve,StandardEngineValve就是Engine的BasicValve,繼承自ValveBase。StandardEngineValve的方法invoke(Request, Response)負(fù)責(zé)將請求傳遞到Host組件中。

      /** * Select the appropriate child Host to process this request, based on the * requested server name. If no matching Host can be found, return an * appropriate HTTP error. * * @param request * Request to be processed * @param response * Response to be produced * @param valveContext * Valve context used to forward to the next Valve * * @exception IOException * if an input/output error occurred * @exception ServletException * if a servlet error occurred */ public final void invoke(Request request, Response response) throws IOException, ServletException { // Select the Host to be used for this Request Host host = request.getHost();//選擇host if (host == null) { response.sendError( HttpServletResponse.SC_BAD_REQUEST, sm.getString("standardEngine.noHost", request.getServerName())); return; } // Ask this Host to process this request host.getPipeline().getFirst().invoke(request, response); }

      Valve
      過濾Request/Response的接口,類似于Filter,兩者功能類似,但是作用階段不一樣。Valve由tomcat控制,多個Valve組成一個Pipeline Valve鏈,每一個容器組件由于一個Pipeline,F(xiàn)ilter是程序員定義邏輯,作用范圍比Valve小。方法setNext(Valve)是設(shè)置本Valve的下一個Valve,Valve自己本身就是一個單向鏈表的節(jié)點,方法backgroundProcess()是后臺任務(wù)處理,與容器的backgroundProcess()功能相同,方法invoke(Request, Response)是Valve的核心,也即它的功能點所在,負(fù)責(zé)過濾Request/Response或者傳遞控制。

      ValveBase
      是Valve接口的實現(xiàn),同時實現(xiàn)了Contained,MBeanRegistration接口,具備粘附容器和添加JMX監(jiān)控的能力,方法backgroundProcess(),invoke(Request, Response)提供空實現(xiàn),不做任何邏輯操作,將邏輯定義放置到子類中去。本類所完成的功能是Valve的next,保存Valve的下一個Valve,以及Contained接口的方法功能,依附容器。

      addChild(Container)
      添加子容器,在方法內(nèi)部是調(diào)用父類的方法添加子容器。容器嵌套是容器的基本功能之一。

      init()
      負(fù)責(zé)StandardEngine容器的初始化。主要完成以下幾步操作:

      設(shè)置以及初始化標(biāo)記 注冊組件,添加MBServer監(jiān)控 對父容器Service組件狀態(tài)的判斷

      /** * 初始化 */ public void init() { if (initialized) return; initialized = true;//標(biāo)記初始化 if (oname == null) { // not registered in JMX yet - standalone mode try { if (domain == null) { domain = getName(); } if (log.isDebugEnabled()) log.debug("Register " + domain); oname = new ObjectName(domain + ":type=Engine"); controller = oname; //登記組件 Registry.getRegistry(null, null).registerComponent(this, oname, null); } catch (Throwable t) { log.info("Error registering ", t); } } //MBean監(jiān)控 if (mbeansFile == null) { String defaultMBeansFile = getBaseDir() + "/conf/tomcat5-mbeans.xml"; File f = new File(defaultMBeansFile); if (f.exists()) mbeansFile = f.getAbsolutePath(); } if (mbeansFile != null) { readEngineMbeans(); } if (mbeans != null) { try { Registry.getRegistry(null, null).invoke(mbeans, "init", false); } catch (Exception e) { log.error("Error in init() for " + mbeansFile, e); } } // not needed since the following if statement does the same thing the // right way // remove later after checking // if( service==null ) { // try { // ObjectName serviceName=getParentName(); // if( mserver.isRegistered( serviceName )) { // log.info("Registering with the service "); // try { // mserver.invoke( serviceName, "setContainer", // new Object[] { this }, // new String[] { "org.apache.catalina.Container" } ); // } catch( Exception ex ) { // ex.printStackTrace(); // } // } // } catch( Exception ex ) { // log.error("Error registering with service "); // } // } if (service == null) {//如果服務(wù)沒有創(chuàng)建 // for consistency...: we are probably in embeded mode try { //創(chuàng)建標(biāo)準(zhǔn)服務(wù) service = new StandardService(); //設(shè)在容器所屬 service.setContainer(this); //初始化 service.initialize(); // Use same name for Service service.setName(getName()); } catch (Throwable t) { log.error(t); } } }

      start()
      負(fù)責(zé)StandardEngine容器的啟動任務(wù),在start()方法中主要完成以下幾步操作:

      判定是否已經(jīng)啟動和初始化 啟動realm權(quán)限管理組件,注冊到MBServer 調(diào)用基類的start()方法,啟動容器,在父容器的start()方法中主要完成事件觸發(fā),logger組件,manager組件,realm組件,cluster組件,resource組件,pipeline組件,后臺處理任務(wù)的啟動

      /** * Start this Engine component. * 啟動Engine * * @exception LifecycleException * if a startup error occurs */ public void start() throws LifecycleException { if (started) { return; } if (!initialized) { init();//初始化 } // Look for a realm - that may have been configured earlier. // If the realm is added after context - it\'ll set itself. if (realm == null) { ObjectName realmName = null; try { realmName = new ObjectName(domain + ":type=Realm"); if (mserver.isRegistered(realmName)) { mserver.invoke(realmName, "init", new Object[] {}, new String[] {}); } } catch (Throwable t) { log.debug("No realm for this engine " + realmName); } } // Log our server identification information // System.out.println(ServerInfo.getServerInfo()); if (log.isInfoEnabled()) log.info("Starting Servlet Engine: " + ServerInfo.getServerInfo()); if (mbeans != null) { try { Registry.getRegistry(null, null).invoke(mbeans, "start", false); } catch (Exception e) { log.error("Error in start() for " + mbeansFile, e); } } // Standard container startup super.start();//啟動 }

      stop()
      負(fù)責(zé)停止Engine,主要完成以下幾步:

      調(diào)用父類的stop()方法 停止mbserver

      /** * 停止engine */ public void stop() throws LifecycleException { super.stop();//停止 if (mbeans != null) { try { Registry.getRegistry(null, null).invoke(mbeans, "stop", false); } catch (Exception e) { log.error("Error in stop() for " + mbeansFile, e); } } }

      destroy()
      負(fù)責(zé)Engine銷毀,清理占用資源。主要完成以下幾個步驟:

      注銷組件在mbserver,銷毀組件。

      /** * 銷毀Engine */ public void destroy() throws LifecycleException { if (!initialized) return; initialized = false;//標(biāo)記未初始化 // if we created it, make sure it\'s also destroyed // this call implizit this.stop() ((StandardService) service).destroy();//銷毀服務(wù) if (mbeans != null) { try { Registry.getRegistry(null, null).invoke(mbeans, "destroy", false); } catch (Exception e) { log.error(sm.getString( "standardEngine.unregister.mbeans.failed", mbeansFile), e); } } // if (mbeans != null) { try { for (int i = 0; i < mbeans.size(); i++) { Registry.getRegistry(null, null).unregisterComponent( (ObjectName) mbeans.get(i)); } } catch (Exception e) { log.error(sm.getString( "standardEngine.unregister.mbeans.failed", mbeansFile), e); } } // force all metadata to be reloaded. // That doesn\'t affect existing beans. We should make it per // registry - and stop using the static. Registry.getRegistry(null, null).resetMetadata(); }

      logAccess(Request, Response, long, boolean)
      日志記錄方法,負(fù)責(zé)記錄請求信息和響應(yīng)信息,對于監(jiān)控和調(diào)試很有幫助。

      AccessLogListener
      負(fù)責(zé)監(jiān)聽請求,如果有請求則觸發(fā)事件通知日志記錄。

      StandardEngine寫的馬馬虎虎,認(rèn)識程度還不夠深。Engine作為連接Connector和Host的角色,Connector負(fù)責(zé)監(jiān)聽網(wǎng)絡(luò)端口,接收請求信息,Engine負(fù)責(zé)將請求信息轉(zhuǎn)到指定的Host中處理。Engine管理一個或者多個Host,可以在一個Engine中配置多個Host,不同的Host應(yīng)該由系統(tǒng)中配置的jvmRouteId來運行。Engine作為tomcat中標(biāo)準(zhǔn)的容器,銜接Service和Host,但是也可以沒有Engine組件,可以直接將請求轉(zhuǎn)到Servlet中處理,Engine的存在使得多個Host成為可能,而且層次結(jié)構(gòu)更清晰,管理和維護組件更加容易。


      分享標(biāo)題:StandardEngine分析-tomcat6.x源碼閱讀
      URL網(wǎng)址:http://ef60e0e.cn/article/cjidii.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        河北区| 秦皇岛市| 巨野县| 旬阳县| 平山县| 疏勒县| 龙海市| 东丽区| 金华市| 洪洞县| 天祝| 柏乡县| 乡城县| 铜鼓县| 灵璧县| 东城区| 淄博市| 朝阳市| 恩施市| 浦北县| 锦州市| 唐山市| 阿克陶县| 博兴县| 神农架林区| 富民县| 华坪县| 获嘉县| 顺义区| 万山特区| 方正县| 大新县| 台中县| 新津县| 平原县| 长岭县| 陇南市| 潞城市| 齐齐哈尔市| 牙克石市| 保靖县|