用的是play1.2.7为例进行分析的,启动方式为DEV模式,如有错误请指出.不胜感激
play1.2.7的框架的DEV模式启动过程:
1.项目启动运行play.server.Server中的main方法对框架进行一个初始化,
1.Play.init(root, System.getProperty("play.id", ""));
1.加载静态文件
2.读取配置文件,加载application.conf配置,放到set中,加载日志配置文件
3.Play.classes = new ApplicationClasses(); new 了一个Application classes container. 这个类,就是类的容器
4.log的配制
5.启动方式的读取,获取配置中的项目启动方式是mode还是DEV的方式
6.Main route file
7.默认cookie
8.设置标记Play.initialized = true;
2.new Server(args);
1.设置编码utf-8
2.从配置文件中解析出端口号,进行端口的校对,是否占用
3.ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())
创建一个新的NIO的通道,传递的参数是:两个个可缓存线程池
4.设置启动的bootstrap 参数,例如端口号
5.有重复了上面3/4的步骤一次,上面是http请求的,这次是https请求的方式的,区别是:
bootstrap.setPipelineFactory(new SslHttpServerPipelineFactory()); //https
bootstrap.setPipelineFactory(new HttpServerPipelineFactory()); //http
6.如果启动模式是dev,打印~ Server is up and running 启动完成.等待第一个请求的到达
2.当第一个请求到达框架的时候,进行如下的处理步骤
1.play.server.PlayHandler.NettyInvocation#init
1.设置当前现成的类加载器 Thread.currentThread().setContextClassLoader(Play.classloader);
2.设置当前的Request和Response
Request.current.set(request);
Response.current.set(response);
3.判断是DEV模式启动,热加载修改后的Router
4.根据请求的路径与Route中进行匹配,匹配到了就退出
5.调用去父类的inti();方法
2.play.Invoker.Invocation#init
1.设置当前的类加载器
2.在DEV模式启动时候,
3.链接数据库,13:26:57,402 INFO ~ Application 'project' is now started !
4.再到这个方法:play.Invoker.Invocation#init
5.设置当前的InvocationContext.
3.play.jobs.Job#run
1.进入call() 方法
2.进行init()判断:是否已经初始化成功
3.before();
Thread.currentThread().setContextClassLoader(Play.classloader); //设置类加载器
Play.pluginCollection.beforeInvocation(); //
4.monitor = MonitorFactory.start(getClass().getName()+".doJob()");
jobs.Bootstrap.doJob() 系统启动的定时任务
5.result = doJobWithResult(); 启动了定时任务,加载一些配置文件
6.after(); play.Invoker.Invocation#after
Play.pluginCollection.afterInvocation();
LocalVariablesNamesTracer.checkEmpty(); // detect bugs ....
7.finally中 执行play.Invoker.Invocation#_finally 方法:
1.移除当前线程的中保存的内容
4.跳转进入:play.jobs.JobsPlugin#afterApplicationStart 方法中
1.加载其他的定时任务
有注解@Every On...
2.执行 play.jobs.JobsPlugin#scheduleForCRON 方法
3.使用线程执行executor.schedule((Callable<V>)job, nextDate.getTime() - now.getTime(), TimeUnit.MILLISECONDS);
job.executor = executor;
5.又到达了play.Invoker.Invocation#init
1.又到了play.jobs.Job#run 方法
6.又跳转到了play.plugins.PluginCollection#afterApplicationStart 方法
7.跳转到了 play.Play#start 这个方法的最后,
7.play.Play#detectChanges
8.跳转到了: play.Invoker.Invocation#run
preInit();
if (init()) {
before();
execute();
1.play.server.PlayHandler.NettyInvocation#execute
after();
onSuccess();
1.play.server.PlayHandler.NettyInvocation#onSuccess
2.play.server.PlayHandler#copyResponse
1.根据response状态创建Response对象
2.设置响应头信息nettyResponse.setHeader(SERVER, signature);
3.play.server.PlayHandler#addToResponse
4.play.server.PlayHandler#writeResponse //NIO的操作了
finally {
_finally();
}
}
CSS文件,js文件,附件都是上面同样的过程...............
不想画图了,也不想看类的层次结构了,以后有空在继续修改这个
2018年1月16日14:07:31
Java Framework,欢迎各位前来交流java相关
QQ群:965125360