0%

引导类

引导类

之前简单地介绍了一下Bootstrap和ServerBootstrap两个引导类,先来看一下Bootstrap有哪些方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// 设置EventLoopGroup,EventLoopGroup用来处理所有通道的IO事件
public B group(EventLoopGroup group)

@SuppressWarnings("unchecked")
private B self() {
return (B) this;
}

// 设置通道类型
public B channel(Class<? extends C> channelClass)

// 使用ChannelFactory来设置通道类型
public B channelFactory(io.netty.channel.ChannelFactory<? extends C> channelFactory)

// 设置本地地址,也可以通过bind和connect方法来设定
public B localAddress(SocketAddress localAddress)

/**
* @see #localAddress(SocketAddress)
*/
public B localAddress(int inetPort)

/**
* @see #localAddress(SocketAddress)
*/
public B localAddress(String inetHost, int inetPort)

/**
* @see #localAddress(SocketAddress)
*/
public B localAddress(InetAddress inetHost, int inetPort)

// 设置通道选项,如果value为null,则删除设置对应的属性
public <T> B option(ChannelOption<T> option, T value)

// 设置属性到Channel,如果value为null,则删除对应的属性
public <T> B attr(AttributeKey<T> key, T value)

// 创建一个新的Channel并绑定
public ChannelFuture bind()

public ChannelFuture bind(int inetPort)

public ChannelFuture bind(String inetHost, int inetPort)

public ChannelFuture bind(InetAddress inetHost, int inetPort)

public ChannelFuture bind(SocketAddress localAddress)

// 设置ChannelHandler用于处理请求事件
public B handler(ChannelHandler handler)

// 连接远程通道
public ChannelFuture connect()

public ChannelFuture connect(String inetHost, int inetPort)

public ChannelFuture connect(InetAddress inetHost, int inetPort)

public ChannelFuture connect(SocketAddress remoteAddress)

再看一下ServerBootstrap的方法,其实很多方法是一样的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 设置EventLoopGroup,EventLoopGroup用来处理所有通道的IO事件
public B group(EventLoopGroup group)

public ServerBootstrap group(EventLoopGroup parentGroup, EventLoopGroup childGroup)

@SuppressWarnings("unchecked")
private B self() {
return (B) this;
}

// 设置通道类型
public B channel(Class<? extends C> channelClass)

// 使用ChannelFactory来设置通道类型
public B channelFactory(io.netty.channel.ChannelFactory<? extends C> channelFactory)

// 设置本地地址,也可以通过bind和connect方法来设定
public B localAddress(SocketAddress localAddress)

/**
* @see #localAddress(SocketAddress)
*/
public B localAddress(int inetPort)

/**
* @see #localAddress(SocketAddress)
*/
public B localAddress(String inetHost, int inetPort)

/**
* @see #localAddress(SocketAddress)
*/
public B localAddress(InetAddress inetHost, int inetPort)

// 设置通道选项,如果value为null,则删除设置对应的属性
public <T> B option(ChannelOption<T> option, T value)

// 设置子通道选项
public <T> ServerBootstrap childOption(ChannelOption<T> childOption, T value)

// 设置属性到Channel,如果value为null,则删除对应的属性
public <T> B attr(AttributeKey<T> key, T value)

// 设置子通道属性
public <T> ServerBootstrap childAttr(AttributeKey<T> childKey, T value)

// 设置ChannelHandler用于处理请求事件
public B handler(ChannelHandler handler)

// 设置子ChannelHandler
public ServerBootstrap childHandler(ChannelHandler childHandler)

// 创建一个新的Channel并绑定
public ChannelFuture bind()

public ChannelFuture bind(int inetPort)

public ChannelFuture bind(String inetHost, int inetPort)

public ChannelFuture bind(InetAddress inetHost, int inetPort)

public ChannelFuture bind(SocketAddress localAddress)

欢迎关注我的其它发布渠道