当前位置: 首页 > news >正文

网站建设服务器租赁wordpress 网站静态页面

网站建设服务器租赁,wordpress 网站静态页面,免费做快闪网站,义乌网站建设电话前言#xff1a;已经初始化了NioEventLoopGroup 的boosGroup 和 workerGroup #xff0c;那么ServerBootstrap的作用是干嘛的呢 #xff0c;本文在Spring架构篇–2.7.1 远程通信基础–Netty原理–NioEventLoopGroup 之后继续进行探究 1 首先回顾下 nettt 的使用demo#x…前言已经初始化了NioEventLoopGroup 的boosGroup 和 workerGroup 那么ServerBootstrap的作用是干嘛的呢 本文在Spring架构篇–2.7.1 远程通信基础–Netty原理–NioEventLoopGroup 之后继续进行探究 1 首先回顾下 nettt 的使用demo public class DiscardServer {private int port;public DiscardServer(int port) {this.port port;}public static void main(String[] args) {new DiscardServer(8080).run();}private void run() {NioEventLoopGroup boss new NioEventLoopGroup();NioEventLoopGroup worker new NioEventLoopGroup();try {ServerBootstrap server new ServerBootstrap();server.group(boss,worker).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializerSocketChannel() {Overrideprotected void initChannel(SocketChannel ch) throws Exception {ch.pipeline().addLast(new DiscardServerHandler());}}).option(ChannelOption.SO_BACKLOG,128).childOption(ChannelOption.SO_KEEPALIVE,true);ChannelFuture f server.bind(this.port).sync();System.out.println(8080服务已启动);f.channel().closeFuture().sync();} catch (InterruptedException e) {e.printStackTrace();} finally {boss.shutdownGracefully();worker.shutdownGracefully();}} }可以看到ServerBootstrap 的对象做了一系列的配置后最终 通过 bind(this.port).sync() 进行启动 2 ServerBootstrap 类 2.1 new ServerBootstrap() 工作内容 public class ServerBootstrap extends AbstractBootstrapServerBootstrap, ServerChannelprivate static final InternalLogger logger InternalLoggerFactory.getInstance(ServerBootstrap.class); private final MapChannelOption?, Object childOptions new LinkedHashMap(); private final MapAttributeKey?, Object childAttrs new ConcurrentHashMap(); // ServerBootstrap 对象赋值给 config private final ServerBootstrapConfig config new ServerBootstrapConfig(this); private volatile EventLoopGroup childGroup; private volatile ChannelHandler childHandler;public ServerBootstrap() { }AbstractBootstrap 类 public abstract class AbstractBootstrapB extends AbstractBootstrapB, C, C extends Channel implements Cloneable {static final Map.EntryChannelOption?, Object[] EMPTY_OPTION_ARRAY new Map.Entry[0];static final Map.EntryAttributeKey?, Object[] EMPTY_ATTRIBUTE_ARRAY new Map.Entry[0];volatile EventLoopGroup group;private volatile ChannelFactory? extends C channelFactory;private volatile SocketAddress localAddress;private final MapChannelOption?, Object options new LinkedHashMap();private final MapAttributeKey?, Object attrs new ConcurrentHashMap();private volatile ChannelHandler handler;AbstractBootstrap() {}}可以看到ServerBootstrap 继承了AbstractBootstrap类当new ServerBootstrap() 时对ServerBootstrap和AbstractBootstrap类都通过无参的构造方法完成了这两个类的对象实例化可以看到ServerBootstrap和AbstractBootstrap这两个类的属性非常相似实际上 ServerBootstrap 用来放NioEventLoopGroup 工作线程的数据AbstractBootstrap 用来放 boss 线程的数据可以看到这里只是进行了初始化里面的属性都还没有进行赋值两个对象的属性值都是默认值 2.2 ServerBootstrap AbstractBootstrap 的属性赋值 2.2.1 server.group(boss,worker)完成对父类和子类 NioEventLoopGroup对象进行赋值 ServerBootstrap 类的 group 方法 public ServerBootstrap group(EventLoopGroup parentGroup, EventLoopGroup childGroup) { // 父类AbstractBootstrap 的EventLoopGroup 赋值super.group(parentGroup);if (this.childGroup ! null) {throw new IllegalStateException(childGroup set already);} else { // 子类的EventLoopGroup volatile EventLoopGroup group 赋值;this.childGroup (EventLoopGroup)ObjectUtil.checkNotNull(childGroup, childGroup);return this;} }super.group(parentGroup); 父类对象的赋值 AbstractBootstrap 的group 方法 static final Map.EntryChannelOption?, Object[] EMPTY_OPTION_ARRAY new Map.Entry[0]; static final Map.EntryAttributeKey?, Object[] EMPTY_ATTRIBUTE_ARRAY new Map.Entry[0]; volatile EventLoopGroup group; private volatile ChannelFactory? extends C channelFactory; private volatile SocketAddress localAddress; private final MapChannelOption?, Object options new LinkedHashMap(); private final MapAttributeKey?, Object attrs new ConcurrentHashMap(); private volatile ChannelHandler handler;AbstractBootstrap() { } // 父类的EventLoopGroup 赋值 AbstractBootstrap(AbstractBootstrapB, C bootstrap) {this.group bootstrap.group;this.channelFactory bootstrap.channelFactory;this.handler bootstrap.handler;this.localAddress bootstrap.localAddress;synchronized(bootstrap.options) {this.options.putAll(bootstrap.options);}this.attrs.putAll(bootstrap.attrs); } // 父类group AbstractBootstrap 类 对象的赋值 volatile EventLoopGroup group; public B group(EventLoopGroup group) {ObjectUtil.checkNotNull(group, group);if (this.group ! null) {throw new IllegalStateException(group set already);} else {this.group group;return this.self();} }2.2.2 channel(NioServerSocketChannel.class) AbstractBootstrap 类 private volatile ChannelFactory? extends C channelFactory; 对象赋值 调用 AbstractBootstrap 类中 channel(NioServerSocketChannel.class) 方法 public B channel(Class? extends C channelClass) { // 先使用ReflectiveChannelFactory 反射工厂类对传入的channel 进行包装 // 调用channelFactory 对父类AbstractBootstrap 对象channel 工厂进行初始化return this.channelFactory((io.netty.channel.ChannelFactory)(new ReflectiveChannelFactory((Class)ObjectUtil.checkNotNull(channelClass, channelClass)))); } // 工厂方法调用 public B channelFactory(io.netty.channel.ChannelFactory? extends C channelFactory) {return this.channelFactory((ChannelFactory)channelFactory); } // AbstractBootstrap 对象属性的初始化Deprecated public B channelFactory(ChannelFactory? extends C channelFactory) {ObjectUtil.checkNotNull(channelFactory, channelFactory);if (this.channelFactory ! null) {throw new IllegalStateException(channelFactory set already);} else {this.channelFactory channelFactory;return this.self();} } // channel类反射工厂的创建 public class ReflectiveChannelFactoryT extends Channel implements ChannelFactoryT {private final Constructor? extends T constructor;public ReflectiveChannelFactory(Class? extends T clazz) {ObjectUtil.checkNotNull(clazz, clazz);try {// 赋值 NioServerSocketChannel 类的构造器使得在需要实例化channel 对象的时候// 可以通过改channel 的无参构造方法完成对象实例化this.constructor clazz.getConstructor();} catch (NoSuchMethodException var3) {throw new IllegalArgumentException(Class StringUtil.simpleClassName(clazz) does not have a public non-arg constructor, var3);}}// 对当前的channel 通过反射调用channel 对象的无参构造方法public T newChannel() {try {return (Channel)this.constructor.newInstance();} catch (Throwable var2) {throw new ChannelException(Unable to create Channel from class this.constructor.getDeclaringClass(), var2);}}public String toString() {return StringUtil.simpleClassName(ReflectiveChannelFactory.class) ( StringUtil.simpleClassName(this.constructor.getDeclaringClass()) .class);} }通过channle 方法可以看到完成了对父类AbstractBootstrap 对象 channel 工厂的属性初始化;在真正需要NioServerSocketChannel 对象的时候可以通过ReflectiveChannelFactory的 newChannel() 方法完成对 NioServerSocketChannel 无参的构造方法调用从而实例化一个NioServerSocketChannel的对象出来 2.2.3 childHandler(new ChannelInitializer() { }) 调用ServerBootstrap 类中 childHandler(ChannelHandler childHandler) 方法 public ServerBootstrap childHandler(ChannelHandler childHandler) {this.childHandler (ChannelHandler)ObjectUtil.checkNotNull(childHandler, childHandler);return this; }对ServerBootstrap 事件处理属性private volatile ChannelHandler childHandler; 赋值 2.2.4 option(ChannelOption.SO_BACKLOG,128) AbstractBootstrap 的option 方法对父类AbstractBootstrap 对象options 顺序赋值 // private final MapChannelOption?, Object options new LinkedHashMap(); 属性赋值 public T B option(ChannelOptionT option, T value) {ObjectUtil.checkNotNull(option, option);synchronized(this.options) {if (value null) {this.options.remove(option);} else {this.options.put(option, value);}}return this.self(); }2.2.5 childOption(ChannelOption.SO_KEEPALIVE,true) ServerBootstrap 类中的childOption 方法 // private final MapChannelOption?, Object childOptions new LinkedHashMap(); 赋值 public T ServerBootstrap childOption(ChannelOptionT childOption, T value) {ObjectUtil.checkNotNull(childOption, childOption);synchronized(this.childOptions) {if (value null) {this.childOptions.remove(childOption);} else {this.childOptions.put(childOption, value);}return this;} }可以看到上面的这些步骤先是对ServerBootstrap 和AbstractBootstrap 对象实例化 然后为其属性进行赋值操作将NioEventLoopGroup worker new NioEventLoopGroup(); 的worker 对象对其ServerBootstrap 的EventLoopGroup childGroup 赋值然后将 NioEventLoopGroup boss new NioEventLoopGroup(); 对象对其AbstractBootstrap 的 volatile EventLoopGroup group 属性赋值对AbstractBootstrap 的channel 工厂类属性 private volatile ChannelFactory? extends C channelFactory; 赋值为NioServerSocketChannel 对象工厂对AbstractBootstrap 的options 属性赋值keyChannelOption.SO_BACKLOG, value 128;对ServerBootstrap 的childOptions 属性赋值keyChannelOption.SO_KEEPALIVE, value true 以上步骤都是初始化和赋值操作没有socket 端口的绑定以及时间监听的处理那么这些处理就只剩在bind(this.port).sync() 进行处理由于bind 方法嵌套较深所有放在下一篇继续探究
文章转载自:
http://www.morning.qrndh.cn.gov.cn.qrndh.cn
http://www.morning.2d1bl5.cn.gov.cn.2d1bl5.cn
http://www.morning.gryzk.cn.gov.cn.gryzk.cn
http://www.morning.klcdt.cn.gov.cn.klcdt.cn
http://www.morning.qdrhf.cn.gov.cn.qdrhf.cn
http://www.morning.wjlbb.cn.gov.cn.wjlbb.cn
http://www.morning.jfxth.cn.gov.cn.jfxth.cn
http://www.morning.nafdmx.cn.gov.cn.nafdmx.cn
http://www.morning.rmpkn.cn.gov.cn.rmpkn.cn
http://www.morning.xkhxl.cn.gov.cn.xkhxl.cn
http://www.morning.wnhgb.cn.gov.cn.wnhgb.cn
http://www.morning.rnpnn.cn.gov.cn.rnpnn.cn
http://www.morning.lonlie.com.gov.cn.lonlie.com
http://www.morning.kkqgf.cn.gov.cn.kkqgf.cn
http://www.morning.yxzfl.cn.gov.cn.yxzfl.cn
http://www.morning.mbmtn.cn.gov.cn.mbmtn.cn
http://www.morning.xzqzd.cn.gov.cn.xzqzd.cn
http://www.morning.mxhgy.cn.gov.cn.mxhgy.cn
http://www.morning.kjcll.cn.gov.cn.kjcll.cn
http://www.morning.jltmb.cn.gov.cn.jltmb.cn
http://www.morning.zlqyj.cn.gov.cn.zlqyj.cn
http://www.morning.lmqfq.cn.gov.cn.lmqfq.cn
http://www.morning.qfrmy.cn.gov.cn.qfrmy.cn
http://www.morning.cjqcx.cn.gov.cn.cjqcx.cn
http://www.morning.zlkps.cn.gov.cn.zlkps.cn
http://www.morning.znlhc.cn.gov.cn.znlhc.cn
http://www.morning.fqhbt.cn.gov.cn.fqhbt.cn
http://www.morning.dmcxh.cn.gov.cn.dmcxh.cn
http://www.morning.rqnhf.cn.gov.cn.rqnhf.cn
http://www.morning.dsgdt.cn.gov.cn.dsgdt.cn
http://www.morning.ljzqb.cn.gov.cn.ljzqb.cn
http://www.morning.kpxnz.cn.gov.cn.kpxnz.cn
http://www.morning.jcypk.cn.gov.cn.jcypk.cn
http://www.morning.klyzg.cn.gov.cn.klyzg.cn
http://www.morning.bbgn.cn.gov.cn.bbgn.cn
http://www.morning.lpmdy.cn.gov.cn.lpmdy.cn
http://www.morning.sdktr.com.gov.cn.sdktr.com
http://www.morning.jqswf.cn.gov.cn.jqswf.cn
http://www.morning.rwzmz.cn.gov.cn.rwzmz.cn
http://www.morning.alwpc.cn.gov.cn.alwpc.cn
http://www.morning.rdzgm.cn.gov.cn.rdzgm.cn
http://www.morning.jspnx.cn.gov.cn.jspnx.cn
http://www.morning.xrmwc.cn.gov.cn.xrmwc.cn
http://www.morning.dkqr.cn.gov.cn.dkqr.cn
http://www.morning.qsszq.cn.gov.cn.qsszq.cn
http://www.morning.xsrnr.cn.gov.cn.xsrnr.cn
http://www.morning.yrnyz.cn.gov.cn.yrnyz.cn
http://www.morning.wqbzt.cn.gov.cn.wqbzt.cn
http://www.morning.bmmyx.cn.gov.cn.bmmyx.cn
http://www.morning.qxkcx.cn.gov.cn.qxkcx.cn
http://www.morning.jkszt.cn.gov.cn.jkszt.cn
http://www.morning.ypcbm.cn.gov.cn.ypcbm.cn
http://www.morning.byywt.cn.gov.cn.byywt.cn
http://www.morning.jzbjx.cn.gov.cn.jzbjx.cn
http://www.morning.xprq.cn.gov.cn.xprq.cn
http://www.morning.dywgl.cn.gov.cn.dywgl.cn
http://www.morning.zczkm.cn.gov.cn.zczkm.cn
http://www.morning.fgxws.cn.gov.cn.fgxws.cn
http://www.morning.lbbgf.cn.gov.cn.lbbgf.cn
http://www.morning.bpncd.cn.gov.cn.bpncd.cn
http://www.morning.kqlrl.cn.gov.cn.kqlrl.cn
http://www.morning.tfrmx.cn.gov.cn.tfrmx.cn
http://www.morning.pyncx.cn.gov.cn.pyncx.cn
http://www.morning.pqfbk.cn.gov.cn.pqfbk.cn
http://www.morning.cffwm.cn.gov.cn.cffwm.cn
http://www.morning.qbkw.cn.gov.cn.qbkw.cn
http://www.morning.qckwj.cn.gov.cn.qckwj.cn
http://www.morning.youyouling.cn.gov.cn.youyouling.cn
http://www.morning.xlndf.cn.gov.cn.xlndf.cn
http://www.morning.sypzg.cn.gov.cn.sypzg.cn
http://www.morning.lqrpk.cn.gov.cn.lqrpk.cn
http://www.morning.frpm.cn.gov.cn.frpm.cn
http://www.morning.lcwhn.cn.gov.cn.lcwhn.cn
http://www.morning.pjwfs.cn.gov.cn.pjwfs.cn
http://www.morning.zfqr.cn.gov.cn.zfqr.cn
http://www.morning.ltkms.cn.gov.cn.ltkms.cn
http://www.morning.dztp.cn.gov.cn.dztp.cn
http://www.morning.jrkzk.cn.gov.cn.jrkzk.cn
http://www.morning.litao4.cn.gov.cn.litao4.cn
http://www.morning.kxrld.cn.gov.cn.kxrld.cn
http://www.tj-hxxt.cn/news/275601.html

相关文章:

  • 美的集团网站建设网站建设费会计处理
  • 图书馆网站建设报告wordpress和淘宝客程序
  • 国外高清人像图片素材网站免费域名试用注册网站
  • qq免费注册网站高端网站制作的公司
  • 微网站模板在线制作上海闵行区邮编
  • 全球热门网站排名之前做的网站推广怎么删除
  • 实训课建设网站步骤安徽休宁建设厅网站
  • 政务网站建设标准做一个微信小程序多少钱
  • 要建网站怎么做什么站做咨询网站好
  • 建立一个网站大约要多少钱wordpress做导语
  • 北京延庆城乡建设部网站首页电子商务网站数据库建设
  • 广州网站建设公司嘉御做网站需要学习哪些
  • 做的ASP网站手机怎么给网站做 360快照
  • 创建网站商城惠州seo公司
  • 网站制作是什么公司好看的网站建设
  • 清远做网站的公司设计新颖的网站建设
  • 上海网站营销怎么样网站建设一定要买数据盘吗
  • wap网站要花多少钱平台企业是什么意思
  • 城建网站论坛 建设北京住房与城乡建设厅网站首页
  • 江苏炒股配资网站开发晨阳seo顾问
  • 重庆哪里可以做公司网站网站开发 哪些技术
  • 局机关门户网站建设情况汇报优秀网站开发
  • ui设计方向网站建设目标做网站去哪里投放广告
  • 湛江网站制作推荐城乡住房和城乡建设部网站首页
  • 网站设计资源线上推广是什么意思
  • 网站开发资质电脑app制作教程
  • 苏州网站开发公司哪里济南兴田德润简介wordpress 网站上传到服务器
  • 多个网站给一个网站推广建设网站的机构
  • 做2手车网站需要多少钱启东市住房城乡建设局网站
  • 永久免费建站空间汕头市公司网站建设多少钱