mvc5 源码解析2-1:mvchandler的执行
上一节说在urlroutingmodule中mvchandler 映射到httpcontext上,那mvchandler又是怎么执行的呢?
(1)、httpruntime
从isapiruntime pr方法到httpruntime
ProcessRequestNoDemand(wr)方法
// System.Web.HttpRuntime
internal static void ProcessRequestNoDemand(HttpWorkerRequest wr)
{
//获取请求队列
RequestQueue requestQueue = HttpRuntime._theRuntime._requestQueue;
wr.UpdateInitialCounters();
if (requestQueue != null)
{
wr = requestQueue.GetRequestToExecute(wr);
}
if (wr != null)
{
HttpRuntime.CalculateWaitTimeAndUpdatePerfCounter(wr);
wr.ResetStartTime();
HttpRuntime.ProcessRequestNow(wr);
}
}
ProcessRequestNow(wr)方法
// System.Web.HttpRuntime
internal static void ProcessRequestNow(HttpWorkerRequest wr)
{
HttpRuntime._theRuntime.ProcessRequestInternal(wr);
}
ProcessRequestInternal(wr)方法
// System.Web.HttpRuntime
private void ProcessRequestInternal(HttpWorkerRequest wr)
{
//活动请求数量增加
Interlocked.Increment(ref this._activeRequestCount);
//判断请求数异常
if (this._disposingHttpRuntime)
{
try
{
wr.SendStatus(, "Server Too Busy");
wr.SendKnownResponseHeader(, "text/html; charset=utf-8");
byte[] bytes = Encoding.ASCII.GetBytes("<html><body>Server Too Busy</body></html>");
wr.SendResponseFromMemory(bytes, bytes.Length);
wr.FlushResponse(true);
wr.EndOfRequest();
}
finally
{
Interlocked.Decrement(ref this._activeRequestCount);
}
return;
}
HttpContext httpContext;
try
{
//HttpWorkerRequest转HttpContext
httpContext = new HttpContext(wr, false);
}
catch
{
try
{
wr.SendStatus(, "Bad Request");
wr.SendKnownResponseHeader(, "text/html; charset=utf-8");
byte[] bytes2 = Encoding.ASCII.GetBytes("<html><body>Bad Request</body></html>");
wr.SendResponseFromMemory(bytes2, bytes2.Length);
wr.FlushResponse(true);
wr.EndOfRequest();
return;
}
finally
{
Interlocked.Decrement(ref this._activeRequestCount);
}
}
wr.SetEndOfSendNotification(this._asyncEndOfSendCallback, httpContext);
HostingEnvironment.IncrementBusyCount();
try
{
try
{
this.EnsureFirstRequestInit(httpContext);
}
catch
{
if (!httpContext.Request.IsDebuggingRequest)
{
throw;
}
}
httpContext.Response.InitResponseWriter();
//获取application实例
IHttpHandler applicationInstance = HttpApplicationFactory.GetApplicationInstance(httpContext);
if (applicationInstance == null)
{
throw new HttpException(SR.GetString("Unable_create_app_object"));
}
if (EtwTrace.IsTraceEnabled(, ))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_START_HANDLER, httpContext.WorkerRequest, applicationInstance.GetType().FullName, "Start");
}
//判断application实例是否有继承IHttpAsyncHandler
if (applicationInstance is IHttpAsyncHandler)
{
IHttpAsyncHandler httpAsyncHandler = (IHttpAsyncHandler)applicationInstance;
httpContext.AsyncAppHandler = httpAsyncHandler;
//执行application的BeginProcessRequest
httpAsyncHandler.BeginProcessRequest(httpContext, this._handlerCompletionCallback, httpContext);
}
else
{
applicationInstance.ProcessRequest(httpContext);
this.FinishRequest(httpContext.WorkerRequest, httpContext, null);
}
}
catch (Exception e)
{
httpContext.Response.InitResponseWriter();
this.FinishRequest(wr, httpContext, e);
}
}
BeginProcessRequest方法
IAsyncResult IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
{
this._context = context;
this._context.ApplicationInstance = this;
this._stepManager.InitRequest();
this._context.Root();
HttpAsyncResult httpAsyncResult = new HttpAsyncResult(cb, extraData);
this.AsyncResult = httpAsyncResult;
if (this._context.TraceIsEnabled)
{
HttpRuntime.Profile.StartRequest(this._context);
}
//执行步骤
this.ResumeSteps(null);
return httpAsyncResult;
}
ResumeSteps方法
private void ResumeSteps(Exception error)
{
this._stepManager.ResumeSteps(error);
}
this._stepManager 抽象类
internal abstract class StepManager
{
protected HttpApplication _application; protected bool _requestCompleted; internal bool IsCompleted
{
get
{
return this._requestCompleted;
}
} internal StepManager(HttpApplication application)
{
this._application = application;
} internal abstract void BuildSteps(WaitCallback stepCallback); internal void CompleteRequest()
{
this._requestCompleted = true;
if (HttpRuntime.UseIntegratedPipeline)
{
HttpContext context = this._application.Context;
if (context != null && context.NotificationContext != null)
{
context.NotificationContext.RequestCompleted = true;
}
}
} internal abstract void InitRequest(); internal abstract void ResumeSteps(Exception error);
}
mvc5 源码解析2-1:mvchandler的执行的更多相关文章
- [源码解析]Oozie来龙去脉之内部执行
		[源码解析]Oozie来龙去脉之内部执行 目录 [源码解析]Oozie来龙去脉之内部执行 0x00 摘要 0x01 Oozie阶段 1.1 ActionStartXCommand 1.2 HiveAc ... 
- mvc5 源码解析1:UrlRoutingModule
		注册在C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG \webconfig中 在该module源码中 我们可以看出注册了application ... 
- 【JVM源码解析】模板解释器解释执行Java字节码指令(上)
		本文由HeapDump性能社区首席讲师鸠摩(马智)授权整理发布 第17章-x86-64寄存器 不同的CPU都能够解释的机器语言的体系称为指令集架构(ISA,Instruction Set Archit ... 
- mvc5 源码解析2-2 mvchandler的执行
		我们从application获取的时候查看stepmanager的实现类 IHttpHandler applicationInstance = HttpApplicationFactory.GetAp ... 
- Celery 源码解析三: Task 对象的实现
		Task 的实现在 Celery 中你会发现有两处,一处位于 celery/app/task.py,这是第一个:第二个位于 celery/task/base.py 中,这是第二个.他们之间是有关系的, ... 
- Celery 源码解析五: 远程控制管理
		今天要聊的话题可能被大家关注得不过,但是对于 Celery 来说确实很有用的功能,曾经我在工作中遇到这类情况,就是我们将所有的任务都放在同一个队列里面,然后有一天突然某个同学的代码写得不对,导致大量的 ... 
- Celery 源码解析六:Events 的实现
		在 Celery 中,除了远程控制之外,还有一个元素可以让我们对分布式中的任务的状态有所掌控,而且从实际意义上来说,这个元素对 Celery 更为重要,这就是在本文中将要说到的 Event. 在 Ce ... 
- 6 admin(注册设计)源码解析、单例模式
		1.单例模式 https://www.cnblogs.com/yuanchenqi/articles/8323452.html 单例模式(Singleton Pattern)是一种常用的软件设计模式, ... 
- [源码解析] 并行分布式框架 Celery 之 worker 启动 (1)
		[源码解析] 并行分布式框架 Celery 之 worker 启动 (1) 目录 [源码解析] 并行分布式框架 Celery 之 worker 启动 (1) 0x00 摘要 0x01 Celery的架 ... 
随机推荐
- Docker镜像服务(二)
			一.Docker镜像介绍 镜像是Docker的三大核心概念之一. Docker运行容器前需要本地存在对应的镜像,如果镜像不存在本地,Docker会尝试先从默认的镜像仓库下载(默认使用Docker Hu ... 
- Setting up the data and the model
			Table of Contents: Setting up the data and the model Data Preprocessing Weight Initialization Batch ... 
- CMakeLists.txt编写常用命令
			目录 1. 设置cmake最小版本 2. 设置项目名称 3. 设置编译目标类型 4. 指定编译包含的源文件 1. 明确指明包含的源文件 2. 搜索指定目录的所有的cpp文件 3. 自定义搜索规则 4. ... 
- JS高阶---闭包面试题
			[面试题1] 答案:The Window 分析: 本案例里,不存在闭包. 条件: .函数嵌套(满足) .内部函数调用外部函数变量(没有) 综上所述,该例中不存在闭包 [面试题2] 答案:My Obje ... 
- c# 第11节 运算符大全
			本节内容: 1:数学运算符 2:赋值运算符 3:关系运算符 4:布尔运算符 5:位运算符 6:其他运算符 1:数学运算符 2:赋值运算符 3:关系运算符 4:布尔运算符 5:位运算符 & 运算 ... 
- 201871010118-唐敬博《面向对象程序设计(java)》第八周学习总结
			博文正文开头格式:(2分) 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.co ... 
- 201871010136-赵艳强《面向对象程序设计(java)》第十五周学习总结
			201871010136-赵艳强<面向对象程序设计JAVA>第十五周实验总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh 这 ... 
- JDOJ 1790: 高精度A-B
			JDOJ 1790: 高精度A-B JDOJ传送门 洛谷 P2142 高精度减法 洛谷传送门 题目描述 高精度减法 输入格式 两个整数a,b(第二个可能比第一个大) 输出格式 结果(是负数要输出负号) ... 
- UML系列
			UML类图:https://www.cnblogs.com/shindo/p/5579191.html UML用例图:https://www.jianshu.com/p/3cde67aed8e9 UM ... 
- es6之后,真的不需要知道原型链了吗?
			3月份几乎每天都能看到面试的人从我身边经过,前段时间同事聊面试话题提到了原型链,顿时激起了我在开始学习前端时很多心酸的回忆.第一次接触js的面向对象思想是在读<js高程设计>(红宝书)的时 ... 
