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.CloneableAbstractBootstrapis 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
ServerBootstrapcontext, 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> Battr(AttributeKey<T> key, T value)Allow to specify an initial attribute of the newly createdChannel.ChannelFuturebind()Create a newChanneland bind it.ChannelFuturebind(int inetPort)Create a newChanneland bind it.ChannelFuturebind(java.lang.String inetHost, int inetPort)Create a newChanneland bind it.ChannelFuturebind(java.net.InetAddress inetHost, int inetPort)Create a newChanneland bind it.ChannelFuturebind(java.net.SocketAddress localAddress)Create a newChanneland bind it.Bchannel(java.lang.Class<? extends C> channelClass)TheClasswhich is used to createChannelinstances from.BchannelFactory(ChannelFactory<? extends C> channelFactory)Deprecated.UsechannelFactory(io.netty.channel.ChannelFactory)instead.BchannelFactory(ChannelFactory<? extends C> channelFactory)abstract Bclone()Returns a deep clone of this bootstrap which has the identical configuration.abstract AbstractBootstrapConfig<B,C>config()Returns theAbstractBootstrapConfigobject that can be used to obtain the current config of the bootstrap.BextensionsClassLoader(java.lang.ClassLoader classLoader)LoadChannelInitializerExtensions using the given class loader.EventLoopGroupgroup()Deprecated.Useconfig()instead.Bgroup(EventLoopGroup group)TheEventLoopGroupwhich is used to handle all the events for the to-be-createdChannelBhandler(ChannelHandler handler)theChannelHandlerto use for serving the requests.BlocalAddress(int inetPort)BlocalAddress(java.lang.String inetHost, int inetPort)BlocalAddress(java.net.InetAddress inetHost, int inetPort)BlocalAddress(java.net.SocketAddress localAddress)TheSocketAddresswhich is used to bind the local "end" to.<T> Boption(ChannelOption<T> option, T value)Allow to specify aChannelOptionwhich is used for theChannelinstances once they got created.ChannelFutureregister()java.lang.StringtoString()Bvalidate()Validate all the parameters.
-
-
-
Method Detail
-
group
public B group(EventLoopGroup group)
TheEventLoopGroupwhich is used to handle all the events for the to-be-createdChannel
-
channel
public B channel(java.lang.Class<? extends C> channelClass)
TheClasswhich is used to createChannelinstances from. You either use this orchannelFactory(io.netty.channel.ChannelFactory)if yourChannelimplementation 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)
ChannelFactorywhich is used to createChannelinstances from when callingbind(). This method is usually only used ifchannel(Class)is not working for you because of some more complex needs. If yourChannelimplementation has a no-args constructor, its highly recommend to just usechannel(Class)to simplify your code.
-
localAddress
public B localAddress(java.net.SocketAddress localAddress)
TheSocketAddresswhich 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 aChannelOptionwhich is used for theChannelinstances once they got created. Use a value ofnullto 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 thevalueisnull, the attribute of the specifiedkeyis removed.
-
extensionsClassLoader
public B extensionsClassLoader(java.lang.ClassLoader classLoader)
LoadChannelInitializerExtensions 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 loadingChannelInitializerExtensions.- 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 multipleChannels with similar settings. Please note that this method does not clone theEventLoopGroupdeeply but shallowly, making the group a shared resource.- Overrides:
clonein classjava.lang.Object
-
register
public ChannelFuture register()
-
bind
public ChannelFuture bind()
Create a newChanneland bind it.
-
bind
public ChannelFuture bind(int inetPort)
Create a newChanneland bind it.
-
bind
public ChannelFuture bind(java.lang.String inetHost, int inetPort)
Create a newChanneland bind it.
-
bind
public ChannelFuture bind(java.net.InetAddress inetHost, int inetPort)
Create a newChanneland bind it.
-
bind
public ChannelFuture bind(java.net.SocketAddress localAddress)
Create a newChanneland bind it.
-
handler
public B handler(ChannelHandler handler)
theChannelHandlerto use for serving the requests.
-
group
@Deprecated public final EventLoopGroup group()
Deprecated.Useconfig()instead.Returns the configuredEventLoopGroupornullif non is configured yet.
-
config
public abstract AbstractBootstrapConfig<B,C> config()
Returns theAbstractBootstrapConfigobject that can be used to obtain the current config of the bootstrap.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-