Tapestry3源码阅读笔记4:ApplicationServlet/RequestContext
之前都是从Page类以及Page类的创建缓存相关的类去阅读代码,现在换个角度,从请求开始的角度去出发,这样才能将整个流程联系起来。那么开始看tapestry的servlet。
?
ApplicationServlet类作为默认的tapestry的servlet。实际就是将请求调用传递给engine进行调用。// Create a context from the various bits and pieces.context = createRequestContext(request, response);// The subclass provides the engine.IEngine engine = getEngine(context);boolean dirty = engine.service(context);HttpSession session = context.getSession();// When there's an active session, we *may* store it into// the HttpSession and we *will not* store the engine// back into the engine pool.if (session != null){// If the service may have changed the engine and the// special storeEngine flag is on, then re-save the engine// into the session. Otherwise, we only save the engine// into the session when the session is first created (is new).try{boolean forceStore =engine.isStateful() && (session.getAttribute(_attributeName) == null);if (forceStore || dirty){if (LOG.isDebugEnabled())LOG.debug("Storing " + engine + " into session as " + _attributeName);session.setAttribute(_attributeName, engine);}}catch (IllegalStateException ex){}// The engine is stateful and stored in a session. Even if it started// the request cycle in the pool, it doesn't go back.return;}if (engine.isStateful()){LOG.error(Tapestry.format("ApplicationServlet.engine-stateful-without-session",engine));return;}// No session; the engine contains no state particular to// the client (except for locale). Don't throw it away,// instead save it in a pool for later reuse (by this, or another// client in the same locale)._enginePool.store(engine.getLocale(), engine);??