Class NioDatagramChannel

All Implemented Interfaces:
Channel, ChannelOutboundInvoker, DatagramChannel, AttributeMap, java.lang.Comparable<Channel>

public final class NioDatagramChannel extends AbstractNioMessageChannel implements DatagramChannel
An NIO datagram Channel that sends and receives an AddressedEnvelopeinvalid input: '<'ByteBuf, SocketAddress>.
See Also:
  • Field Details

    • METADATA

      private static final ChannelMetadata METADATA
    • DEFAULT_SELECTOR_PROVIDER

      private static final java.nio.channels.spi.SelectorProvider DEFAULT_SELECTOR_PROVIDER
    • EXPECTED_TYPES

      private static final java.lang.String EXPECTED_TYPES
    • config

      private final DatagramChannelConfig config
    • memberships

      private java.util.Map<java.net.InetAddress, java.util.List<java.nio.channels.MembershipKey>> memberships
  • Constructor Details

    • NioDatagramChannel

      public NioDatagramChannel()
      Create a new instance which will use the Operation Systems default SocketProtocolFamily.
    • NioDatagramChannel

      public NioDatagramChannel(java.nio.channels.spi.SelectorProvider provider)
      Create a new instance using the given SelectorProvider which will use the Operation Systems default SocketProtocolFamily.
    • NioDatagramChannel

      @Deprecated public NioDatagramChannel(InternetProtocolFamily ipFamily)
      Create a new instance using the given InternetProtocolFamily. If null is used it will depend on the Operation Systems default which will be chosen.
    • NioDatagramChannel

      public NioDatagramChannel(SocketProtocolFamily protocolFamily)
      Create a new instance using the given SocketProtocolFamily. If null is used it will depend on the Operation Systems default which will be chosen.
    • NioDatagramChannel

      @Deprecated public NioDatagramChannel(java.nio.channels.spi.SelectorProvider provider, InternetProtocolFamily ipFamily)
      Create a new instance using the given SelectorProvider and InternetProtocolFamily. If InternetProtocolFamily is null it will depend on the Operation Systems default which will be chosen.
    • NioDatagramChannel

      public NioDatagramChannel(java.nio.channels.spi.SelectorProvider provider, SocketProtocolFamily protocolFamily)
      Create a new instance using the given SelectorProvider and SocketProtocolFamily. If SocketProtocolFamily is null it will depend on the Operation Systems default which will be chosen.
    • NioDatagramChannel

      public NioDatagramChannel(java.nio.channels.DatagramChannel socket)
      Create a new instance from the given DatagramChannel.
  • Method Details

    • newSocket

      private static java.nio.channels.DatagramChannel newSocket(java.nio.channels.spi.SelectorProvider provider)
      Use the SelectorProvider to open DatagramChannel and so remove condition in SelectorProvider.provider() which is called by each DatagramChannel.open() otherwise.

      See #2308.

    • newSocket

      private static java.nio.channels.DatagramChannel newSocket(java.nio.channels.spi.SelectorProvider provider, SocketProtocolFamily ipFamily)
    • metadata

      public ChannelMetadata metadata()
      Description copied from interface: Channel
      Return the ChannelMetadata of the Channel which describe the nature of the Channel.
      Specified by:
      metadata in interface Channel
    • config

      public DatagramChannelConfig config()
      Description copied from interface: Channel
      Returns the configuration of this channel.
      Specified by:
      config in interface Channel
      Specified by:
      config in interface DatagramChannel
    • isActive

      public boolean isActive()
      Description copied from interface: Channel
      Return true if the Channel is active and so connected.
      Specified by:
      isActive in interface Channel
    • isConnected

      public boolean isConnected()
      Description copied from interface: DatagramChannel
      Return true if the DatagramChannel is connected to the remote peer.
      Specified by:
      isConnected in interface DatagramChannel
    • javaChannel

      protected java.nio.channels.DatagramChannel javaChannel()
      Overrides:
      javaChannel in class AbstractNioChannel
    • localAddress0

      protected java.net.SocketAddress localAddress0()
      Description copied from class: AbstractChannel
      Returns the SocketAddress which is bound locally.
      Specified by:
      localAddress0 in class AbstractChannel
    • remoteAddress0

      protected java.net.SocketAddress remoteAddress0()
      Description copied from class: AbstractChannel
      Return the SocketAddress which the Channel is connected to.
      Specified by:
      remoteAddress0 in class AbstractChannel
    • doBind

      protected void doBind(java.net.SocketAddress localAddress) throws java.lang.Exception
      Description copied from class: AbstractChannel
      Bind the Channel to the SocketAddress
      Specified by:
      doBind in class AbstractChannel
      Throws:
      java.lang.Exception
    • doBind0

      private void doBind0(java.net.SocketAddress localAddress) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • doConnect

      protected boolean doConnect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress) throws java.lang.Exception
      Description copied from class: AbstractNioChannel
      Connect to the remote peer
      Specified by:
      doConnect in class AbstractNioChannel
      Throws:
      java.lang.Exception
    • doFinishConnect

      protected void doFinishConnect() throws java.lang.Exception
      Description copied from class: AbstractNioChannel
      Finish the connect
      Specified by:
      doFinishConnect in class AbstractNioChannel
      Throws:
      java.lang.Exception
    • doDisconnect

      protected void doDisconnect() throws java.lang.Exception
      Description copied from class: AbstractChannel
      Disconnect this Channel from its remote peer
      Specified by:
      doDisconnect in class AbstractChannel
      Throws:
      java.lang.Exception
    • doClose

      protected void doClose() throws java.lang.Exception
      Description copied from class: AbstractChannel
      Close the Channel
      Overrides:
      doClose in class AbstractNioChannel
      Throws:
      java.lang.Exception
    • doReadMessages

      protected int doReadMessages(java.util.List<java.lang.Object> buf) throws java.lang.Exception
      Description copied from class: AbstractNioMessageChannel
      Read messages into the given array and return the amount which was read.
      Specified by:
      doReadMessages in class AbstractNioMessageChannel
      Throws:
      java.lang.Exception
    • doWriteMessage

      protected boolean doWriteMessage(java.lang.Object msg, ChannelOutboundBuffer in) throws java.lang.Exception
      Description copied from class: AbstractNioMessageChannel
      Write a message to the underlying Channel.
      Specified by:
      doWriteMessage in class AbstractNioMessageChannel
      Returns:
      true if and only if the message has been written
      Throws:
      java.lang.Exception
    • checkUnresolved

      private static void checkUnresolved(AddressedEnvelope<?,?> envelope)
    • filterOutboundMessage

      protected java.lang.Object filterOutboundMessage(java.lang.Object msg)
      Description copied from class: AbstractChannel
      Invoked when a new message is added to a ChannelOutboundBuffer of this AbstractChannel, so that the Channel implementation converts the message to another. (e.g. heap buffer -> direct buffer)
      Overrides:
      filterOutboundMessage in class AbstractChannel
    • isSingleDirectBuffer

      private static boolean isSingleDirectBuffer(ByteBuf buf)
      Checks if the specified buffer is a direct buffer and is composed of a single NIO buffer. (We check this because otherwise we need to make it a non-composite buffer.)
    • continueOnWriteError

      protected boolean continueOnWriteError()
      Description copied from class: AbstractNioMessageChannel
      Returns true if we should continue the write loop on a write error.
      Overrides:
      continueOnWriteError in class AbstractNioMessageChannel
    • localAddress

      public java.net.InetSocketAddress localAddress()
      Description copied from interface: Channel
      Returns the local address where this channel is bound to. The returned SocketAddress is supposed to be down-cast into more concrete type such as InetSocketAddress to retrieve the detailed information.
      Specified by:
      localAddress in interface Channel
      Specified by:
      localAddress in interface DatagramChannel
      Overrides:
      localAddress in class AbstractChannel
      Returns:
      the local address of this channel. null if this channel is not bound.
    • remoteAddress

      public java.net.InetSocketAddress remoteAddress()
      Description copied from interface: Channel
      Returns the remote address where this channel is connected to. The returned SocketAddress is supposed to be down-cast into more concrete type such as InetSocketAddress to retrieve the detailed information.
      Specified by:
      remoteAddress in interface Channel
      Specified by:
      remoteAddress in interface DatagramChannel
      Overrides:
      remoteAddress in class AbstractChannel
      Returns:
      the remote address of this channel. null if this channel is not connected. If this channel is not connected but it can receive messages from arbitrary remote addresses (e.g. DatagramChannel, use DefaultAddressedEnvelope.recipient() to determine the origination of the received message as this method will return null.
    • joinGroup

      public ChannelFuture joinGroup(java.net.InetAddress multicastAddress)
      Description copied from interface: DatagramChannel
      Joins a multicast group and notifies the ChannelFuture once the operation completes.
      Specified by:
      joinGroup in interface DatagramChannel
    • joinGroup

      public ChannelFuture joinGroup(java.net.InetAddress multicastAddress, ChannelPromise promise)
      Description copied from interface: DatagramChannel
      Joins a multicast group and notifies the ChannelFuture once the operation completes. The given ChannelFuture will be notified and also returned.
      Specified by:
      joinGroup in interface DatagramChannel
    • defaultMulticastInterface

      private java.net.NetworkInterface defaultMulticastInterface() throws java.net.SocketException
      Returns the interface to use when none was given: the one set via ChannelOption.IP_MULTICAST_IF or, if unset, the interface of the local address.
      Throws:
      java.net.SocketException
    • joinGroup

      public ChannelFuture joinGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface)
      Description copied from interface: DatagramChannel
      Joins the specified multicast group at the specified interface and notifies the ChannelFuture once the operation completes.
      Specified by:
      joinGroup in interface DatagramChannel
    • joinGroup

      public ChannelFuture joinGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface, ChannelPromise promise)
      Description copied from interface: DatagramChannel
      Joins the specified multicast group at the specified interface and notifies the ChannelFuture once the operation completes. The given ChannelFuture will be notified and also returned.
      Specified by:
      joinGroup in interface DatagramChannel
    • joinGroup

      public ChannelFuture joinGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source)
      Description copied from interface: DatagramChannel
      Joins the specified multicast group at the specified interface and notifies the ChannelFuture once the operation completes.
      Specified by:
      joinGroup in interface DatagramChannel
    • joinGroup

      public ChannelFuture joinGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source, ChannelPromise promise)
      Description copied from interface: DatagramChannel
      Joins the specified multicast group at the specified interface and notifies the ChannelFuture once the operation completes. The given ChannelFuture will be notified and also returned.
      Specified by:
      joinGroup in interface DatagramChannel
    • leaveGroup

      public ChannelFuture leaveGroup(java.net.InetAddress multicastAddress)
      Description copied from interface: DatagramChannel
      Leaves a multicast group and notifies the ChannelFuture once the operation completes.
      Specified by:
      leaveGroup in interface DatagramChannel
    • leaveGroup

      public ChannelFuture leaveGroup(java.net.InetAddress multicastAddress, ChannelPromise promise)
      Description copied from interface: DatagramChannel
      Leaves a multicast group and notifies the ChannelFuture once the operation completes. The given ChannelFuture will be notified and also returned.
      Specified by:
      leaveGroup in interface DatagramChannel
    • leaveGroup

      public ChannelFuture leaveGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface)
      Description copied from interface: DatagramChannel
      Leaves a multicast group on a specified local interface and notifies the ChannelFuture once the operation completes.
      Specified by:
      leaveGroup in interface DatagramChannel
    • leaveGroup

      public ChannelFuture leaveGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface, ChannelPromise promise)
      Description copied from interface: DatagramChannel
      Leaves a multicast group on a specified local interface and notifies the ChannelFuture once the operation completes. The given ChannelFuture will be notified and also returned.
      Specified by:
      leaveGroup in interface DatagramChannel
    • leaveGroup

      public ChannelFuture leaveGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source)
      Description copied from interface: DatagramChannel
      Leave the specified multicast group at the specified interface using the specified source and notifies the ChannelFuture once the operation completes.
      Specified by:
      leaveGroup in interface DatagramChannel
    • leaveGroup

      public ChannelFuture leaveGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source, ChannelPromise promise)
      Description copied from interface: DatagramChannel
      Leave the specified multicast group at the specified interface using the specified source and notifies the ChannelFuture once the operation completes. The given ChannelFuture will be notified and also returned.
      Specified by:
      leaveGroup in interface DatagramChannel
    • block

      public ChannelFuture block(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress sourceToBlock)
      Block the given sourceToBlock address for the given multicastAddress on the given networkInterface
      Specified by:
      block in interface DatagramChannel
    • block

      public ChannelFuture block(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress sourceToBlock, ChannelPromise promise)
      Block the given sourceToBlock address for the given multicastAddress on the given networkInterface
      Specified by:
      block in interface DatagramChannel
    • block

      public ChannelFuture block(java.net.InetAddress multicastAddress, java.net.InetAddress sourceToBlock)
      Block the given sourceToBlock address for the given multicastAddress
      Specified by:
      block in interface DatagramChannel
    • block

      public ChannelFuture block(java.net.InetAddress multicastAddress, java.net.InetAddress sourceToBlock, ChannelPromise promise)
      Block the given sourceToBlock address for the given multicastAddress
      Specified by:
      block in interface DatagramChannel
    • setReadPending

      @Deprecated protected void setReadPending(boolean readPending)
      Deprecated.
      Overrides:
      setReadPending in class AbstractNioChannel
    • clearReadPending0

      void clearReadPending0()
    • closeOnReadError

      protected boolean closeOnReadError(java.lang.Throwable cause)
      Overrides:
      closeOnReadError in class AbstractNioMessageChannel
    • continueReading

      protected boolean continueReading(RecvByteBufAllocator.Handle allocHandle)
      Overrides:
      continueReading in class AbstractNioMessageChannel