Package io.netty.channel.socket.nio
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
,java.lang.Comparable<Channel>
public final class NioDatagramChannel extends AbstractNioMessageChannel implements DatagramChannel
An NIO datagramChannel
that sends and receives anAddressedEnvelope
.- See Also:
AddressedEnvelope
,DatagramPacket
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty.channel.nio.AbstractNioChannel
AbstractNioChannel.AbstractNioUnsafe, AbstractNioChannel.NioUnsafe
-
Nested classes/interfaces inherited from class io.netty.channel.AbstractChannel
AbstractChannel.AbstractUnsafe
-
Nested classes/interfaces inherited from interface io.netty.channel.Channel
Channel.Unsafe
-
-
Field Summary
Fields Modifier and Type Field Description private DatagramChannelConfig
config
private static java.nio.channels.spi.SelectorProvider
DEFAULT_SELECTOR_PROVIDER
private static java.lang.String
EXPECTED_TYPES
private java.util.Map<java.net.InetAddress,java.util.List<java.nio.channels.MembershipKey>>
memberships
private static ChannelMetadata
METADATA
-
Fields inherited from class io.netty.channel.nio.AbstractNioChannel
readInterestOp
-
-
Constructor Summary
Constructors Constructor Description NioDatagramChannel()
Create a new instance which will use the Operation Systems defaultInternetProtocolFamily
.NioDatagramChannel(InternetProtocolFamily ipFamily)
Create a new instance using the givenInternetProtocolFamily
.NioDatagramChannel(java.nio.channels.DatagramChannel socket)
Create a new instance from the givenDatagramChannel
.NioDatagramChannel(java.nio.channels.spi.SelectorProvider provider)
Create a new instance using the givenSelectorProvider
which will use the Operation Systems defaultInternetProtocolFamily
.NioDatagramChannel(java.nio.channels.spi.SelectorProvider provider, InternetProtocolFamily ipFamily)
Create a new instance using the givenSelectorProvider
andInternetProtocolFamily
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ChannelFuture
block(java.net.InetAddress multicastAddress, java.net.InetAddress sourceToBlock)
Block the given sourceToBlock address for the given multicastAddressChannelFuture
block(java.net.InetAddress multicastAddress, java.net.InetAddress sourceToBlock, ChannelPromise promise)
Block the given sourceToBlock address for the given multicastAddressChannelFuture
block(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress sourceToBlock)
Block the given sourceToBlock address for the given multicastAddress on the given networkInterfaceChannelFuture
block(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress sourceToBlock, ChannelPromise promise)
Block the given sourceToBlock address for the given multicastAddress on the given networkInterfaceprivate static void
checkJavaVersion()
(package private) void
clearReadPending0()
protected boolean
closeOnReadError(java.lang.Throwable cause)
DatagramChannelConfig
config()
Returns the configuration of this channel.protected boolean
continueOnWriteError()
Returnstrue
if we should continue the write loop on a write error.protected void
doBind(java.net.SocketAddress localAddress)
Bind theChannel
to theSocketAddress
private void
doBind0(java.net.SocketAddress localAddress)
protected void
doClose()
Close theChannel
protected boolean
doConnect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress)
Connect to the remote peerprotected void
doDisconnect()
Disconnect thisChannel
from its remote peerprotected void
doFinishConnect()
Finish the connectprotected int
doReadMessages(java.util.List<java.lang.Object> buf)
Read messages into the given array and return the amount which was read.protected boolean
doWriteMessage(java.lang.Object msg, ChannelOutboundBuffer in)
Write a message to the underlyingChannel
.protected java.lang.Object
filterOutboundMessage(java.lang.Object msg)
Invoked when a new message is added to aChannelOutboundBuffer
of thisAbstractChannel
, so that theChannel
implementation converts the message to another.boolean
isActive()
Returntrue
if theChannel
is active and so connected.boolean
isConnected()
Returntrue
if theDatagramChannel
is connected to the remote peer.private static boolean
isSingleDirectBuffer(ByteBuf buf)
Checks if the specified buffer is a direct buffer and is composed of a single NIO buffer.protected java.nio.channels.DatagramChannel
javaChannel()
ChannelFuture
joinGroup(java.net.InetAddress multicastAddress)
Joins a multicast group and notifies theChannelFuture
once the operation completes.ChannelFuture
joinGroup(java.net.InetAddress multicastAddress, ChannelPromise promise)
Joins a multicast group and notifies theChannelFuture
once the operation completes.ChannelFuture
joinGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source)
Joins the specified multicast group at the specified interface and notifies theChannelFuture
once the operation completes.ChannelFuture
joinGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source, ChannelPromise promise)
Joins the specified multicast group at the specified interface and notifies theChannelFuture
once the operation completes.ChannelFuture
joinGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface)
Joins the specified multicast group at the specified interface and notifies theChannelFuture
once the operation completes.ChannelFuture
joinGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface, ChannelPromise promise)
Joins the specified multicast group at the specified interface and notifies theChannelFuture
once the operation completes.ChannelFuture
leaveGroup(java.net.InetAddress multicastAddress)
Leaves a multicast group and notifies theChannelFuture
once the operation completes.ChannelFuture
leaveGroup(java.net.InetAddress multicastAddress, ChannelPromise promise)
Leaves a multicast group and notifies theChannelFuture
once the operation completes.ChannelFuture
leaveGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source)
Leave the specified multicast group at the specified interface using the specified source and notifies theChannelFuture
once the operation completes.ChannelFuture
leaveGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source, ChannelPromise promise)
Leave the specified multicast group at the specified interface using the specified source and notifies theChannelFuture
once the operation completes.ChannelFuture
leaveGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface)
Leaves a multicast group on a specified local interface and notifies theChannelFuture
once the operation completes.ChannelFuture
leaveGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface, ChannelPromise promise)
Leaves a multicast group on a specified local interface and notifies theChannelFuture
once the operation completes.java.net.InetSocketAddress
localAddress()
Returns the local address where this channel is bound to.protected java.net.SocketAddress
localAddress0()
Returns theSocketAddress
which is bound locally.ChannelMetadata
metadata()
private static java.nio.channels.DatagramChannel
newSocket(java.nio.channels.spi.SelectorProvider provider)
private static java.nio.channels.DatagramChannel
newSocket(java.nio.channels.spi.SelectorProvider provider, InternetProtocolFamily ipFamily)
java.net.InetSocketAddress
remoteAddress()
Returns the remote address where this channel is connected to.protected java.net.SocketAddress
remoteAddress0()
Return theSocketAddress
which theChannel
is connected to.protected void
setReadPending(boolean readPending)
Deprecated.-
Methods inherited from class io.netty.channel.nio.AbstractNioMessageChannel
doBeginRead, doWrite, newUnsafe
-
Methods inherited from class io.netty.channel.nio.AbstractNioChannel
clearReadPending, doDeregister, doRegister, eventLoop, isCompatible, isOpen, isReadPending, newDirectBuffer, newDirectBuffer, selectionKey, unsafe
-
Methods inherited from class io.netty.channel.AbstractChannel
alloc, bind, bind, bytesBeforeUnwritable, bytesBeforeWritable, close, close, closeFuture, compareTo, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, doShutdownOutput, equals, flush, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, isWritable, newChannelPipeline, newFailedFuture, newId, newProgressivePromise, newPromise, newSucceededFuture, parent, pipeline, read, toString, validateFileRegion, voidPromise, write, write, writeAndFlush, writeAndFlush
-
Methods inherited from class io.netty.util.DefaultAttributeMap
attr, hasAttr
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.netty.util.AttributeMap
attr, hasAttr
-
Methods inherited from interface io.netty.channel.Channel
alloc, bytesBeforeUnwritable, bytesBeforeWritable, closeFuture, eventLoop, flush, id, isOpen, isRegistered, isWritable, parent, pipeline, read, unsafe
-
Methods inherited from interface io.netty.channel.ChannelOutboundInvoker
bind, bind, close, close, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, voidPromise, write, write, writeAndFlush, writeAndFlush
-
-
-
-
Field Detail
-
METADATA
private static final ChannelMetadata METADATA
-
DEFAULT_SELECTOR_PROVIDER
private static final java.nio.channels.spi.SelectorProvider DEFAULT_SELECTOR_PROVIDER
-
EXPECTED_TYPES
private static final java.lang.String EXPECTED_TYPES
-
config
private final DatagramChannelConfig config
-
memberships
private java.util.Map<java.net.InetAddress,java.util.List<java.nio.channels.MembershipKey>> memberships
-
-
Constructor Detail
-
NioDatagramChannel
public NioDatagramChannel()
Create a new instance which will use the Operation Systems defaultInternetProtocolFamily
.
-
NioDatagramChannel
public NioDatagramChannel(java.nio.channels.spi.SelectorProvider provider)
Create a new instance using the givenSelectorProvider
which will use the Operation Systems defaultInternetProtocolFamily
.
-
NioDatagramChannel
public NioDatagramChannel(InternetProtocolFamily ipFamily)
Create a new instance using the givenInternetProtocolFamily
. Ifnull
is used it will depend on the Operation Systems default which will be chosen.
-
NioDatagramChannel
public NioDatagramChannel(java.nio.channels.spi.SelectorProvider provider, InternetProtocolFamily ipFamily)
Create a new instance using the givenSelectorProvider
andInternetProtocolFamily
. IfInternetProtocolFamily
isnull
it will depend on the Operation Systems default which will be chosen.
-
NioDatagramChannel
public NioDatagramChannel(java.nio.channels.DatagramChannel socket)
Create a new instance from the givenDatagramChannel
.
-
-
Method Detail
-
newSocket
private static java.nio.channels.DatagramChannel newSocket(java.nio.channels.spi.SelectorProvider provider)
-
newSocket
private static java.nio.channels.DatagramChannel newSocket(java.nio.channels.spi.SelectorProvider provider, InternetProtocolFamily ipFamily)
-
checkJavaVersion
private static void checkJavaVersion()
-
metadata
public ChannelMetadata metadata()
Description copied from interface:Channel
-
config
public DatagramChannelConfig config()
Description copied from interface:Channel
Returns the configuration of this channel.- Specified by:
config
in interfaceChannel
- Specified by:
config
in interfaceDatagramChannel
-
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 java.nio.channels.DatagramChannel javaChannel()
- Overrides:
javaChannel
in classAbstractNioChannel
-
localAddress0
protected java.net.SocketAddress localAddress0()
Description copied from class:AbstractChannel
Returns theSocketAddress
which is bound locally.- Specified by:
localAddress0
in classAbstractChannel
-
remoteAddress0
protected java.net.SocketAddress remoteAddress0()
Description copied from class:AbstractChannel
Return theSocketAddress
which theChannel
is connected to.- Specified by:
remoteAddress0
in classAbstractChannel
-
doBind
protected void doBind(java.net.SocketAddress localAddress) throws java.lang.Exception
Description copied from class:AbstractChannel
Bind theChannel
to theSocketAddress
- Specified by:
doBind
in classAbstractChannel
- Throws:
java.lang.Exception
-
doBind0
private void doBind0(java.net.SocketAddress localAddress) throws java.lang.Exception
- Throws:
java.lang.Exception
-
doConnect
protected boolean doConnect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress) throws java.lang.Exception
Description copied from class:AbstractNioChannel
Connect to the remote peer- Specified by:
doConnect
in classAbstractNioChannel
- Throws:
java.lang.Exception
-
doFinishConnect
protected void doFinishConnect() throws java.lang.Exception
Description copied from class:AbstractNioChannel
Finish the connect- Specified by:
doFinishConnect
in classAbstractNioChannel
- Throws:
java.lang.Exception
-
doDisconnect
protected void doDisconnect() throws java.lang.Exception
Description copied from class:AbstractChannel
Disconnect thisChannel
from its remote peer- Specified by:
doDisconnect
in classAbstractChannel
- Throws:
java.lang.Exception
-
doClose
protected void doClose() throws java.lang.Exception
Description copied from class:AbstractChannel
Close theChannel
- Overrides:
doClose
in classAbstractNioChannel
- Throws:
java.lang.Exception
-
doReadMessages
protected int doReadMessages(java.util.List<java.lang.Object> buf) throws java.lang.Exception
Description copied from class:AbstractNioMessageChannel
Read messages into the given array and return the amount which was read.- Specified by:
doReadMessages
in classAbstractNioMessageChannel
- Throws:
java.lang.Exception
-
doWriteMessage
protected boolean doWriteMessage(java.lang.Object msg, ChannelOutboundBuffer in) throws java.lang.Exception
Description copied from class:AbstractNioMessageChannel
Write a message to the underlyingChannel
.- Specified by:
doWriteMessage
in classAbstractNioMessageChannel
- Returns:
true
if and only if the message has been written- Throws:
java.lang.Exception
-
filterOutboundMessage
protected java.lang.Object filterOutboundMessage(java.lang.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
-
isSingleDirectBuffer
private static boolean isSingleDirectBuffer(ByteBuf buf)
Checks if the specified buffer is a direct buffer and is composed of a single NIO buffer. (We check this because otherwise we need to make it a non-composite buffer.)
-
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
-
localAddress
public java.net.InetSocketAddress localAddress()
Description copied from interface:Channel
Returns the local address where this channel is bound to. The returnedSocketAddress
is supposed to be down-cast into more concrete type such asInetSocketAddress
to retrieve the detailed information.- Specified by:
localAddress
in interfaceChannel
- Specified by:
localAddress
in interfaceDatagramChannel
- Overrides:
localAddress
in classAbstractChannel
- Returns:
- the local address of this channel.
null
if this channel is not bound.
-
remoteAddress
public java.net.InetSocketAddress remoteAddress()
Description copied from interface:Channel
Returns the remote address where this channel is connected to. The returnedSocketAddress
is supposed to be down-cast into more concrete type such asInetSocketAddress
to retrieve the detailed information.- Specified by:
remoteAddress
in interfaceChannel
- Specified by:
remoteAddress
in interfaceDatagramChannel
- Overrides:
remoteAddress
in classAbstractChannel
- Returns:
- the remote address of this channel.
null
if 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
public ChannelFuture joinGroup(java.net.InetAddress multicastAddress)
Description copied from interface:DatagramChannel
Joins a multicast group and notifies theChannelFuture
once the operation completes.- Specified by:
joinGroup
in interfaceDatagramChannel
-
joinGroup
public ChannelFuture joinGroup(java.net.InetAddress multicastAddress, ChannelPromise promise)
Description copied from interface:DatagramChannel
Joins a multicast group and notifies theChannelFuture
once the operation completes. The givenChannelFuture
will be notified and also returned.- Specified by:
joinGroup
in interfaceDatagramChannel
-
joinGroup
public ChannelFuture joinGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface)
Description copied from interface:DatagramChannel
Joins the specified multicast group at the specified interface and notifies theChannelFuture
once the operation completes.- Specified by:
joinGroup
in interfaceDatagramChannel
-
joinGroup
public ChannelFuture joinGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface, ChannelPromise promise)
Description copied from interface:DatagramChannel
Joins the specified multicast group at the specified interface and notifies theChannelFuture
once the operation completes. The givenChannelFuture
will be notified and also returned.- Specified by:
joinGroup
in interfaceDatagramChannel
-
joinGroup
public ChannelFuture joinGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source)
Description copied from interface:DatagramChannel
Joins the specified multicast group at the specified interface and notifies theChannelFuture
once the operation completes.- Specified by:
joinGroup
in interfaceDatagramChannel
-
joinGroup
public ChannelFuture joinGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source, ChannelPromise promise)
Description copied from interface:DatagramChannel
Joins the specified multicast group at the specified interface and notifies theChannelFuture
once the operation completes. The givenChannelFuture
will be notified and also returned.- Specified by:
joinGroup
in interfaceDatagramChannel
-
leaveGroup
public ChannelFuture leaveGroup(java.net.InetAddress multicastAddress)
Description copied from interface:DatagramChannel
Leaves a multicast group and notifies theChannelFuture
once the operation completes.- Specified by:
leaveGroup
in interfaceDatagramChannel
-
leaveGroup
public ChannelFuture leaveGroup(java.net.InetAddress multicastAddress, ChannelPromise promise)
Description copied from interface:DatagramChannel
Leaves a multicast group and notifies theChannelFuture
once the operation completes. The givenChannelFuture
will be notified and also returned.- Specified by:
leaveGroup
in interfaceDatagramChannel
-
leaveGroup
public ChannelFuture leaveGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface)
Description copied from interface:DatagramChannel
Leaves a multicast group on a specified local interface and notifies theChannelFuture
once the operation completes.- Specified by:
leaveGroup
in interfaceDatagramChannel
-
leaveGroup
public ChannelFuture leaveGroup(java.net.InetSocketAddress multicastAddress, java.net.NetworkInterface networkInterface, ChannelPromise promise)
Description copied from interface:DatagramChannel
Leaves a multicast group on a specified local interface and notifies theChannelFuture
once the operation completes. The givenChannelFuture
will be notified and also returned.- Specified by:
leaveGroup
in interfaceDatagramChannel
-
leaveGroup
public ChannelFuture leaveGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source)
Description copied from interface:DatagramChannel
Leave the specified multicast group at the specified interface using the specified source and notifies theChannelFuture
once the operation completes.- Specified by:
leaveGroup
in interfaceDatagramChannel
-
leaveGroup
public ChannelFuture leaveGroup(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress source, ChannelPromise promise)
Description copied from interface:DatagramChannel
Leave the specified multicast group at the specified interface using the specified source and notifies theChannelFuture
once the operation completes. The givenChannelFuture
will be notified and also returned.- Specified by:
leaveGroup
in interfaceDatagramChannel
-
block
public ChannelFuture block(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress sourceToBlock)
Block the given sourceToBlock address for the given multicastAddress on the given networkInterface- Specified by:
block
in interfaceDatagramChannel
-
block
public ChannelFuture block(java.net.InetAddress multicastAddress, java.net.NetworkInterface networkInterface, java.net.InetAddress sourceToBlock, ChannelPromise promise)
Block the given sourceToBlock address for the given multicastAddress on the given networkInterface- Specified by:
block
in interfaceDatagramChannel
-
block
public ChannelFuture block(java.net.InetAddress multicastAddress, java.net.InetAddress sourceToBlock)
Block the given sourceToBlock address for the given multicastAddress- Specified by:
block
in interfaceDatagramChannel
-
block
public ChannelFuture block(java.net.InetAddress multicastAddress, java.net.InetAddress sourceToBlock, ChannelPromise promise)
Block the given sourceToBlock address for the given multicastAddress- Specified by:
block
in interfaceDatagramChannel
-
setReadPending
@Deprecated protected void setReadPending(boolean readPending)
Deprecated.- Overrides:
setReadPending
in classAbstractNioChannel
-
clearReadPending0
void clearReadPending0()
-
closeOnReadError
protected boolean closeOnReadError(java.lang.Throwable cause)
- Overrides:
closeOnReadError
in classAbstractNioMessageChannel
-
-