public abstract class AbstractBootstrap<B extends AbstractBootstrap<B,C>,C extends Channel>
extends java.lang.Object
implements java.lang.Cloneable
AbstractBootstrap
is a helper class that makes it easy to bootstrap a Channel
. It support
method-chaining to provide an easy way to configure the AbstractBootstrap
.
When not used in a ServerBootstrap
context, the bind()
methods are useful for connectionless
transports such as datagram (UDP).
限定符和类型 | 方法和说明 |
---|---|
<T> B |
attr(AttributeKey<T> key,
T value)
Allow to specify an initial attribute of the newly created
Channel . |
ChannelFuture |
bind()
Create a new
Channel and bind it. |
ChannelFuture |
bind(java.net.InetAddress inetHost,
int inetPort)
Create a new
Channel and bind it. |
ChannelFuture |
bind(int inetPort)
Create a new
Channel and bind it. |
ChannelFuture |
bind(java.net.SocketAddress localAddress)
Create a new
Channel and bind it. |
ChannelFuture |
bind(java.lang.String inetHost,
int inetPort)
Create a new
Channel and bind it. |
B |
channel(java.lang.Class<? extends C> channelClass)
The
Class which is used to create Channel instances from. |
B |
channelFactory(ChannelFactory<? extends C> channelFactory)
已过时。
Use
channelFactory(io.netty.channel.ChannelFactory) instead. |
B |
channelFactory(ChannelFactory<? extends C> channelFactory)
|
abstract B |
clone()
Returns a deep clone of this bootstrap which has the identical configuration.
|
abstract AbstractBootstrapConfig<B,C> |
config()
Returns the
AbstractBootstrapConfig object that can be used to obtain the current config
of the bootstrap. |
B |
extensionsClassLoader(java.lang.ClassLoader classLoader)
Load
ChannelInitializerExtension s using the given class loader. |
EventLoopGroup |
group()
已过时。
Use
config() instead. |
B |
group(EventLoopGroup group)
The
EventLoopGroup which is used to handle all the events for the to-be-created
Channel |
B |
handler(ChannelHandler handler)
the
ChannelHandler to use for serving the requests. |
B |
localAddress(java.net.InetAddress inetHost,
int inetPort) |
B |
localAddress(int inetPort) |
B |
localAddress(java.net.SocketAddress localAddress)
The
SocketAddress which is used to bind the local "end" to. |
B |
localAddress(java.lang.String inetHost,
int inetPort) |
<T> B |
option(ChannelOption<T> option,
T value)
Allow to specify a
ChannelOption which is used for the Channel instances once they got
created. |
ChannelFuture |
register()
|
java.lang.String |
toString() |
B |
validate()
Validate all the parameters.
|
public B group(EventLoopGroup group)
EventLoopGroup
which is used to handle all the events for the to-be-created
Channel
public B channel(java.lang.Class<? extends C> channelClass)
Class
which is used to create Channel
instances from.
You either use this or channelFactory(io.netty.channel.ChannelFactory)
if your
Channel
implementation has no no-args constructor.@Deprecated public B channelFactory(ChannelFactory<? extends C> channelFactory)
channelFactory(io.netty.channel.ChannelFactory)
instead.public B channelFactory(ChannelFactory<? extends C> channelFactory)
ChannelFactory
which is used to create Channel
instances from
when calling bind()
. This method is usually only used if channel(Class)
is not working for you because of some more complex needs. If your Channel
implementation
has a no-args constructor, its highly recommend to just use channel(Class)
to
simplify your code.public B localAddress(java.net.SocketAddress localAddress)
SocketAddress
which is used to bind the local "end" to.public B localAddress(int inetPort)
public B localAddress(java.lang.String inetHost, int inetPort)
public B localAddress(java.net.InetAddress inetHost, int inetPort)
public <T> B option(ChannelOption<T> option, T value)
ChannelOption
which is used for the Channel
instances once they got
created. Use a value of null
to remove a previous set ChannelOption
.public <T> B attr(AttributeKey<T> key, T value)
Channel
. If the value
is
null
, the attribute of the specified key
is removed.public B extensionsClassLoader(java.lang.ClassLoader classLoader)
ChannelInitializerExtension
s using the given class loader.
By default, the extensions will be loaded by the same class loader that loaded this bootstrap class.
classLoader
- The class loader to use for loading ChannelInitializerExtension
s.public B validate()
public abstract B clone()
Channel
s with similar settings. Please note that this method does not clone the
EventLoopGroup
deeply but shallowly, making the group a shared resource.clone
在类中 java.lang.Object
public ChannelFuture register()
public ChannelFuture bind()
Channel
and bind it.public ChannelFuture bind(int inetPort)
Channel
and bind it.public ChannelFuture bind(java.lang.String inetHost, int inetPort)
Channel
and bind it.public ChannelFuture bind(java.net.InetAddress inetHost, int inetPort)
Channel
and bind it.public ChannelFuture bind(java.net.SocketAddress localAddress)
Channel
and bind it.public B handler(ChannelHandler handler)
ChannelHandler
to use for serving the requests.@Deprecated public final EventLoopGroup group()
config()
instead.EventLoopGroup
or null
if non is configured yet.public abstract AbstractBootstrapConfig<B,C> config()
AbstractBootstrapConfig
object that can be used to obtain the current config
of the bootstrap.public java.lang.String toString()
toString
在类中 java.lang.Object