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 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).

  • Field Details

    • CLOSE_ON_SET_OPTION_FAILURE

      private static final boolean CLOSE_ON_SET_OPTION_FAILURE
    • EMPTY_OPTION_ARRAY

      private static final java.util.Map.Entry<ChannelOption<?>, java.lang.Object>[] EMPTY_OPTION_ARRAY
    • EMPTY_ATTRIBUTE_ARRAY

      private 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
    • extensionsClassLoader

      private volatile java.lang.ClassLoader extensionsClassLoader
  • Constructor Details

    • AbstractBootstrap

      AbstractBootstrap()
    • AbstractBootstrap

      AbstractBootstrap(AbstractBootstrap<B,C> bootstrap)
  • Method Details

    • group

      public B group(EventLoopGroup group)
      The EventLoopGroup which is used to handle all the events for the to-be-created Channel
    • self

      private B self()
    • channel

      public B channel(java.lang.Class<? extends C> channelClass)
      The 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.
    • channelFactory

      @Deprecated public B channelFactory(ChannelFactory<? extends C> channelFactory)
    • channelFactory

      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.
    • localAddress

      public B localAddress(java.net.SocketAddress localAddress)
      The SocketAddress which is used to bind the local "end" to.
    • localAddress

      public B localAddress(int inetPort)
      See Also:
    • localAddress

      public B localAddress(java.lang.String inetHost, int inetPort)
      See Also:
    • localAddress

      public B localAddress(java.net.InetAddress inetHost, int inetPort)
      See Also:
    • option

      public <T> B option(ChannelOption<T> option, T value)
      Allow to specify a ChannelOption which is used for the Channel instances once they got created. Use a value of null to remove a previous set ChannelOption.
    • attr

      public <T> B attr(AttributeKey<T> key, T value)
      Allow to specify an initial attribute of the newly created Channel. If the value is null, the attribute of the specified key is removed.
    • extensionsClassLoader

      public B extensionsClassLoader(java.lang.ClassLoader classLoader)
      Load ChannelInitializerExtensions 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 loading ChannelInitializerExtensions.
      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 multiple Channels with similar settings. Please note that this method does not clone the EventLoopGroup deeply but shallowly, making the group a shared resource.
      Overrides:
      clone in class java.lang.Object
    • register

      public ChannelFuture register()
      Create a new Channel and register it with an EventLoop.
    • bind

      public ChannelFuture bind()
      Create a new Channel and bind it.
    • bind

      public ChannelFuture bind(int inetPort)
      Create a new Channel and bind it.
    • bind

      public ChannelFuture bind(java.lang.String inetHost, int inetPort)
      Create a new Channel and bind it.
    • bind

      public ChannelFuture bind(java.net.InetAddress inetHost, int inetPort)
      Create a new Channel and bind it.
    • bind

      public ChannelFuture bind(java.net.SocketAddress localAddress)
      Create a new Channel and bind it.
    • doBind

      private ChannelFuture doBind(java.net.SocketAddress localAddress)
    • initAndRegister

      final ChannelFuture initAndRegister()
    • init

      abstract void init(Channel channel) throws java.lang.Throwable
      Throws:
      java.lang.Throwable
    • getInitializerExtensions

      java.util.Collection<ChannelInitializerExtension> getInitializerExtensions()
    • doBind0

      private static void doBind0(ChannelFuture regFuture, Channel channel, java.net.SocketAddress localAddress, ChannelPromise promise)
    • handler

      public B handler(ChannelHandler handler)
      the ChannelHandler to use for serving the requests.
    • group

      @Deprecated public final EventLoopGroup group()
      Deprecated.
      Use config() instead.
      Returns the configured EventLoopGroup or null if non is configured yet.
    • config

      public abstract AbstractBootstrapConfig<B,C> config()
      Returns the AbstractBootstrapConfig object that can be used to obtain the current config of the bootstrap.
    • newOptionsArray

      final java.util.Map.Entry<ChannelOption<?>, java.lang.Object>[] newOptionsArray()
    • newOptionsArray

      static java.util.Map.Entry<ChannelOption<?>, java.lang.Object>[] newOptionsArray(java.util.Map<ChannelOption<?>, java.lang.Object> options)
    • newAttributesArray

      final java.util.Map.Entry<AttributeKey<?>, java.lang.Object>[] newAttributesArray()
    • newAttributesArray

      static java.util.Map.Entry<AttributeKey<?>, java.lang.Object>[] newAttributesArray(java.util.Map<AttributeKey<?>, java.lang.Object> attributes)
    • 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) throws java.lang.Throwable
      Throws:
      java.lang.Throwable
    • setChannelOption

      private static void setChannelOption(Channel channel, ChannelOption<?> option, java.lang.Object value, InternalLogger logger) throws java.lang.Throwable
      Throws:
      java.lang.Throwable
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object