Jetty的架构代码分析

kafka--- consumer 消费消息

LD is tigger forever,CG are not brothers forever, throw the pot and shine forever.
Modesty is not false, solid is not naive, treacherous but not deceitful, stay with good people, and stay away from poor people.
talk is cheap, show others the code and KPI, Keep progress,make a better result.
Survive during the day and develop at night。

目录

概 述

包下载:
http://download.eclipse.org/jetty/
包结构:

源码下载:
https://github.com/eclipse/jetty.project/releases

代码模块:

启动方式:

start.ini配置文件

这个默认配置决定启动了哪些模块以及启动的顺序。
这些配置文件的顺序不能错,比如若是将jetty-deploy.xml置于最下面将导致jetty-webapps无法初始化的错误。简单介绍下几个配置的作用:

2)jetty.xml

该配制文件就对应了server类,管理着connection,thread pool,handler等。

3)deploy.xml

该配置文件对应于上篇博客描述的deployService,在jetty中就是deployManager,部署管理器,因此如果这玩意位置错了,下面的webapps.xml自然就报错了

4)webapps.xml
war包的部署器,webappcontext便于基于此生产出来的。

start.jar启动原理

1、解析命令行参数:
截取源码里jetty-start模块中的Main类的main函数调用解析启动命令的方法(命令行方式启动 jetty 的入口)小块:
public List expandCommandLine(String[] args) throws Exception
{
List arguments = new ArrayList();
// add the command line args and look for start.ini args
boolean ini = false;
for (String arg : args)
{
if (arg.startsWith("–ini=") || arg.equals("–ini"))
{
ini = true;
if (arg.length() > 6)
{
arguments.addAll(loadStartIni(new File(arg.substring(6))));
}
}
else if (arg.startsWith("–config="))
{
_startConfig = arg.substring(9);
}
else
{
arguments.add(arg);
}
}
// if no non-option inis, add the start.ini and start.d
if (!ini)
{
arguments.addAll(0,parseStartIniFiles());
}
return arguments;
}

2、定位加载资源并依据配置文件反射调用相应的类
同样截取jetty-xml里的一块源代码:

// For all arguments, load properties or parse XMLs
XmlConfiguration last = null;
Object[] obj = new Object[args.length];
for (int i = 0; i < args.length; i++)
{
if (args[i].toLowerCase(Locale.ENGLISH).endsWith(".properties"))
{
properties.load(Resource.newResource(args[i]).getInputStream());
}
else
{
XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(args[i]).getURL());
if (last != null)
configuration.getIdMap().putAll(last.getIdMap());
if (properties.size() > 0)
{
Map<String, String> props = new HashMap<String, String>();
for (Object key : properties.keySet())
{
props.put(key.toString(),String.valueOf(properties.get(key)));
}
configuration.getProperties().putAll(props);
}
obj[i] = configuration.configure();
last = configuration;
}
}

分为两步,先是依据xm描述的内容依次解析xml并处理逻辑,期间会生成很多个实例,如果实例实现了LifeCycle接口再依次调用start方法,因此server就是在此被start起来了。

例子:

java -jar start.jar --list-options 命令查找Server,jsp,jmx,resources,websocket,ext,plus,annotations这些对应的模块有:

java -jar start.jar --list-options

小结

Jetty 代码的分析:

参考资料和推荐阅读

1.链接: 参考资料.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值