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的架 ...
随机推荐
- redis报错: redis.exceptions.ResponseError: value is not an integer or out of range
问题描述 今天在使用python的redis客户端时碰到了这样的报错:redis.exceptions.ResponseError: value is not an integer or out of ...
- JavaWeb项目 IDEA+Tomcat+Nginx 部署流程
转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/11375100.html 一:IDEA Maven项目打包 1.修改打包方式 在maven项目的pom文件中, ...
- 10、shell编程+流程控制+分支嵌套
SHELL 编程 shell 是一个命令解释器,侦听用户指令.启动这些指令.将结果返回给用户(交互式的shell) shell 也是一种简单的程序设计语言.利用它可以编写一些系统脚本. ...
- Ubuntu下安装Rabbitmq和golang环境
安装及配置Rabbitmq 1. 安装: sudo apt-get install rabbitmq-server 2. 启动web管理插件 sudo rabbitmq-plugins enable ...
- 2019第一期《python测试开发》课程,10月13号开学
2019第一期<python测试开发>课程,10月13号开学! 主讲老师:上海-悠悠 上课方式:QQ群视频在线教学,方便交流 本期上课时间:10月13号-12月8号,每周六.周日晚上20: ...
- JS高阶---进程与线程
[大纲] 二级大纲: 三级大纲: [主体] (1)进程process 如下所示,两者内存空间相互独立 (2)线程thread (3)图解 注意:有的程序是多进程的,有的时单进程的 (4)单线程与多线程 ...
- 使用 HuTool时候,遇到Cannot add merged region A1:C1 to sheet because it overlaps with an existing merged region (A1:C1).
java.lang.IllegalStateException: Cannot add merged region A1:C1 to sheet because it overlaps with an ...
- Golang调用Python
https://yq.aliyun.com/articles/117329 Python是时髦的机器学习御用开发语言,Golang是大红大紫的新时代后端开发语言.Python很适合让搞算法的写写模型, ...
- NOIP 2005 采药
洛谷 P1048 采药 洛谷传送门 JDOJ 1277: [NOIP2005]采药 T3 JDOJ传送门 Description 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师.为此,他 ...
- Excel引用和数学函数
1.indirect函数--引用函数 indirect 英 [ˌɪndəˈrekt] 美 [ˌɪndəˈrekt] adj. 间接的;附带的;闪烁其词的;拐弯抹角的;迂回的;弯曲的 indirect函 ...