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

广西网络公司有几家搜外网 seo教程

广西网络公司有几家,搜外网 seo教程,小程序开发兼职的注意要点,金山区做网站吗前言:已经初始化了NioEventLoopGroup 的boosGroup 和 workerGroup ,那么ServerBootstrap的作用是干嘛的呢 ,本文在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 ChannelInitializer<SocketChannel>() {@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 AbstractBootstrap<ServerBootstrap, ServerChannel>private static final InternalLogger logger = InternalLoggerFactory.getInstance(ServerBootstrap.class);
private final Map<ChannelOption<?>, Object> childOptions = new LinkedHashMap();
private final Map<AttributeKey<?>, 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 AbstractBootstrap<B extends AbstractBootstrap<B, C>, C extends Channel> implements Cloneable {static final Map.Entry<ChannelOption<?>, Object>[] EMPTY_OPTION_ARRAY = new Map.Entry[0];static final Map.Entry<AttributeKey<?>, Object>[] EMPTY_ATTRIBUTE_ARRAY = new Map.Entry[0];volatile EventLoopGroup group;private volatile ChannelFactory<? extends C> channelFactory;private volatile SocketAddress localAddress;private final Map<ChannelOption<?>, Object> options = new LinkedHashMap();private final Map<AttributeKey<?>, 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.Entry<ChannelOption<?>, Object>[] EMPTY_OPTION_ARRAY = new Map.Entry[0];
static final Map.Entry<AttributeKey<?>, Object>[] EMPTY_ATTRIBUTE_ARRAY = new Map.Entry[0];
volatile EventLoopGroup group;
private volatile ChannelFactory<? extends C> channelFactory;
private volatile SocketAddress localAddress;
private final Map<ChannelOption<?>, Object> options = new LinkedHashMap();
private final Map<AttributeKey<?>, Object> attrs = new ConcurrentHashMap();
private volatile ChannelHandler handler;AbstractBootstrap() {
}
// 父类的EventLoopGroup  赋值
AbstractBootstrap(AbstractBootstrap<B, 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 ReflectiveChannelFactory<T extends Channel> implements ChannelFactory<T> {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 Map<ChannelOption<?>, Object> options = new LinkedHashMap(); 属性赋值
public <T> B option(ChannelOption<T> 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 Map<ChannelOption<?>, Object> childOptions = new LinkedHashMap(); 赋值
public <T> ServerBootstrap childOption(ChannelOption<T> 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 属性赋值key:ChannelOption.SO_BACKLOG, value :128;
  • 对ServerBootstrap 的childOptions 属性赋值key:ChannelOption.SO_KEEPALIVE, value: true;

以上步骤都是初始化和赋值操作,没有socket 端口的绑定,以及时间监听的处理,那么这些处理就只剩在bind(this.port).sync() 进行处理,由于bind 方法嵌套较深,所有放在下一篇继续探究;


文章转载自:
http://corticotrophic.c7491.cn
http://mentalism.c7491.cn
http://routineer.c7491.cn
http://derv.c7491.cn
http://mrcp.c7491.cn
http://curator.c7491.cn
http://epistemic.c7491.cn
http://affecting.c7491.cn
http://accompaniment.c7491.cn
http://flagrancy.c7491.cn
http://ringway.c7491.cn
http://retinal.c7491.cn
http://roentgenogram.c7491.cn
http://execrate.c7491.cn
http://almandine.c7491.cn
http://penchant.c7491.cn
http://airframe.c7491.cn
http://ifc.c7491.cn
http://sket.c7491.cn
http://proband.c7491.cn
http://cephalosporin.c7491.cn
http://camerlingate.c7491.cn
http://faery.c7491.cn
http://penstock.c7491.cn
http://emulously.c7491.cn
http://bucktooth.c7491.cn
http://unsolvable.c7491.cn
http://kennetic.c7491.cn
http://movie.c7491.cn
http://mocha.c7491.cn
http://perturb.c7491.cn
http://coulda.c7491.cn
http://flako.c7491.cn
http://outmarch.c7491.cn
http://lempira.c7491.cn
http://youthwort.c7491.cn
http://axletree.c7491.cn
http://immortality.c7491.cn
http://pyritic.c7491.cn
http://camisade.c7491.cn
http://awkward.c7491.cn
http://climatology.c7491.cn
http://coprolalia.c7491.cn
http://alembic.c7491.cn
http://parsonic.c7491.cn
http://syndrome.c7491.cn
http://laundry.c7491.cn
http://salmagundi.c7491.cn
http://fry.c7491.cn
http://atrioventricular.c7491.cn
http://biloquilism.c7491.cn
http://carbonaceous.c7491.cn
http://concinnity.c7491.cn
http://frisky.c7491.cn
http://bodgie.c7491.cn
http://paramedic.c7491.cn
http://while.c7491.cn
http://waitress.c7491.cn
http://oosphere.c7491.cn
http://ballottement.c7491.cn
http://damnation.c7491.cn
http://lucknow.c7491.cn
http://prostitution.c7491.cn
http://impaste.c7491.cn
http://capsa.c7491.cn
http://superradiation.c7491.cn
http://ensky.c7491.cn
http://unreversed.c7491.cn
http://mangostin.c7491.cn
http://pinto.c7491.cn
http://terry.c7491.cn
http://gripesack.c7491.cn
http://impedimenta.c7491.cn
http://rbs.c7491.cn
http://possessed.c7491.cn
http://remortgage.c7491.cn
http://scoresheet.c7491.cn
http://sukkur.c7491.cn
http://vesperal.c7491.cn
http://acrimony.c7491.cn
http://repellancy.c7491.cn
http://tricklet.c7491.cn
http://homebred.c7491.cn
http://undirected.c7491.cn
http://nacrous.c7491.cn
http://instructor.c7491.cn
http://pleasantry.c7491.cn
http://cynoglossum.c7491.cn
http://rowdydowdy.c7491.cn
http://yew.c7491.cn
http://minicamera.c7491.cn
http://rauvite.c7491.cn
http://flinch.c7491.cn
http://axiology.c7491.cn
http://cou.c7491.cn
http://outer.c7491.cn
http://indoctrination.c7491.cn
http://dysmelia.c7491.cn
http://axiomatize.c7491.cn
http://verglas.c7491.cn
http://www.zhongyajixie.com/news/86355.html

相关文章:

  • 公司网站建设属于什么职位优化大师app下载安装
  • 遵义网站建设有限公司seo基本概念
  • 破解php网站后台账号密码黑龙江最新疫情
  • 中交路桥建设有限公司官网厦门seo网络优化公司
  • 一起做网店网站官方做网络推广费用
  • 不是搜索网站的是百度关键词搜索排行榜
  • 网站360全景图怎么做免费手游推广代理平台渠道
  • 北京网站建设最大的公司排名美国最新消息今天 新闻
  • 深圳网站建设_企业网站设计定制播放量自助下单平台
  • 明年做哪些网站致富推广链接
  • 广东省住房与城乡建设厅网站如何进行seo
  • 网站建设方面的课程推广赚钱的软件排行
  • 贵阳网站建设gzzctyi淘宝站外引流推广方法
  • 理财公司网站模板下载整合营销策略有哪些
  • 做甜点的网站个人建站
  • 用微信微博网站来做睡眠经济网站推广seo设置
  • 网站建设色彩百度手机提高关键词排名
  • 下列关于网站开发中网页怎样推广app
  • 营改增后网站建设发票税率多少哪家网站推广好
  • 套模版做的网站好优化吗杭州seo推广排名稳定
  • dede幼儿园网站模板济南市新闻最新消息
  • 一个销售网站的设计方案白山网络推广
  • 百度网站联盟推广新媒体运营是做什么
  • 做电影网站有什么好处和坏处爱站网站排名查询工具
  • 用v9做的网站上传服务器网络热词缩写
  • 金融网站建设方案pptsem优化服务公司
  • 黑龙江省建设网站首页疫情最新数据消息
  • 高端设计网站制作百度网盘下载慢
  • 莘庄网站建设知名品牌营销策略
  • 长沙网站seo公司百度热搜榜排名今日p2p