Top Description Fields Constructors Methods
io.netty5.channel.socket.nio

public final Class NioDatagramChannel

extends AbstractNioMessageChannel<Channel, SocketAddress, SocketAddress>
implements DatagramChannel
Class Inheritance
All Implemented Interfaces
io.netty5.channel.socket.DatagramChannel, io.netty5.channel.Channel, io.netty5.channel.IoHandle, java.lang.Comparable, io.netty5.channel.ChannelOutboundInvoker, io.netty5.util.concurrent.FuturePromiseFactory, io.netty5.util.AttributeMap
Imports
io.netty5.buffer.Buffer, io.netty5.channel.ChannelShutdownDirection, .FixedReadHandleFactory, .MaxMessagesWriteHandleFactory, .AddressedEnvelope, .Channel, .ChannelException, .ChannelOption, .DefaultBufferAddressedEnvelope, .EventLoop, io.netty5.util.Resource, io.netty5.channel.nio.AbstractNioMessageChannel, io.netty5.channel.socket.DatagramPacket, io.netty5.util.concurrent.Future, io.netty5.util.internal.PlatformDependent, .SocketUtils, .StringUtil, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.io.IOException, java.net.InetAddress, .InetSocketAddress, .NetworkInterface, .ProtocolFamily, .SocketAddress, .SocketException, .SocketOption, .StandardSocketOptions, java.nio.ByteBuffer, java.nio.channels.DatagramChannel, .MembershipKey, .SelectionKey, java.nio.channels.spi.SelectorProvider, java.util.ArrayList, .HashMap, .Iterator, .List, .Map

An NIO io.netty5.channel.socket.DatagramChannel that sends and receives an AddressedEnvelope<ByteBuf, SocketAddress>.

Available options

In addition to the options provided by io.netty5.channel.socket.DatagramChannel, NioDatagramChannel allows the following options in the option map:
ChannelOption INET INET6 {@code UNIX
NioChannelOptionXXX
See Also
AddressedEnvelope, DatagramPacket

Field Summary

Modifier and TypeField and Description
private volatile boolean
private volatile boolean
private static final SelectorProvider
private static final String
private final ProtocolFamily
private volatile boolean
private static final InternalLogger
private Map<InetAddress, List<MembershipKey>>
private volatile boolean

Constructor Summary

AccessConstructor and Description
public
NioDatagramChannel(EventLoop eventLoop)

Create a new instance which will use the Operation Systems default ProtocolFamily.

public
NioDatagramChannel(EventLoop eventLoop, SelectorProvider provider)

Create a new instance using the given SelectorProvider which will use the Operation Systems default ProtocolFamily.

public
NioDatagramChannel(EventLoop eventLoop, ProtocolFamily family)

Create a new instance using the given ProtocolFamily.

public
NioDatagramChannel(EventLoop eventLoop, SelectorProvider provider, ProtocolFamily family)

Create a new instance using the given SelectorProvider and ProtocolFamily.

public
NioDatagramChannel(EventLoop eventLoop, DatagramChannel socket, ProtocolFamily family)

Create a new instance from the given DatagramChannel.

Method Summary

Modifier and TypeMethod and Description
public Future<Void>
block(InetAddress
the multicast group address.
multicastAddress
,
NetworkInterface
the interface to use.
networkInterface
,
InetAddress
the source address.
sourceToBlock
)

Implements io.netty5.channel.socket.DatagramChannel.block.

Block the given sourceToBlock address for the given multicastAddress on the given networkInterface
public Future<Void>
block(InetAddress
the multicast group address.
multicastAddress
,
InetAddress
the source address.
sourceToBlock
)

Implements io.netty5.channel.socket.DatagramChannel.block.

Block the given sourceToBlock address for the given multicastAddress
protected void
doBind(SocketAddress
the SocketAddress to bound to.
localAddress
)

Implements abstract io.netty5.channel.AbstractChannel.doBind.

Bind the Channel to the SocketAddress
private void
doBind0(SocketAddress localAddress)

protected boolean
doConnect(SocketAddress
the address of the remote peer.
remoteAddress
,
SocketAddress
the local address of this channel.
localAddress
,
Buffer
the initial data that is written during connect (if ChannelOption#TCP_FASTOPEN_CONNECT is supported and configured). If data is written care must be taken to update the reader offset.
initialData
)

Implements abstract io.netty5.channel.AbstractChannel.doConnect.

Connect to remote peer.
protected void
doDisconnect()

Implements abstract io.netty5.channel.AbstractChannel.doDisconnect.

Disconnect this Channel from its remote peer
protected boolean
doFinishConnect(SocketAddress
the remote address of the peer.
requestedRemoteAddress
)

Implements abstract io.netty5.channel.AbstractChannel.doFinishConnect.

Finish a connect request.
protected int
doReadMessages(AbstractChannel<Channel, SocketAddress, SocketAddress>.ReadSink readSink)

Implements abstract io.netty5.channel.nio.AbstractNioMessageChannel.doReadMessages.

Read messages into the given array and return the amount which was read.
protected void
doShutdown(ChannelShutdownDirection
the direction to shut down.
direction
)

Implements abstract io.netty5.channel.AbstractChannel.doShutdown.

Shutdown one direction of the Channel.
protected void
doWriteNow(AbstractChannel<Channel, SocketAddress, SocketAddress>.WriteSink
the WriteSink that must be completed with the write progress. WriteSink#complete(long, long, int, boolean) or WriteSink#complete(long, Throwable, boolean) must be called exactly once before this method returns non-exceptional.
writeSink
)

Implements abstract io.netty5.channel.AbstractChannel.doWriteNow.

Called in a loop when writes should be performed until this method returns false or there are no more messages to write.
protected Object
filterOutboundMessage(Object
the message to filter / convert.
msg
)

Overrides io.netty5.channel.AbstractChannel.filterOutboundMessage.

Invoked when a new message is added to to the outbound queue of this AbstractChannel, so that the Channel implementation converts the message to another.
protected <T> T
private NetworkInterface
public boolean
isActive()

Implements io.netty5.channel.Channel.isActive.

Return true if the Channel is active and so connected.
private boolean
private boolean
public boolean
isConnected()

Implements io.netty5.channel.socket.DatagramChannel.isConnected.

Return true if the DatagramChannel is connected to the remote peer.
protected boolean
public boolean
isShutdown(ChannelShutdownDirection direction)

Implements io.netty5.channel.Channel.isShutdown.

Returns true if the ChannelShutdownDirection of the Channel was shutdown before.
private static boolean
isSingleDirectBuffer(Buffer buf)

Checks if the specified buffer is a direct buffer and not composite.

protected DatagramChannel
public Future<Void>
joinGroup(InetAddress
the multicast group address.
multicastAddress
)

Implements io.netty5.channel.socket.DatagramChannel.joinGroup.

Joins a multicast group and notifies the Future once the operation completes.
public Future<Void>
joinGroup(InetAddress
the multicast group address.
multicastAddress
,
NetworkInterface
the interface to use.
networkInterface
,
InetAddress
the source address (might be null).
source
)

Implements io.netty5.channel.socket.DatagramChannel.joinGroup.

Joins the specified multicast group at the specified interface and notifies the Future once the operation completes.
public Future<Void>
leaveGroup(InetAddress
the multicast group address.
multicastAddress
)

Implements io.netty5.channel.socket.DatagramChannel.leaveGroup.

Leaves a multicast group and notifies the Future once the operation completes.
public Future<Void>
leaveGroup(InetAddress
the multicast group address.
multicastAddress
,
NetworkInterface
the interface to use.
networkInterface
,
InetAddress
the source address (might be null).
source
)

Implements io.netty5.channel.socket.DatagramChannel.leaveGroup.

Leave the specified multicast group at the specified interface using the specified source and notifies the Future once the operation completes.
protected SocketAddress
localAddress0()

Implements abstract io.netty5.channel.AbstractChannel.localAddress0.

Returns the SocketAddress which is bound locally.
private NetworkInterface
private static DatagramChannel
private static DatagramChannel
protected SocketAddress
remoteAddress0()

Implements abstract io.netty5.channel.AbstractChannel.remoteAddress0.

Return the SocketAddress which the Channel is connected to.
private void
setActiveOnOpen(boolean activeOnOpen)

protected <T> void
setExtendedOption(ChannelOption<T> option, T value)

Overrides io.netty5.channel.AbstractChannel.setExtendedOption.

Override to add support for more ChannelOptions.
private int
write(Buffer buf, SocketAddress remoteAddress)

Inherited from io.netty5.channel.nio.AbstractNioMessageChannel:
doReadNow

Field Detail

activeOnOpenback to summary
private volatile boolean activeOnOpen
boundback to summary
private volatile boolean bound
DEFAULT_SELECTOR_PROVIDERback to summary
private static final SelectorProvider DEFAULT_SELECTOR_PROVIDER
EXPECTED_TYPESback to summary
private static final String EXPECTED_TYPES
familyback to summary
private final ProtocolFamily family
inputShutdownback to summary
private volatile boolean inputShutdown
loggerback to summary
private static final InternalLogger logger

Hides io.netty5.channel.nio.AbstractNioChannel.logger.

membershipsback to summary
private Map<InetAddress, List<MembershipKey>> memberships
outputShutdownback to summary
private volatile boolean outputShutdown

Constructor Detail

NioDatagramChannelback to summary
public NioDatagramChannel(EventLoop eventLoop)

Create a new instance which will use the Operation Systems default ProtocolFamily.

NioDatagramChannelback to summary
public NioDatagramChannel(EventLoop eventLoop, SelectorProvider provider)

Create a new instance using the given SelectorProvider which will use the Operation Systems default ProtocolFamily.

NioDatagramChannelback to summary
public NioDatagramChannel(EventLoop eventLoop, ProtocolFamily family)

Create a new instance using the given ProtocolFamily. If null is used it will depend on the Operation Systems default which will be chosen.

NioDatagramChannelback to summary
public NioDatagramChannel(EventLoop eventLoop, SelectorProvider provider, ProtocolFamily family)

Create a new instance using the given SelectorProvider and ProtocolFamily. If ProtocolFamily is null it will depend on the Operation Systems default which will be chosen.

NioDatagramChannelback to summary
public NioDatagramChannel(EventLoop eventLoop, DatagramChannel socket, ProtocolFamily family)

Create a new instance from the given DatagramChannel.

Method Detail

blockback to summary
public Future<Void> block(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress sourceToBlock)

Implements io.netty5.channel.socket.DatagramChannel.block.

Block the given sourceToBlock address for the given multicastAddress on the given networkInterface

Parameters
multicastAddress:InetAddress

Doc from io.netty5.channel.socket.DatagramChannel.block.

the multicast group address.

networkInterface:NetworkInterface

Doc from io.netty5.channel.socket.DatagramChannel.block.

the interface to use.

sourceToBlock:InetAddress

Doc from io.netty5.channel.socket.DatagramChannel.block.

the source address.

Returns:Future<Void>

Doc from io.netty5.channel.socket.DatagramChannel.block.

a Future which is notified once the operation completes.

Annotations
@Override
blockback to summary
public Future<Void> block(InetAddress multicastAddress, InetAddress sourceToBlock)

Implements io.netty5.channel.socket.DatagramChannel.block.

Block the given sourceToBlock address for the given multicastAddress

Parameters
multicastAddress:InetAddress

Doc from io.netty5.channel.socket.DatagramChannel.block.

the multicast group address.

sourceToBlock:InetAddress

Doc from io.netty5.channel.socket.DatagramChannel.block.

the source address.

Returns:Future<Void>

Doc from io.netty5.channel.socket.DatagramChannel.block.

a Future which is notified once the operation completes.

Annotations
@Override
doBindback to summary
protected void doBind(SocketAddress localAddress) throws Exception

Implements abstract io.netty5.channel.AbstractChannel.doBind.

Doc from io.netty5.channel.AbstractChannel.doBind.

Bind the Channel to the SocketAddress

Parameters
localAddress:SocketAddress

the SocketAddress to bound to.

Annotations
@Override
Exceptions
Exception:
when an error happens.
doBind0back to summary
private void doBind0(SocketAddress localAddress) throws Exception
doConnectback to summary
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress, Buffer initialData) throws Exception

Implements abstract io.netty5.channel.AbstractChannel.doConnect.

Doc from io.netty5.channel.AbstractChannel.doConnect.

Connect to remote peer. This method should never be directly called.

Parameters
remoteAddress:SocketAddress

the address of the remote peer.

localAddress:SocketAddress

the local address of this channel.

initialData:Buffer

the initial data that is written during connect (if ChannelOption#TCP_FASTOPEN_CONNECT is supported and configured). If data is written care must be taken to update the reader offset.

Returns:boolean

true if the connect operation was completed, false if finishConnect() will be called later again to try finish connecting.

Annotations
@Override
Exceptions
Exception:
thrown on error.
doDisconnectback to summary
protected void doDisconnect() throws Exception

Implements abstract io.netty5.channel.AbstractChannel.doDisconnect.

Doc from io.netty5.channel.AbstractChannel.doDisconnect.

Disconnect this Channel from its remote peer

Annotations
@Override
Exceptions
Exception:
thrown on error.
doFinishConnectback to summary
protected boolean doFinishConnect(SocketAddress requestedRemoteAddress)

Implements abstract io.netty5.channel.AbstractChannel.doFinishConnect.

Doc from io.netty5.channel.AbstractChannel.doFinishConnect.

Finish a connect request. This method should never be directly called, use finishConnect() instead.

Parameters
requestedRemoteAddress:SocketAddress

the remote address of the peer.

Returns:boolean

true if the connect operations was completed, false if finishConnect() will be called later again to try finishing the connect operation.

Annotations
@Override
doReadMessagesback to summary
protected int doReadMessages(AbstractChannel<Channel, SocketAddress, SocketAddress>.ReadSink readSink) throws Exception

Implements abstract io.netty5.channel.nio.AbstractNioMessageChannel.doReadMessages.

Doc from io.netty5.channel.nio.AbstractNioMessageChannel.doReadMessages.

Read messages into the given array and return the amount which was read.

Annotations
@Override
doShutdownback to summary
protected void doShutdown(ChannelShutdownDirection direction)

Implements abstract io.netty5.channel.AbstractChannel.doShutdown.

Doc from io.netty5.channel.AbstractChannel.doShutdown.

Shutdown one direction of the Channel.

Parameters
direction:ChannelShutdownDirection

the direction to shut down.

Annotations
@Override
doWriteNowback to summary
protected void doWriteNow(AbstractChannel<Channel, SocketAddress, SocketAddress>.WriteSink writeSink) throws Exception

Implements abstract io.netty5.channel.AbstractChannel.doWriteNow.

Doc from io.netty5.channel.AbstractChannel.doWriteNow.

Called in a loop when writes should be performed until this method returns false or there are no more messages to write. Implementations are responsible for handling partial writes, which for example means that if Buffers are written partial implementations need to ensure the readerOffset is updated accordingly.

Parameters
writeSink:AbstractChannel<Channel, SocketAddress, SocketAddress>.WriteSink

the WriteSink that must be completed with the write progress. WriteSink#complete(long, long, int, boolean) or WriteSink#complete(long, Throwable, boolean) must be called exactly once before this method returns non-exceptional.

Annotations
@Override
Exceptions
Exception:
if an error happened during writing. This will also terminate the write loop.
filterOutboundMessageback to summary
protected Object filterOutboundMessage(Object msg)

Overrides io.netty5.channel.AbstractChannel.filterOutboundMessage.

Doc from io.netty5.channel.AbstractChannel.filterOutboundMessage.

Invoked when a new message is added to to the outbound queue of this AbstractChannel, so that the Channel implementation converts the message to another. (e.g. heap buffer -> direct buffer)

Parameters
msg:Object

the message to filter / convert.

Annotations
@Override
getExtendedOptionback to summary
protected <T> T getExtendedOption(ChannelOption<T> option)

Overrides io.netty5.channel.AbstractChannel.getExtendedOption.

Doc from io.netty5.channel.AbstractChannel.getExtendedOption.

Override to add support for more ChannelOptions. You need to also call super after handling the extra options.

Parameters
<T>
the value type.
option:ChannelOption<T>

the ChannelOption.

Returns:T

the value for the option.

Annotations
@SuppressWarnings:unchecked
@Override
getNetworkInterfaceback to summary
private NetworkInterface getNetworkInterface()
isActiveback to summary
public boolean isActive()

Implements io.netty5.channel.Channel.isActive.

Doc from io.netty5.channel.Channel.isActive.

Return true if the Channel is active and so connected.

Annotations
@Override
@SuppressWarnings:deprecation
isActiveOnOpenback to summary
private boolean isActiveOnOpen()
isAnyLocalAddressback to summary
private boolean isAnyLocalAddress() throws IOException
isConnectedback to summary
public boolean isConnected()

Implements io.netty5.channel.socket.DatagramChannel.isConnected.

Doc from io.netty5.channel.socket.DatagramChannel.isConnected.

Return true if the DatagramChannel is connected to the remote peer.

Annotations
@Override
isExtendedOptionSupportedback to summary
protected boolean isExtendedOptionSupported(ChannelOption<?> option)

Overrides io.netty5.channel.AbstractChannel.isExtendedOptionSupported.

Doc from io.netty5.channel.AbstractChannel.isExtendedOptionSupported.

Override to add support for more ChannelOptions. You need to also call super after handling the extra options.

Parameters
option:ChannelOption<?>

the ChannelOption.

Returns:boolean

true if supported, false otherwise.

Annotations
@Override
isShutdownback to summary
public boolean isShutdown(ChannelShutdownDirection direction)

Implements io.netty5.channel.Channel.isShutdown.

Doc from io.netty5.channel.Channel.isShutdown.

Returns true if the ChannelShutdownDirection of the Channel was shutdown before.

Annotations
@Override
isSingleDirectBufferback to summary
private static boolean isSingleDirectBuffer(Buffer buf)

Checks if the specified buffer is a direct buffer and not composite. (We check this because otherwise we need to make it a non-composite buffer.)

javaChannelback to summary
protected DatagramChannel javaChannel()

Overrides io.netty5.channel.nio.AbstractNioChannel.javaChannel.

Annotations
@Override
joinGroupback to summary
public Future<Void> joinGroup(InetAddress multicastAddress)

Implements io.netty5.channel.socket.DatagramChannel.joinGroup.

Doc from io.netty5.channel.socket.DatagramChannel.joinGroup.

Joins a multicast group and notifies the Future once the operation completes.

If the underlying implementation does not support this operation it will return a Future which is failed with an UnsupportedOperationException.

Parameters
multicastAddress:InetAddress

the multicast group address.

Returns:Future<Void>

a Future which is notified once the operation completes.

Annotations
@Override
joinGroupback to summary
public Future<Void> joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)

Implements io.netty5.channel.socket.DatagramChannel.joinGroup.

Doc from io.netty5.channel.socket.DatagramChannel.joinGroup.

Joins the specified multicast group at the specified interface and notifies the Future once the operation completes.

If the underlying implementation does not support this operation it will return a Future which is failed with an UnsupportedOperationException.

Parameters
multicastAddress:InetAddress

the multicast group address.

networkInterface:NetworkInterface

the interface to use.

source:InetAddress

the source address (might be null).

Returns:Future<Void>

a Future which is notified once the operation completes.

Annotations
@Override
leaveGroupback to summary
public Future<Void> leaveGroup(InetAddress multicastAddress)

Implements io.netty5.channel.socket.DatagramChannel.leaveGroup.

Doc from io.netty5.channel.socket.DatagramChannel.leaveGroup.

Leaves a multicast group and notifies the Future once the operation completes.

If the underlying implementation does not support this operation it will return a Future which is failed with an UnsupportedOperationException.

Parameters
multicastAddress:InetAddress

the multicast group address.

Returns:Future<Void>

a Future which is notified once the operation completes.

Annotations
@Override
leaveGroupback to summary
public Future<Void> leaveGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)

Implements io.netty5.channel.socket.DatagramChannel.leaveGroup.

Doc from io.netty5.channel.socket.DatagramChannel.leaveGroup.

Leave the specified multicast group at the specified interface using the specified source and notifies the Future once the operation completes.

If the underlying implementation does not support this operation it will return a Future which is failed with an UnsupportedOperationException.

Parameters
multicastAddress:InetAddress

the multicast group address.

networkInterface:NetworkInterface

the interface to use.

source:InetAddress

the source address (might be null).

Returns:Future<Void>

a Future which is notified once the operation completes.

Annotations
@Override
localAddress0back to summary
protected SocketAddress localAddress0()

Implements abstract io.netty5.channel.AbstractChannel.localAddress0.

Doc from io.netty5.channel.AbstractChannel.localAddress0.

Returns the SocketAddress which is bound locally.

Returns:SocketAddress

the local address if any, null otherwise.

Annotations
@Override
networkInterfaceback to summary
private NetworkInterface networkInterface() throws SocketException
newSocketback to summary
private static DatagramChannel newSocket(SelectorProvider provider)
newSocketback to summary
private static DatagramChannel newSocket(SelectorProvider provider, ProtocolFamily family)
remoteAddress0back to summary
protected SocketAddress remoteAddress0()

Implements abstract io.netty5.channel.AbstractChannel.remoteAddress0.

Doc from io.netty5.channel.AbstractChannel.remoteAddress0.

Return the SocketAddress which the Channel is connected to.

Returns:SocketAddress

the remote address if any, null otherwise.

Annotations
@Override
setActiveOnOpenback to summary
private void setActiveOnOpen(boolean activeOnOpen)
setExtendedOptionback to summary
protected <T> void setExtendedOption(ChannelOption<T> option, T value)

Overrides io.netty5.channel.AbstractChannel.setExtendedOption.

Doc from io.netty5.channel.AbstractChannel.setExtendedOption.

Override to add support for more ChannelOptions. You need to also call super after handling the extra options.

Parameters
<T>
the value type.
option:ChannelOption<T>

the ChannelOption.

Annotations
@Override
writeback to summary
private int write(Buffer buf, SocketAddress remoteAddress) throws IOException