- 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,io.netty5.util.AttributeMap,io.netty5.util.concurrent.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, AbstractChannel.ReadSink, AbstractChannel.WriteSink
-
-
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 io.netty5.util.concurrent.Future<Void>block(InetAddress multicastAddress, InetAddress sourceToBlock)Block the given sourceToBlock address for the given multicastAddressio.netty5.util.concurrent.Future<Void>block(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress sourceToBlock)Block the given sourceToBlock address for the given multicastAddress on the given networkInterfaceprotected voiddoBind(SocketAddress localAddress)Bind theChannelto theSocketAddressprotected booleandoConnect(SocketAddress remoteAddress, SocketAddress localAddress, io.netty5.buffer.Buffer initialData)Connect to remote peer.protected voiddoDisconnect()Disconnect thisChannelfrom its remote peerprotected booleandoFinishConnect(SocketAddress requestedRemoteAddress)Finish a connect request.protected intdoReadMessages(AbstractChannel.ReadSink readSink)Read messages into the given array and return the amount which was read.protected voiddoShutdown(ChannelShutdownDirection direction)Shutdown one direction of theChannel.protected voiddoWriteNow(AbstractChannel.WriteSink writeSink)Called in a loop when writes should be performed until this method returnsfalseor there are no more messages to write.protected ObjectfilterOutboundMessage(Object msg)Invoked when a new message is added to to the outbound queue of 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()io.netty5.util.concurrent.Future<Void>joinGroup(InetAddress multicastAddress)Joins a multicast group and notifies theFutureonce the operation completes.io.netty5.util.concurrent.Future<Void>joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)Joins the specified multicast group at the specified interface and notifies theFutureonce the operation completes.io.netty5.util.concurrent.Future<Void>leaveGroup(InetAddress multicastAddress)Leaves a multicast group and notifies theFutureonce the operation completes.io.netty5.util.concurrent.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
doReadNow
-
Methods inherited from class io.netty5.channel.nio.AbstractNioChannel
doClearScheduledRead, doClose, doRead, isOpen, isWriteFlushedScheduled, newDirectBuffer, newDirectBuffer, selectionKey, writeLoopComplete
-
Methods inherited from class io.netty5.channel.AbstractChannel
bufferAllocator, cacheAddresses, closeFuture, closeTransport, compareTo, equals, executor, finishConnect, getOption, hashCode, id, isConnectPending, isOptionSupported, isReadPending, isRegistered, isSupportingDisconnect, localAddress, newChannelPipeline, newSupportedIdentityOptionsSet, parent, pipeline, prepareToClose, readBufferAllocator, readHandle, readIfIsAutoRead, readLoopComplete, readNow, remoteAddress, setOption, shutdownReadSide, toString, validateEventLoopGroup, validateFileRegion, writableBytes, writeFlushed, writeFlushedNow, writeHandle
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.Channel
bind, bufferAllocator, close, closeFuture, connect, connect, deregister, disconnect, executor, flush, getOption, id, isOpen, isOptionSupported, isWritable, localAddress, parent, pipeline, read, 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 callsuperafter 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 callsuperafter 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 shut down.
-
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>- Returns:
- the local address if any,
nullotherwise.
-
remoteAddress0
protected SocketAddress remoteAddress0()
Description copied from class:AbstractChannelReturn theSocketAddresswhich theChannelis connected to.- Specified by:
remoteAddress0in classAbstractChannel<Channel,SocketAddress,SocketAddress>- Returns:
- the remote address if any,
nullotherwise.
-
doBind
protected void doBind(SocketAddress localAddress) throws Exception
Description copied from class:AbstractChannelBind theChannelto theSocketAddress- Specified by:
doBindin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Parameters:
localAddress- theSocketAddressto bound to.- Throws:
Exception- when an error happens.
-
doConnect
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress, io.netty5.buffer.Buffer initialData) throws Exception
Description copied from class:AbstractChannelConnect to remote peer. This method should never be directly called.- Specified by:
doConnectin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Parameters:
remoteAddress- the address of the remote peer.localAddress- the local address of this channel.initialData- the initial data that is written during connect (ifChannelOption.TCP_FASTOPEN_CONNECTis supported and configured). If data is written care must be taken to update thereader offset.- Returns:
trueif the connect operation was completed,falseifAbstractChannel.finishConnect()will be called later again to try finish connecting.- Throws:
Exception- thrown on error.
-
doFinishConnect
protected boolean doFinishConnect(SocketAddress requestedRemoteAddress)
Description copied from class:AbstractChannelFinish a connect request. This method should never be directly called, useAbstractChannel.finishConnect()instead.- Specified by:
doFinishConnectin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Parameters:
requestedRemoteAddress- the remote address of the peer.- Returns:
trueif the connect operations was completed,falseifAbstractChannel.finishConnect()will be called later again to try finishing the connect operation.
-
doDisconnect
protected void doDisconnect() throws ExceptionDescription copied from class:AbstractChannelDisconnect thisChannelfrom its remote peer- Specified by:
doDisconnectin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Throws:
Exception- thrown on error.
-
doReadMessages
protected int doReadMessages(AbstractChannel.ReadSink readSink) 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
-
doWriteNow
protected void doWriteNow(AbstractChannel.WriteSink writeSink) throws Exception
Description copied from class:AbstractChannelCalled in a loop when writes should be performed until this method returnsfalseor there are no more messages to write. Implementations are responsible for handling partial writes, which for example means that ifBuffers are written partial implementations need to ensure thereaderOffsetis updated accordingly.- Specified by:
doWriteNowin classAbstractChannel<Channel,SocketAddress,SocketAddress>- Parameters:
writeSink- theAbstractChannel.WriteSinkthat must be completed with the write progress.AbstractChannel.WriteSink.complete(long, long, int, boolean)orAbstractChannel.WriteSink.complete(long, Throwable, boolean)must be called exactly once before this method returns non-exceptional.- Throws:
Exception- if an error happened during writing. This will also terminate the write loop.
-
filterOutboundMessage
protected Object filterOutboundMessage(Object msg)
Description copied from class:AbstractChannelInvoked when a new message is added to to the outbound queue of thisAbstractChannel, so that theChannelimplementation converts the message to another. (e.g. heap buffer -> direct buffer)- Overrides:
filterOutboundMessagein classAbstractChannel<Channel,SocketAddress,SocketAddress>- Parameters:
msg- the message to filter / convert.
-
joinGroup
public io.netty5.util.concurrent.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 io.netty5.util.concurrent.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 io.netty5.util.concurrent.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 io.netty5.util.concurrent.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 io.netty5.util.concurrent.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 io.netty5.util.concurrent.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.
-
-