Class NioDatagramChannel
java.lang.Object
io.netty.util.DefaultAttributeMap
io.netty.channel.AbstractChannel
io.netty.channel.nio.AbstractNioChannel
io.netty.channel.nio.AbstractNioMessageChannel
io.netty.channel.socket.nio.NioDatagramChannel
- All Implemented Interfaces:
Channel, ChannelOutboundInvoker, DatagramChannel, AttributeMap, Comparable<Channel>
An NIO datagram
Channel that sends and receives an
AddressedEnvelopeinvalid input: '<'ByteBuf, SocketAddress>.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractNioChannel
AbstractNioChannel.AbstractNioUnsafe, AbstractNioChannel.NioUnsafeModifier and TypeClassDescriptionprotected classstatic interfaceSpecialChannel.Unsafesub-type which allows to access the underlyingSelectableChannelNested classes/interfaces inherited from class AbstractChannel
AbstractChannel.AbstractUnsafeModifier and TypeClassDescriptionprotected classChannel.Unsafeimplementation which sub-classes must extend and use.Nested classes/interfaces inherited from interface Channel
Channel.UnsafeModifier and TypeInterfaceDescriptionstatic interfaceUnsafe operations that should never be called from user-code. -
Field Summary
Fields inherited from class AbstractNioChannel
readInterestOp, readOps -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance which will use the Operation Systems defaultSocketProtocolFamily.NioDatagramChannel(InternetProtocolFamily ipFamily) Deprecated.NioDatagramChannel(SocketProtocolFamily protocolFamily) Create a new instance using the givenSocketProtocolFamily.NioDatagramChannel(DatagramChannel socket) Create a new instance from the givenDatagramChannel.NioDatagramChannel(SelectorProvider provider) Create a new instance using the givenSelectorProviderwhich will use the Operation Systems defaultSocketProtocolFamily.NioDatagramChannel(SelectorProvider provider, InternetProtocolFamily ipFamily) Deprecated.NioDatagramChannel(SelectorProvider provider, SocketProtocolFamily protocolFamily) Create a new instance using the givenSelectorProviderandSocketProtocolFamily. -
Method Summary
Modifier and TypeMethodDescriptionblock(InetAddress multicastAddress, InetAddress sourceToBlock) Block the given sourceToBlock address for the given multicastAddressblock(InetAddress multicastAddress, InetAddress sourceToBlock, ChannelPromise promise) Block the given sourceToBlock address for the given multicastAddressblock(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress sourceToBlock) Block the given sourceToBlock address for the given multicastAddress on the given networkInterfaceblock(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress sourceToBlock, ChannelPromise promise) Block the given sourceToBlock address for the given multicastAddress on the given networkInterfaceprotected booleancloseOnReadError(Throwable cause) config()Returns the configuration of this channel.protected booleanReturnstrueif we should continue the write loop on a write error.protected booleancontinueReading(RecvByteBufAllocator.Handle allocHandle) protected voiddoBind(SocketAddress localAddress) Bind theChannelto theSocketAddressprotected voiddoClose()Close theChannelprotected booleandoConnect(SocketAddress remoteAddress, SocketAddress localAddress) Connect to the remote peerprotected voidDisconnect thisChannelfrom its remote peerprotected voidFinish the connectprotected intdoReadMessages(List<Object> buf) Read messages into the given array and return the amount which was read.protected booleandoWriteMessage(Object msg, ChannelOutboundBuffer in) Write a message to the underlyingChannel.protected ObjectInvoked when a new message is added to aChannelOutboundBufferof thisAbstractChannel, so that theChannelimplementation converts the message to another.booleanisActive()Returntrueif theChannelis active and so connected.booleanReturntrueif theDatagramChannelis connected to the remote peer.protected DatagramChanneljoinGroup(InetAddress multicastAddress) Joins a multicast group and notifies theChannelFutureonce the operation completes.joinGroup(InetAddress multicastAddress, ChannelPromise promise) Joins a multicast group and notifies theChannelFutureonce the operation completes.joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source) Joins the specified multicast group at the specified interface and notifies theChannelFutureonce the operation completes.joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source, ChannelPromise promise) Joins the specified multicast group at the specified interface and notifies theChannelFutureonce the operation completes.joinGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface) Joins the specified multicast group at the specified interface and notifies theChannelFutureonce the operation completes.joinGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface, ChannelPromise promise) Joins the specified multicast group at the specified interface and notifies theChannelFutureonce the operation completes.leaveGroup(InetAddress multicastAddress) Leaves a multicast group and notifies theChannelFutureonce the operation completes.leaveGroup(InetAddress multicastAddress, ChannelPromise promise) Leaves a multicast group and notifies theChannelFutureonce the operation completes.leaveGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source) Leave the specified multicast group at the specified interface using the specified source and notifies theChannelFutureonce the operation completes.leaveGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source, ChannelPromise promise) Leave the specified multicast group at the specified interface using the specified source and notifies theChannelFutureonce the operation completes.leaveGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface) Leaves a multicast group on a specified local interface and notifies theChannelFutureonce the operation completes.leaveGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface, ChannelPromise promise) Leaves a multicast group on a specified local interface and notifies theChannelFutureonce the operation completes.Returns the local address where this channel is bound to.protected SocketAddressReturns theSocketAddresswhich is bound locally.metadata()Returns the remote address where this channel is connected to.protected SocketAddressReturn theSocketAddresswhich theChannelis connected to.protected voidsetReadPending(boolean readPending) Deprecated.Methods inherited from class AbstractNioMessageChannel
doBeginRead, doWrite, newUnsafeModifier and TypeMethodDescriptionprotected voidSchedule a read operation.protected voidFlush the content of the given buffer to the remote peer.protected AbstractNioChannel.AbstractNioUnsafeCreate a newAbstractChannel.AbstractUnsafeinstance which will be used for the life-time of theChannelMethods inherited from class AbstractNioChannel
addAndSubmit, clearReadPending, doDeregister, doRegister, isCompatible, isOpen, isReadPending, newDirectBuffer, newDirectBuffer, registration, removeAndSubmit, selectionKey, unsafeModifier and TypeMethodDescriptionprotected voidaddAndSubmit(NioIoOps addOps) protected final voidSet read pending tofalse.protected voidprotected voiddoRegister(ChannelPromise promise) protected booleanisCompatible(EventLoop loop) Returntrueif the givenEventLoopis compatible with this instance.booleanisOpen()Returnstrueif theChannelis open and may get active laterprotected booleanDeprecated.No longer supported.protected final ByteBufnewDirectBuffer(ByteBuf buf) Returns an off-heap copy of the specifiedByteBuf, and releases the original one.protected final ByteBufnewDirectBuffer(ReferenceCounted holder, ByteBuf buf) Returns an off-heap copy of the specifiedByteBuf, and releases the specified holder.protected IoRegistrationprotected voidremoveAndSubmit(NioIoOps removeOps) protected SelectionKeyDeprecated.useAbstractNioChannel.registration.unsafe()Returns an internal-use-only object that provides unsafe operations.Methods inherited from class AbstractChannel
closeFuture, compareTo, doRegister, doShutdownOutput, equals, eventLoop, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, maxMessagesPerWrite, newChannelPipeline, newId, parent, pipeline, toString, validateFileRegion, voidPromiseModifier and TypeMethodDescriptionReturns theChannelFuturewhich will be notified when this channel is closed.final intprotected voidDeprecated.protected voidCalled when conditions justify shutting down the output portion of the channel.final booleanReturnstrueif and only if the specified object is identical with this channel (i.e:this == o).final inthashCode()Returns the ID of this channel.final ChannelIdid()Returns the globally unique identifier of thisChannel.protected voidDeprecated.no use-case for this.protected voidDeprecated.no use-case for this.booleanprotected final intprotected DefaultChannelPipelineReturns a newDefaultChannelPipelineinstance.protected ChannelIdnewId()Returns a newDefaultChannelIdinstance.parent()Returns the parent of this channel.pipeline()Return the assignedChannelPipeline.toString()Returns theStringrepresentation of this channel.protected voidvalidateFileRegion(DefaultFileRegion region, long position) final ChannelPromiseReturn a special ChannelPromise which can be reused for different operations.Methods inherited from class DefaultAttributeMap
attr, hasAttrModifier and TypeMethodDescription<T> Attribute<T> attr(AttributeKey<T> key) Get theAttributefor the givenAttributeKey.<T> booleanhasAttr(AttributeKey<T> key) Methods inherited from interface Channel
alloc, bind, bind, bytesBeforeUnwritable, bytesBeforeWritable, close, close, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, flush, getOption, isWritable, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, read, setOption, write, write, writeAndFlush, writeAndFlushModifier and TypeMethodDescriptiondefault ByteBufAllocatoralloc()Return the assignedByteBufAllocatorwhich will be used to allocateByteBufs.default ChannelFuturebind(SocketAddress localAddress) Request to bind to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default ChannelFuturebind(SocketAddress localAddress, ChannelPromise promise) Request to bind to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default longGet how many bytes can be written untilChannel.isWritable()returnsfalse.default longGet how many bytes must be drained from underlying buffers untilChannel.isWritable()returnstrue.default ChannelFutureclose()Request to close theChanneland notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default ChannelFutureclose(ChannelPromise promise) Request to close theChanneland notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default ChannelFutureconnect(SocketAddress remoteAddress) Request to connect to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default ChannelFutureconnect(SocketAddress remoteAddress, ChannelPromise promise) Request to connect to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default ChannelFutureconnect(SocketAddress remoteAddress, SocketAddress localAddress) Request to connect to the givenSocketAddresswhile bind to the localAddress and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default ChannelFutureconnect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) Request to connect to the givenSocketAddresswhile bind to the localAddress and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default ChannelFutureRequest to deregister from the previous assignedEventExecutorand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default ChannelFuturederegister(ChannelPromise promise) Request to deregister from the previous assignedEventExecutorand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default ChannelFutureRequest to disconnect from the remote peer and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default ChannelFuturedisconnect(ChannelPromise promise) Request to disconnect from the remote peer and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.default Channelflush()Request to flush all pending messages via this ChannelOutboundInvoker.default <T> TgetOption(ChannelOption<T> option) Return the value of the givenChannelOptiondefault booleanReturnstrueif and only if the I/O thread will perform the requested write operation immediately.default ChannelFuturenewFailedFuture(Throwable cause) Create a newChannelFuturewhich is marked as failed already.default ChannelProgressivePromiseReturn an newChannelProgressivePromisedefault ChannelPromiseReturn a newChannelPromise.default ChannelFutureCreate a newChannelFuturewhich is marked as succeeded already.default Channelread()Request to Read data from theChannelinto the first inbound buffer, triggers anChannelInboundHandler.channelRead(ChannelHandlerContext, Object)event if data was read, and triggers achannelReadCompleteevent so the handler can decide to continue reading.default <T> booleansetOption(ChannelOption<T> option, T value) Sets a configuration property with the specified name and value.default ChannelFutureRequest to write a message via thisChannelHandlerContextthrough theChannelPipeline.default ChannelFuturewrite(Object msg, ChannelPromise promise) Request to write a message via thisChannelHandlerContextthrough theChannelPipeline.default ChannelFuturewriteAndFlush(Object msg) Shortcut for callChannelOutboundInvoker.write(Object)andChannelOutboundInvoker.flush().default ChannelFuturewriteAndFlush(Object msg, ChannelPromise promise) Shortcut for callChannelOutboundInvoker.write(Object, ChannelPromise)andChannelOutboundInvoker.flush().
-
Constructor Details
-
NioDatagramChannel
public NioDatagramChannel()Create a new instance which will use the Operation Systems defaultSocketProtocolFamily. -
NioDatagramChannel
Create a new instance using the givenSelectorProviderwhich will use the Operation Systems defaultSocketProtocolFamily. -
NioDatagramChannel
Deprecated.Create a new instance using the givenInternetProtocolFamily. Ifnullis used it will depend on the Operation Systems default which will be chosen. -
NioDatagramChannel
Create a new instance using the givenSocketProtocolFamily. Ifnullis used it will depend on the Operation Systems default which will be chosen. -
NioDatagramChannel
Deprecated.Create a new instance using the givenSelectorProviderandInternetProtocolFamily. IfInternetProtocolFamilyisnullit will depend on the Operation Systems default which will be chosen. -
NioDatagramChannel
Create a new instance using the givenSelectorProviderandSocketProtocolFamily. IfSocketProtocolFamilyisnullit will depend on the Operation Systems default which will be chosen. -
NioDatagramChannel
Create a new instance from the givenDatagramChannel.
-
-
Method Details
-
metadata
Description copied from interface:Channel -
config
Description copied from interface:ChannelReturns the configuration of this channel.- Specified by:
configin interfaceChannel- Specified by:
configin interfaceDatagramChannel
-
isActive
-
isConnected
public boolean isConnected()Description copied from interface:DatagramChannelReturntrueif theDatagramChannelis connected to the remote peer.- Specified by:
isConnectedin interfaceDatagramChannel
-
javaChannel
- Overrides:
javaChannelin classAbstractNioChannel
-
localAddress0
Description copied from class:AbstractChannelReturns theSocketAddresswhich is bound locally.- Specified by:
localAddress0in classAbstractChannel
-
remoteAddress0
Description copied from class:AbstractChannelReturn theSocketAddresswhich theChannelis connected to.- Specified by:
remoteAddress0in classAbstractChannel
-
doBind
Description copied from class:AbstractChannelBind theChannelto theSocketAddress- Specified by:
doBindin classAbstractChannel- Throws:
Exception
-
doConnect
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception Description copied from class:AbstractNioChannelConnect to the remote peer- Specified by:
doConnectin classAbstractNioChannel- Throws:
Exception
-
doFinishConnect
Description copied from class:AbstractNioChannelFinish the connect- Specified by:
doFinishConnectin classAbstractNioChannel- Throws:
Exception
-
doDisconnect
Description copied from class:AbstractChannelDisconnect thisChannelfrom its remote peer- Specified by:
doDisconnectin classAbstractChannel- Throws:
Exception
-
doClose
Description copied from class:AbstractChannelClose theChannel- Overrides:
doClosein classAbstractNioChannel- Throws:
Exception
-
doReadMessages
Description copied from class:AbstractNioMessageChannelRead messages into the given array and return the amount which was read.- Specified by:
doReadMessagesin classAbstractNioMessageChannel- Throws:
Exception
-
doWriteMessage
Description copied from class:AbstractNioMessageChannelWrite a message to the underlyingChannel.- Specified by:
doWriteMessagein classAbstractNioMessageChannel- Returns:
trueif and only if the message has been written- Throws:
Exception
-
filterOutboundMessage
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
-
continueOnWriteError
protected boolean continueOnWriteError()Description copied from class:AbstractNioMessageChannelReturnstrueif we should continue the write loop on a write error.- Overrides:
continueOnWriteErrorin classAbstractNioMessageChannel
-
localAddress
Description copied from interface:ChannelReturns the local address where this channel is bound to. The returnedSocketAddressis supposed to be down-cast into more concrete type such asInetSocketAddressto retrieve the detailed information.- Specified by:
localAddressin interfaceChannel- Specified by:
localAddressin interfaceDatagramChannel- Overrides:
localAddressin classAbstractChannel- Returns:
- the local address of this channel.
nullif this channel is not bound.
-
remoteAddress
Description copied from interface:ChannelReturns the remote address where this channel is connected to. The returnedSocketAddressis supposed to be down-cast into more concrete type such asInetSocketAddressto retrieve the detailed information.- Specified by:
remoteAddressin interfaceChannel- Specified by:
remoteAddressin interfaceDatagramChannel- Overrides:
remoteAddressin classAbstractChannel- Returns:
- the remote address of this channel.
nullif this channel is not connected. If this channel is not connected but it can receive messages from arbitrary remote addresses (e.g.DatagramChannel, useDefaultAddressedEnvelope.recipient()to determine the origination of the received message as this method will returnnull.
-
joinGroup
Description copied from interface:DatagramChannelJoins a multicast group and notifies theChannelFutureonce the operation completes.- Specified by:
joinGroupin interfaceDatagramChannel
-
joinGroup
Description copied from interface:DatagramChannelJoins a multicast group and notifies theChannelFutureonce the operation completes. The givenChannelFuturewill be notified and also returned.- Specified by:
joinGroupin interfaceDatagramChannel
-
joinGroup
public ChannelFuture joinGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface) Description copied from interface:DatagramChannelJoins the specified multicast group at the specified interface and notifies theChannelFutureonce the operation completes.- Specified by:
joinGroupin interfaceDatagramChannel
-
joinGroup
public ChannelFuture joinGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface, ChannelPromise promise) Description copied from interface:DatagramChannelJoins the specified multicast group at the specified interface and notifies theChannelFutureonce the operation completes. The givenChannelFuturewill be notified and also returned.- Specified by:
joinGroupin interfaceDatagramChannel
-
joinGroup
public ChannelFuture joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source) Description copied from interface:DatagramChannelJoins the specified multicast group at the specified interface and notifies theChannelFutureonce the operation completes.- Specified by:
joinGroupin interfaceDatagramChannel
-
joinGroup
public ChannelFuture joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source, ChannelPromise promise) Description copied from interface:DatagramChannelJoins the specified multicast group at the specified interface and notifies theChannelFutureonce the operation completes. The givenChannelFuturewill be notified and also returned.- Specified by:
joinGroupin interfaceDatagramChannel
-
leaveGroup
Description copied from interface:DatagramChannelLeaves a multicast group and notifies theChannelFutureonce the operation completes.- Specified by:
leaveGroupin interfaceDatagramChannel
-
leaveGroup
Description copied from interface:DatagramChannelLeaves a multicast group and notifies theChannelFutureonce the operation completes. The givenChannelFuturewill be notified and also returned.- Specified by:
leaveGroupin interfaceDatagramChannel
-
leaveGroup
public ChannelFuture leaveGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface) Description copied from interface:DatagramChannelLeaves a multicast group on a specified local interface and notifies theChannelFutureonce the operation completes.- Specified by:
leaveGroupin interfaceDatagramChannel
-
leaveGroup
public ChannelFuture leaveGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface, ChannelPromise promise) Description copied from interface:DatagramChannelLeaves a multicast group on a specified local interface and notifies theChannelFutureonce the operation completes. The givenChannelFuturewill be notified and also returned.- Specified by:
leaveGroupin interfaceDatagramChannel
-
leaveGroup
public ChannelFuture 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 theChannelFutureonce the operation completes.- Specified by:
leaveGroupin interfaceDatagramChannel
-
leaveGroup
public ChannelFuture leaveGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source, ChannelPromise promise) Description copied from interface:DatagramChannelLeave the specified multicast group at the specified interface using the specified source and notifies theChannelFutureonce the operation completes. The givenChannelFuturewill be notified and also returned.- Specified by:
leaveGroupin interfaceDatagramChannel
-
block
public ChannelFuture block(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress sourceToBlock) Block the given sourceToBlock address for the given multicastAddress on the given networkInterface- Specified by:
blockin interfaceDatagramChannel
-
block
public ChannelFuture block(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress sourceToBlock, ChannelPromise promise) Block the given sourceToBlock address for the given multicastAddress on the given networkInterface- Specified by:
blockin interfaceDatagramChannel
-
block
Block the given sourceToBlock address for the given multicastAddress- Specified by:
blockin interfaceDatagramChannel
-
block
public ChannelFuture block(InetAddress multicastAddress, InetAddress sourceToBlock, ChannelPromise promise) Block the given sourceToBlock address for the given multicastAddress- Specified by:
blockin interfaceDatagramChannel
-
setReadPending
Deprecated.- Overrides:
setReadPendingin classAbstractNioChannel
-
closeOnReadError
- Overrides:
closeOnReadErrorin classAbstractNioMessageChannel
-
continueReading
- Overrides:
continueReadingin classAbstractNioMessageChannel
-
NioDatagramChannel(SocketProtocolFamily)