Package io.netty.bootstrap
Class AbstractBootstrap<B extends AbstractBootstrap<B,C>,C extends Channel>
- java.lang.Object
-
- io.netty.bootstrap.AbstractBootstrap<B,C>
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
Bootstrap
,ServerBootstrap
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 aChannel
. It support method-chaining to provide an easy way to configure theAbstractBootstrap
.When not used in a
ServerBootstrap
context, thebind()
methods are useful for connectionless transports such as datagram (UDP).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T> B
attr(AttributeKey<T> key, T value)
Allow to specify an initial attribute of the newly createdChannel
.ChannelFuture
bind()
Create a newChannel
and bind it.ChannelFuture
bind(int inetPort)
Create a newChannel
and bind it.ChannelFuture
bind(java.lang.String inetHost, int inetPort)
Create a newChannel
and bind it.ChannelFuture
bind(java.net.InetAddress inetHost, int inetPort)
Create a newChannel
and bind it.ChannelFuture
bind(java.net.SocketAddress localAddress)
Create a newChannel
and bind it.B
channel(java.lang.Class<? extends C> channelClass)
TheClass
which is used to createChannel
instances from.B
channelFactory(ChannelFactory<? extends C> channelFactory)
Deprecated.UsechannelFactory(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 theAbstractBootstrapConfig
object that can be used to obtain the current config of the bootstrap.B
extensionsClassLoader(java.lang.ClassLoader classLoader)
LoadChannelInitializerExtension
s using the given class loader.EventLoopGroup
group()
Deprecated.Useconfig()
instead.B
group(EventLoopGroup group)
TheEventLoopGroup
which is used to handle all the events for the to-be-createdChannel
B
handler(ChannelHandler handler)
theChannelHandler
to use for serving the requests.B
localAddress(int inetPort)
B
localAddress(java.lang.String inetHost, int inetPort)
B
localAddress(java.net.InetAddress inetHost, int inetPort)
B
localAddress(java.net.SocketAddress localAddress)
TheSocketAddress
which is used to bind the local "end" to.<T> B
option(ChannelOption<T> option, T value)
Allow to specify aChannelOption
which is used for theChannel
instances once they got created.ChannelFuture
register()
java.lang.String
toString()
B
validate()
Validate all the parameters.
-
-
-
Method Detail
-
group
public B group(EventLoopGroup group)
TheEventLoopGroup
which is used to handle all the events for the to-be-createdChannel
-
channel
public B channel(java.lang.Class<? extends C> channelClass)
TheClass
which is used to createChannel
instances from. You either use this orchannelFactory(io.netty.channel.ChannelFactory)
if yourChannel
implementation has no no-args constructor.
-
channelFactory
@Deprecated public B channelFactory(ChannelFactory<? extends C> channelFactory)
Deprecated.UsechannelFactory(io.netty.channel.ChannelFactory)
instead.
-
channelFactory
public B channelFactory(ChannelFactory<? extends C> channelFactory)
ChannelFactory
which is used to createChannel
instances from when callingbind()
. This method is usually only used ifchannel(Class)
is not working for you because of some more complex needs. If yourChannel
implementation has a no-args constructor, its highly recommend to just usechannel(Class)
to simplify your code.
-
localAddress
public B localAddress(java.net.SocketAddress localAddress)
TheSocketAddress
which is used to bind the local "end" to.
-
localAddress
public B localAddress(int inetPort)
- See Also:
localAddress(SocketAddress)
-
localAddress
public B localAddress(java.lang.String inetHost, int inetPort)
- See Also:
localAddress(SocketAddress)
-
localAddress
public B localAddress(java.net.InetAddress inetHost, int inetPort)
- See Also:
localAddress(SocketAddress)
-
option
public <T> B option(ChannelOption<T> option, T value)
Allow to specify aChannelOption
which is used for theChannel
instances once they got created. Use a value ofnull
to remove a previous setChannelOption
.
-
attr
public <T> B attr(AttributeKey<T> key, T value)
Allow to specify an initial attribute of the newly createdChannel
. If thevalue
isnull
, the attribute of the specifiedkey
is removed.
-
extensionsClassLoader
public B extensionsClassLoader(java.lang.ClassLoader classLoader)
LoadChannelInitializerExtension
s using the given class loader.By default, the extensions will be loaded by the same class loader that loaded this bootstrap class.
- Parameters:
classLoader
- The class loader to use for loadingChannelInitializerExtension
s.- Returns:
- This bootstrap.
-
validate
public B validate()
Validate all the parameters. Sub-classes may override this, but should call the super method in that case.
-
clone
public abstract B clone()
Returns a deep clone of this bootstrap which has the identical configuration. This method is useful when making multipleChannel
s with similar settings. Please note that this method does not clone theEventLoopGroup
deeply but shallowly, making the group a shared resource.- Overrides:
clone
in classjava.lang.Object
-
register
public ChannelFuture register()
-
bind
public ChannelFuture bind()
Create a newChannel
and bind it.
-
bind
public ChannelFuture bind(int inetPort)
Create a newChannel
and bind it.
-
bind
public ChannelFuture bind(java.lang.String inetHost, int inetPort)
Create a newChannel
and bind it.
-
bind
public ChannelFuture bind(java.net.InetAddress inetHost, int inetPort)
Create a newChannel
and bind it.
-
bind
public ChannelFuture bind(java.net.SocketAddress localAddress)
Create a newChannel
and bind it.
-
handler
public B handler(ChannelHandler handler)
theChannelHandler
to use for serving the requests.
-
group
@Deprecated public final EventLoopGroup group()
Deprecated.Useconfig()
instead.Returns the configuredEventLoopGroup
ornull
if non is configured yet.
-
config
public abstract AbstractBootstrapConfig<B,C> config()
Returns theAbstractBootstrapConfig
object that can be used to obtain the current config of the bootstrap.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-