- java.lang.Object
-
- io.netty5.util.DefaultAttributeMap
-
- io.netty5.channel.AbstractChannel<P,L,R>
-
- io.netty5.channel.nio.AbstractNioChannel<P,L,R>
-
- io.netty5.channel.nio.AbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
-
- io.netty5.channel.socket.nio.NioDatagramChannel
-
- All Implemented Interfaces:
Channel
,ChannelOutboundInvoker
,IoHandle
,DatagramChannel
,AttributeMap
,FuturePromiseFactory
,Comparable<Channel>
public final class NioDatagramChannel extends AbstractNioMessageChannel<Channel,SocketAddress,SocketAddress> implements DatagramChannel
An NIODatagramChannel
that sends and receives anAddressedEnvelope
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty5.channel.AbstractChannel
AbstractChannel.DefaultAbstractChannelPipeline
-
-
Field Summary
-
Fields inherited from class io.netty5.channel.nio.AbstractNioChannel
readInterestOp
-
-
Constructor Summary
Constructors Constructor Description NioDatagramChannel(EventLoop eventLoop)
Create a new instance which will use the Operation Systems defaultProtocolFamily
.NioDatagramChannel(EventLoop eventLoop, ProtocolFamily family)
Create a new instance using the givenProtocolFamily
.NioDatagramChannel(EventLoop eventLoop, DatagramChannel socket, ProtocolFamily family)
Create a new instance from the givenDatagramChannel
.NioDatagramChannel(EventLoop eventLoop, SelectorProvider provider)
Create a new instance using the givenSelectorProvider
which will use the Operation Systems defaultProtocolFamily
.NioDatagramChannel(EventLoop eventLoop, SelectorProvider provider, ProtocolFamily family)
Create a new instance using the givenSelectorProvider
andProtocolFamily
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Future<Void>
block(InetAddress multicastAddress, InetAddress sourceToBlock)
Block the given sourceToBlock address for the given multicastAddressFuture<Void>
block(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress sourceToBlock)
Block the given sourceToBlock address for the given multicastAddress on the given networkInterfaceprotected boolean
closeOnReadError(Throwable cause)
protected boolean
continueOnWriteError()
Returnstrue
if we should continue the write loop on a write error.protected boolean
continueReading(RecvBufferAllocator.Handle allocHandle)
protected void
doBind(SocketAddress localAddress)
Bind theChannel
to theSocketAddress
protected boolean
doConnect(SocketAddress remoteAddress, SocketAddress localAddress)
Connect to remote peer.protected void
doDisconnect()
Disconnect thisChannel
from its remote peerprotected boolean
doFinishConnect(SocketAddress requestedRemoteAddress)
Finish a connect request.protected int
doReadMessages(List<Object> buf)
Read messages into the given array and return the amount which was read.protected void
doShutdown(ChannelShutdownDirection direction)
Shutdown one direction of theChannel
.protected boolean
doWriteMessage(Object msg, ChannelOutboundBuffer in)
Write a message to the underlyingChannel
.protected Object
filterOutboundMessage(Object msg)
Invoked when a new message is added to aChannelOutboundBuffer
of thisAbstractChannel
, so that theChannel
implementation converts the message to another.protected <T> T
getExtendedOption(ChannelOption<T> option)
Override to add support for moreChannelOption
s.boolean
isActive()
Returntrue
if theChannel
is active and so connected.boolean
isConnected()
Returntrue
if theDatagramChannel
is connected to the remote peer.protected boolean
isExtendedOptionSupported(ChannelOption<?> option)
Override to add support for moreChannelOption
s.boolean
isShutdown(ChannelShutdownDirection direction)
protected DatagramChannel
javaChannel()
Future<Void>
joinGroup(InetAddress multicastAddress)
Joins a multicast group and notifies theFuture
once the operation completes.Future<Void>
joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)
Joins the specified multicast group at the specified interface and notifies theFuture
once the operation completes.Future<Void>
leaveGroup(InetAddress multicastAddress)
Leaves a multicast group and notifies theFuture
once the operation completes.Future<Void>
leaveGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)
Leave the specified multicast group at the specified interface using the specified source and notifies theFuture
once the operation completes.protected SocketAddress
localAddress0()
Returns theSocketAddress
which is bound locally.protected SocketAddress
remoteAddress0()
Return theSocketAddress
which theChannel
is connected to.protected <T> void
setExtendedOption(ChannelOption<T> option, T value)
Override to add support for moreChannelOption
s.-
Methods inherited from class io.netty5.channel.nio.AbstractNioMessageChannel
doBeginRead, doWrite, readNow
-
Methods inherited from class io.netty5.channel.nio.AbstractNioChannel
clearReadPending, doClose, isOpen, isReadPending, newDirectBuffer, newDirectBuffer, removeReadOp, selectionKey, setReadPending, writeFlushed
-
Methods inherited from class io.netty5.channel.AbstractChannel
annotateConnectException, assertEventLoop, autoReadCleared, bufferAllocator, cacheAddresses, closeForciblyTransport, closeFuture, closeIfClosed, closeTransport, compareTo, deregisterTransport, ensureOpen, equals, executor, finishConnect, fireChannelActiveIfNotActiveBefore, getMaxMessagesPerWrite, getOption, getWriteSpinCount, handleWriteError, hashCode, id, isAllowHalfClosure, isAutoRead, isConnectPending, isOptionSupported, isRegistered, localAddress, metadata, newChannelPipeline, newSupportedIdentityOptionsSet, outboundBuffer, parent, pipeline, prepareToClose, readIfIsAutoRead, recvBufAllocHandle, remoteAddress, runAfterTransportAction, safeSetFailure, safeSetSuccess, setBufferAllocator, setOption, shutdownTransport, toString, validate, validateEventLoopGroup, validateFileRegion, writableBytes
-
Methods inherited from class io.netty5.util.DefaultAttributeMap
attr, hasAttr
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.netty5.util.AttributeMap
attr, hasAttr
-
Methods inherited from interface io.netty5.channel.Channel
bind, bufferAllocator, close, closeFuture, connect, connect, deregister, disconnect, executor, flush, getOption, id, isOpen, isOptionSupported, isWritable, localAddress, metadata, parent, pipeline, read, register, remoteAddress, sendOutboundEvent, setOption, shutdown, writableBytes, write, writeAndFlush
-
Methods inherited from interface io.netty5.channel.ChannelOutboundInvoker
newFailedFuture, newPromise, newSucceededFuture, newSucceededFuture
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface io.netty5.channel.IoHandle
isRegistered
-
-
-
-
Constructor Detail
-
NioDatagramChannel
public NioDatagramChannel(EventLoop eventLoop)
Create a new instance which will use the Operation Systems defaultProtocolFamily
.
-
NioDatagramChannel
public NioDatagramChannel(EventLoop eventLoop, SelectorProvider provider)
Create a new instance using the givenSelectorProvider
which will use the Operation Systems defaultProtocolFamily
.
-
NioDatagramChannel
public NioDatagramChannel(EventLoop eventLoop, ProtocolFamily family)
Create a new instance using the givenProtocolFamily
. Ifnull
is used it will depend on the Operation Systems default which will be chosen.
-
NioDatagramChannel
public NioDatagramChannel(EventLoop eventLoop, SelectorProvider provider, ProtocolFamily family)
Create a new instance using the givenSelectorProvider
andProtocolFamily
. IfProtocolFamily
isnull
it will depend on the Operation Systems default which will be chosen.
-
NioDatagramChannel
public NioDatagramChannel(EventLoop eventLoop, DatagramChannel socket, ProtocolFamily family)
Create a new instance from the givenDatagramChannel
.
-
-
Method Detail
-
getExtendedOption
protected <T> T getExtendedOption(ChannelOption<T> option)
Description copied from class:AbstractChannel
Override to add support for moreChannelOption
s. You need to also call {@link super} after handling the extra options.- Overrides:
getExtendedOption
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Type Parameters:
T
- the value type.- Parameters:
option
- theChannelOption
.- Returns:
- the value for the option
-
setExtendedOption
protected <T> void setExtendedOption(ChannelOption<T> option, T value)
Description copied from class:AbstractChannel
Override to add support for moreChannelOption
s. You need to also call {@link super} after handling the extra options.- Overrides:
setExtendedOption
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Type Parameters:
T
- the value type.- Parameters:
option
- theChannelOption
.
-
isExtendedOptionSupported
protected boolean isExtendedOptionSupported(ChannelOption<?> option)
Description copied from class:AbstractChannel
Override to add support for moreChannelOption
s. You need to also call {@link super} after handling the extra options.- Overrides:
isExtendedOptionSupported
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Parameters:
option
- theChannelOption
.- Returns:
true
if supported,false
otherwise.
-
doShutdown
protected void doShutdown(ChannelShutdownDirection direction)
Description copied from class:AbstractChannel
Shutdown one direction of theChannel
.- Specified by:
doShutdown
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Parameters:
direction
- the direction to shutdown.
-
isShutdown
public boolean isShutdown(ChannelShutdownDirection direction)
Description copied from interface:Channel
- Specified by:
isShutdown
in interfaceChannel
-
isActive
public boolean isActive()
Description copied from interface:Channel
Returntrue
if theChannel
is active and so connected.
-
isConnected
public boolean isConnected()
Description copied from interface:DatagramChannel
Returntrue
if theDatagramChannel
is connected to the remote peer.- Specified by:
isConnected
in interfaceDatagramChannel
-
javaChannel
protected DatagramChannel javaChannel()
- Overrides:
javaChannel
in classAbstractNioChannel<Channel,SocketAddress,SocketAddress>
-
localAddress0
protected SocketAddress localAddress0()
Description copied from class:AbstractChannel
Returns theSocketAddress
which is bound locally.- Specified by:
localAddress0
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
-
remoteAddress0
protected SocketAddress remoteAddress0()
Description copied from class:AbstractChannel
Return theSocketAddress
which theChannel
is connected to.- Specified by:
remoteAddress0
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
-
doBind
protected void doBind(SocketAddress localAddress) throws Exception
Description copied from class:AbstractChannel
Bind theChannel
to theSocketAddress
- Specified by:
doBind
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Throws:
Exception
-
doConnect
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception
Description copied from class:AbstractChannel
Connect to remote peer.- Specified by:
doConnect
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Parameters:
remoteAddress
- the address of the remote peer.localAddress
- the local address of this channel.- Returns:
true
if the connect was completed,false
ifAbstractChannel.finishConnect()
will be called later again to try finishing the connect.- Throws:
Exception
- thrown on error.
-
doFinishConnect
protected boolean doFinishConnect(SocketAddress requestedRemoteAddress)
Description copied from class:AbstractChannel
Finish a connect request.- Specified by:
doFinishConnect
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Parameters:
requestedRemoteAddress
- the remote address of the peer.- Returns:
true
if the connect was completed,false
ifAbstractChannel.finishConnect()
will be called later again to try finishing the connect.
-
doDisconnect
protected void doDisconnect() throws Exception
Description copied from class:AbstractChannel
Disconnect thisChannel
from its remote peer- Specified by:
doDisconnect
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Throws:
Exception
-
doReadMessages
protected int doReadMessages(List<Object> buf) throws Exception
Description copied from class:AbstractNioMessageChannel
Read messages into the given array and return the amount which was read.- Specified by:
doReadMessages
in classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
- Throws:
Exception
-
doWriteMessage
protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Exception
Description copied from class:AbstractNioMessageChannel
Write a message to the underlyingChannel
.- Specified by:
doWriteMessage
in classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
- Returns:
true
if and only if the message has been written- Throws:
Exception
-
filterOutboundMessage
protected Object filterOutboundMessage(Object msg)
Description copied from class:AbstractChannel
Invoked when a new message is added to aChannelOutboundBuffer
of thisAbstractChannel
, so that theChannel
implementation converts the message to another. (e.g. heap buffer -> direct buffer)- Overrides:
filterOutboundMessage
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
-
continueOnWriteError
protected boolean continueOnWriteError()
Description copied from class:AbstractNioMessageChannel
Returnstrue
if we should continue the write loop on a write error.- Overrides:
continueOnWriteError
in classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
-
joinGroup
public Future<Void> joinGroup(InetAddress multicastAddress)
Description copied from interface:DatagramChannel
Joins a multicast group and notifies theFuture
once the operation completes.If the underlying implementation does not support this operation it will return a
Future
which is failed with anUnsupportedOperationException
.- Specified by:
joinGroup
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.- Returns:
- a
Future
which is notified once the operation completes.
-
joinGroup
public Future<Void> joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)
Description copied from interface:DatagramChannel
Joins the specified multicast group at the specified interface and notifies theFuture
once the operation completes.If the underlying implementation does not support this operation it will return a
Future
which is failed with anUnsupportedOperationException
.- Specified by:
joinGroup
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.networkInterface
- the interface to use.source
- the source address (might benull
).- Returns:
- a
Future
which is notified once the operation completes.
-
leaveGroup
public Future<Void> leaveGroup(InetAddress multicastAddress)
Description copied from interface:DatagramChannel
Leaves a multicast group and notifies theFuture
once the operation completes.If the underlying implementation does not support this operation it will return a
Future
which is failed with anUnsupportedOperationException
.- Specified by:
leaveGroup
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.- Returns:
- a
Future
which is notified once the operation completes.
-
leaveGroup
public Future<Void> leaveGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)
Description copied from interface:DatagramChannel
Leave the specified multicast group at the specified interface using the specified source and notifies theFuture
once the operation completes.If the underlying implementation does not support this operation it will return a
Future
which is failed with anUnsupportedOperationException
.- Specified by:
leaveGroup
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.networkInterface
- the interface to use.source
- the source address (might benull
).- Returns:
- a
Future
which is notified once the operation completes.
-
block
public Future<Void> block(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress sourceToBlock)
Block the given sourceToBlock address for the given multicastAddress on the given networkInterface- Specified by:
block
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.networkInterface
- the interface to use.sourceToBlock
- the source address.- Returns:
- a
Future
which is notified once the operation completes.
-
block
public Future<Void> block(InetAddress multicastAddress, InetAddress sourceToBlock)
Block the given sourceToBlock address for the given multicastAddress- Specified by:
block
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.sourceToBlock
- the source address.- Returns:
- a
Future
which is notified once the operation completes.
-
closeOnReadError
protected boolean closeOnReadError(Throwable cause)
- Overrides:
closeOnReadError
in classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
-
continueReading
protected boolean continueReading(RecvBufferAllocator.Handle allocHandle)
- Overrides:
continueReading
in classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
-
-