- 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 NIODatagramChannelthat 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 givenSelectorProviderwhich will use the Operation Systems defaultProtocolFamily.NioDatagramChannel(EventLoop eventLoop, SelectorProvider provider, ProtocolFamily family)Create a new instance using the givenSelectorProviderandProtocolFamily.
-
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 booleancloseOnReadError(Throwable cause)protected booleancontinueOnWriteError()Returnstrueif we should continue the write loop on a write error.protected booleancontinueReading(RecvBufferAllocator.Handle allocHandle)protected voiddoBind(SocketAddress localAddress)Bind theChannelto theSocketAddressprotected booleandoConnect(SocketAddress remoteAddress, SocketAddress localAddress)Connect to remote peer.protected voiddoDisconnect()Disconnect thisChannelfrom its remote peerprotected booleandoFinishConnect(SocketAddress requestedRemoteAddress)Finish a connect request.protected intdoReadMessages(List<Object> buf)Read messages into the given array and return the amount which was read.protected voiddoShutdown(ChannelShutdownDirection direction)Shutdown one direction of theChannel.protected booleandoWriteMessage(Object msg, ChannelOutboundBuffer in)Write a message to the underlyingChannel.protected ObjectfilterOutboundMessage(Object msg)Invoked when a new message is added to aChannelOutboundBufferof thisAbstractChannel, so that theChannelimplementation converts the message to another.protected <T> TgetExtendedOption(ChannelOption<T> option)Override to add support for moreChannelOptions.booleanisActive()Returntrueif theChannelis active and so connected.booleanisConnected()Returntrueif theDatagramChannelis connected to the remote peer.protected booleanisExtendedOptionSupported(ChannelOption<?> option)Override to add support for moreChannelOptions.booleanisShutdown(ChannelShutdownDirection direction)protected DatagramChanneljavaChannel()Future<Void>joinGroup(InetAddress multicastAddress)Joins a multicast group and notifies theFutureonce the operation completes.Future<Void>joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)Joins the specified multicast group at the specified interface and notifies theFutureonce the operation completes.Future<Void>leaveGroup(InetAddress multicastAddress)Leaves a multicast group and notifies theFutureonce 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 theFutureonce the operation completes.protected SocketAddresslocalAddress0()Returns theSocketAddresswhich is bound locally.protected SocketAddressremoteAddress0()Return theSocketAddresswhich theChannelis connected to.protected <T> voidsetExtendedOption(ChannelOption<T> option, T value)Override to add support for moreChannelOptions.-
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 givenSelectorProviderwhich will use the Operation Systems defaultProtocolFamily.
-
NioDatagramChannel
public NioDatagramChannel(EventLoop eventLoop, ProtocolFamily family)
Create a new instance using the givenProtocolFamily. Ifnullis 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 givenSelectorProviderandProtocolFamily. IfProtocolFamilyisnullit 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:AbstractChannelOverride to add support for moreChannelOptions. You need to also call {@link super} after handling the extra options.- Overrides:
getExtendedOptionin 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:AbstractChannelOverride to add support for moreChannelOptions. You need to also call {@link super} after handling the extra options.- Overrides:
setExtendedOptionin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Type Parameters:
T- the value type.- Parameters:
option- theChannelOption.
-
isExtendedOptionSupported
protected boolean isExtendedOptionSupported(ChannelOption<?> option)
Description copied from class:AbstractChannelOverride to add support for moreChannelOptions. You need to also call {@link super} after handling the extra options.- Overrides:
isExtendedOptionSupportedin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Parameters:
option- theChannelOption.- Returns:
trueif supported,falseotherwise.
-
doShutdown
protected void doShutdown(ChannelShutdownDirection direction)
Description copied from class:AbstractChannelShutdown one direction of theChannel.- Specified by:
doShutdownin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Parameters:
direction- the direction to shutdown.
-
isShutdown
public boolean isShutdown(ChannelShutdownDirection direction)
Description copied from interface:Channel- Specified by:
isShutdownin interfaceChannel
-
isActive
public boolean isActive()
Description copied from interface:ChannelReturntrueif theChannelis active and so connected.
-
isConnected
public boolean isConnected()
Description copied from interface:DatagramChannelReturntrueif theDatagramChannelis connected to the remote peer.- Specified by:
isConnectedin interfaceDatagramChannel
-
javaChannel
protected DatagramChannel javaChannel()
- Overrides:
javaChannelin classAbstractNioChannel<Channel,SocketAddress,SocketAddress>
-
localAddress0
protected SocketAddress localAddress0()
Description copied from class:AbstractChannelReturns theSocketAddresswhich is bound locally.- Specified by:
localAddress0in classAbstractChannel<Channel,SocketAddress,SocketAddress>
-
remoteAddress0
protected SocketAddress remoteAddress0()
Description copied from class:AbstractChannelReturn theSocketAddresswhich theChannelis connected to.- Specified by:
remoteAddress0in classAbstractChannel<Channel,SocketAddress,SocketAddress>
-
doBind
protected void doBind(SocketAddress localAddress) throws Exception
Description copied from class:AbstractChannelBind theChannelto theSocketAddress- Specified by:
doBindin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Throws:
Exception
-
doConnect
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception
Description copied from class:AbstractChannelConnect to remote peer.- Specified by:
doConnectin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Parameters:
remoteAddress- the address of the remote peer.localAddress- the local address of this channel.- Returns:
trueif the connect was completed,falseifAbstractChannel.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:AbstractChannelFinish a connect request.- Specified by:
doFinishConnectin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Parameters:
requestedRemoteAddress- the remote address of the peer.- Returns:
trueif the connect was completed,falseifAbstractChannel.finishConnect()will be called later again to try finishing the connect.
-
doDisconnect
protected void doDisconnect() throws ExceptionDescription copied from class:AbstractChannelDisconnect thisChannelfrom its remote peer- Specified by:
doDisconnectin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Throws:
Exception
-
doReadMessages
protected int doReadMessages(List<Object> buf) throws Exception
Description copied from class:AbstractNioMessageChannelRead messages into the given array and return the amount which was read.- Specified by:
doReadMessagesin classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>- Throws:
Exception
-
doWriteMessage
protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Exception
Description copied from class:AbstractNioMessageChannelWrite a message to the underlyingChannel.- Specified by:
doWriteMessagein classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>- Returns:
trueif and only if the message has been written- Throws:
Exception
-
filterOutboundMessage
protected Object filterOutboundMessage(Object msg)
Description copied from class:AbstractChannelInvoked when a new message is added to aChannelOutboundBufferof thisAbstractChannel, so that theChannelimplementation converts the message to another. (e.g. heap buffer -> direct buffer)- Overrides:
filterOutboundMessagein classAbstractChannel<Channel,SocketAddress,SocketAddress>
-
continueOnWriteError
protected boolean continueOnWriteError()
Description copied from class:AbstractNioMessageChannelReturnstrueif we should continue the write loop on a write error.- Overrides:
continueOnWriteErrorin classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
-
joinGroup
public Future<Void> joinGroup(InetAddress multicastAddress)
Description copied from interface:DatagramChannelJoins a multicast group and notifies theFutureonce the operation completes.If the underlying implementation does not support this operation it will return a
Futurewhich is failed with anUnsupportedOperationException.- Specified by:
joinGroupin interfaceDatagramChannel- Parameters:
multicastAddress- the multicast group address.- Returns:
- a
Futurewhich is notified once the operation completes.
-
joinGroup
public Future<Void> joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)
Description copied from interface:DatagramChannelJoins the specified multicast group at the specified interface and notifies theFutureonce the operation completes.If the underlying implementation does not support this operation it will return a
Futurewhich is failed with anUnsupportedOperationException.- Specified by:
joinGroupin interfaceDatagramChannel- Parameters:
multicastAddress- the multicast group address.networkInterface- the interface to use.source- the source address (might benull).- Returns:
- a
Futurewhich is notified once the operation completes.
-
leaveGroup
public Future<Void> leaveGroup(InetAddress multicastAddress)
Description copied from interface:DatagramChannelLeaves a multicast group and notifies theFutureonce the operation completes.If the underlying implementation does not support this operation it will return a
Futurewhich is failed with anUnsupportedOperationException.- Specified by:
leaveGroupin interfaceDatagramChannel- Parameters:
multicastAddress- the multicast group address.- Returns:
- a
Futurewhich is notified once the operation completes.
-
leaveGroup
public Future<Void> leaveGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)
Description copied from interface:DatagramChannelLeave the specified multicast group at the specified interface using the specified source and notifies theFutureonce the operation completes.If the underlying implementation does not support this operation it will return a
Futurewhich is failed with anUnsupportedOperationException.- Specified by:
leaveGroupin interfaceDatagramChannel- Parameters:
multicastAddress- the multicast group address.networkInterface- the interface to use.source- the source address (might benull).- Returns:
- a
Futurewhich 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:
blockin interfaceDatagramChannel- Parameters:
multicastAddress- the multicast group address.networkInterface- the interface to use.sourceToBlock- the source address.- Returns:
- a
Futurewhich 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:
blockin interfaceDatagramChannel- Parameters:
multicastAddress- the multicast group address.sourceToBlock- the source address.- Returns:
- a
Futurewhich is notified once the operation completes.
-
closeOnReadError
protected boolean closeOnReadError(Throwable cause)
- Overrides:
closeOnReadErrorin classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
-
continueReading
protected boolean continueReading(RecvBufferAllocator.Handle allocHandle)
- Overrides:
continueReadingin classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
-
-