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).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classAbstractBootstrap.PendingRegistrationPromise
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<AttributeKey<?>,java.lang.Object>attrsprivate ChannelFactory<? extends C>channelFactory(package private) static java.util.Map.Entry<AttributeKey<?>,java.lang.Object>[]EMPTY_ATTRIBUTE_ARRAY(package private) static java.util.Map.Entry<ChannelOption<?>,java.lang.Object>[]EMPTY_OPTION_ARRAY(package private) EventLoopGroupgroupprivate ChannelHandlerhandlerprivate java.net.SocketAddresslocalAddressprivate java.util.Map<ChannelOption<?>,java.lang.Object>options
-
Constructor Summary
Constructors Constructor Description AbstractBootstrap()AbstractBootstrap(AbstractBootstrap<B,C> bootstrap)
-
Method Summary
All Methods Static 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.(package private) java.util.Map<AttributeKey<?>,java.lang.Object>attrs()(package private) java.util.Map<AttributeKey<?>,java.lang.Object>attrs0()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.(package private) ChannelFactory<? extends C>channelFactory()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.(package private) static <K,V>
java.util.Map<K,V>copiedMap(java.util.Map<K,V> map)private ChannelFuturedoBind(java.net.SocketAddress localAddress)private static voiddoBind0(ChannelFuture regFuture, Channel channel, java.net.SocketAddress localAddress, ChannelPromise promise)EventLoopGroupgroup()Deprecated.Useconfig()instead.Bgroup(EventLoopGroup group)TheEventLoopGroupwhich is used to handle all the events for the to-be-createdChannel(package private) ChannelHandlerhandler()Bhandler(ChannelHandler handler)theChannelHandlerto use for serving the requests.(package private) abstract voidinit(Channel channel)(package private) ChannelFutureinitAndRegister()(package private) java.net.SocketAddresslocalAddress()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.(package private) java.util.Map.Entry<ChannelOption<?>,java.lang.Object>[]newOptionsArray()<T> Boption(ChannelOption<T> option, T value)Allow to specify aChannelOptionwhich is used for theChannelinstances once they got created.(package private) java.util.Map<ChannelOption<?>,java.lang.Object>options()(package private) java.util.Map<ChannelOption<?>,java.lang.Object>options0()ChannelFutureregister()private Bself()(package private) static voidsetAttributes(Channel channel, java.util.Map.Entry<AttributeKey<?>,java.lang.Object>[] attrs)private static voidsetChannelOption(Channel channel, ChannelOption<?> option, java.lang.Object value, InternalLogger logger)(package private) static voidsetChannelOptions(Channel channel, java.util.Map.Entry<ChannelOption<?>,java.lang.Object>[] options, InternalLogger logger)java.lang.StringtoString()Bvalidate()Validate all the parameters.
-
-
-
Field Detail
-
EMPTY_OPTION_ARRAY
static final java.util.Map.Entry<ChannelOption<?>,java.lang.Object>[] EMPTY_OPTION_ARRAY
-
EMPTY_ATTRIBUTE_ARRAY
static final java.util.Map.Entry<AttributeKey<?>,java.lang.Object>[] EMPTY_ATTRIBUTE_ARRAY
-
group
volatile EventLoopGroup group
-
channelFactory
private volatile ChannelFactory<? extends C extends Channel> channelFactory
-
localAddress
private volatile java.net.SocketAddress localAddress
-
options
private final java.util.Map<ChannelOption<?>,java.lang.Object> options
-
attrs
private final java.util.Map<AttributeKey<?>,java.lang.Object> attrs
-
handler
private volatile ChannelHandler handler
-
-
Constructor Detail
-
AbstractBootstrap
AbstractBootstrap()
-
AbstractBootstrap
AbstractBootstrap(AbstractBootstrap<B,C> bootstrap)
-
-
Method Detail
-
group
public B group(EventLoopGroup group)
TheEventLoopGroupwhich is used to handle all the events for the to-be-createdChannel
-
self
private B self()
-
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.
-
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.
-
doBind
private ChannelFuture doBind(java.net.SocketAddress localAddress)
-
initAndRegister
final ChannelFuture initAndRegister()
-
init
abstract void init(Channel channel) throws java.lang.Exception
- Throws:
java.lang.Exception
-
doBind0
private static void doBind0(ChannelFuture regFuture, Channel channel, java.net.SocketAddress localAddress, ChannelPromise promise)
-
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.
-
newOptionsArray
final java.util.Map.Entry<ChannelOption<?>,java.lang.Object>[] newOptionsArray()
-
options0
final java.util.Map<ChannelOption<?>,java.lang.Object> options0()
-
attrs0
final java.util.Map<AttributeKey<?>,java.lang.Object> attrs0()
-
localAddress
final java.net.SocketAddress localAddress()
-
channelFactory
final ChannelFactory<? extends C> channelFactory()
-
handler
final ChannelHandler handler()
-
options
final java.util.Map<ChannelOption<?>,java.lang.Object> options()
-
attrs
final java.util.Map<AttributeKey<?>,java.lang.Object> attrs()
-
copiedMap
static <K,V> java.util.Map<K,V> copiedMap(java.util.Map<K,V> map)
-
setAttributes
static void setAttributes(Channel channel, java.util.Map.Entry<AttributeKey<?>,java.lang.Object>[] attrs)
-
setChannelOptions
static void setChannelOptions(Channel channel, java.util.Map.Entry<ChannelOption<?>,java.lang.Object>[] options, InternalLogger logger)
-
setChannelOption
private static void setChannelOption(Channel channel, ChannelOption<?> option, java.lang.Object value, InternalLogger logger)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-