Top Description Fields Constructors Methods
io.netty5.channel.socket.nio

public Class NioSocketChannel

extends AbstractNioByteChannel<NioServerSocketChannel, SocketAddress, SocketAddress>
implements SocketChannel
Class Inheritance
All Implemented Interfaces
io.netty5.channel.socket.SocketChannel, io.netty5.channel.Channel, io.netty5.channel.IoHandle, java.lang.Comparable, io.netty5.channel.ChannelOutboundInvoker, io.netty5.util.concurrent.FuturePromiseFactory, io.netty5.util.AttributeMap
Imports
io.netty5.buffer.Buffer, io.netty5.channel.Channel, .ChannelException, .ChannelOption, .ChannelShutdownDirection, .EventLoop, .FileRegion, io.netty5.channel.nio.AbstractNioByteChannel, io.netty5.channel.socket.SocketChannelWriteHandleFactory, io.netty5.util.concurrent.Future, .GlobalEventExecutor, io.netty5.util.internal.PlatformDependent, .SocketUtils, java.io.IOException, java.lang.reflect.Method, java.net.ProtocolFamily, .SocketAddress, .SocketOption, .StandardSocketOptions, java.nio.ByteBuffer, java.nio.channels.SelectionKey, .SocketChannel, java.nio.channels.spi.SelectorProvider, java.util.concurrent.Executor

io.netty5.channel.socket.SocketChannel which uses NIO selector based implementation.

Available options

In addition to the options provided by io.netty5.channel.socket.SocketChannel, NioSocketChannel allows the following options in the option map:
ChannelOption INET INET6 {@code UNIX
NioChannelOptionXXX

Field Summary

Modifier and TypeField and Description
private final ByteBufferCollector
private static final SelectorProvider
private final ProtocolFamily
private volatile boolean
private static final Method
private volatile boolean

Constructor Summary

AccessConstructor and Description
public
NioSocketChannel(EventLoop eventLoop)

Create a new instance

public
NioSocketChannel(EventLoop eventLoop, SelectorProvider provider)

Create a new instance using the given SelectorProvider.

public
NioSocketChannel(EventLoop eventLoop, SelectorProvider provider, ProtocolFamily family)

Create a new instance using the given SelectorProvider and protocol family (supported only since JDK 15).

public
NioSocketChannel(EventLoop eventLoop, SocketChannel socket)

Create a new instance using the given SocketChannel.

public
NioSocketChannel(NioServerSocketChannel
the Channel which created this instance or null if it was created by the user
parent
,
EventLoop
the EventLoop to use for IO.
eventLoop
,
SocketChannel
the SocketChannel which will be used
socket
)

Create a new instance

public
NioSocketChannel(NioServerSocketChannel
the Channel which created this instance or null if it was created by the user
parent
,
EventLoop
the EventLoop to use for IO.
eventLoop
,
SocketChannel
the SocketChannel which will be used
socket
,
ProtocolFamily
the ProtocolFamily that was used to create th SocketChannel
family
)

Create a new instance

Method Summary

Modifier and TypeMethod and Description
protected void
doBind(SocketAddress
the SocketAddress to bound to.
localAddress
)

Implements abstract io.netty5.channel.AbstractChannel.doBind.

Bind the Channel to the SocketAddress
private void
doBind0(SocketAddress localAddress)

protected boolean
doConnect(SocketAddress
the address of the remote peer.
remoteAddress
,
SocketAddress
the local address of this channel.
localAddress
,
Buffer
the initial data that is written during connect (if ChannelOption#TCP_FASTOPEN_CONNECT is supported and configured). If data is written care must be taken to update the reader offset.
data
)

Implements abstract io.netty5.channel.AbstractChannel.doConnect.

Connect to remote peer.
protected void
doDisconnect()

Implements abstract io.netty5.channel.AbstractChannel.doDisconnect.

Disconnect this Channel from its remote peer
protected boolean
doFinishConnect(SocketAddress
the remote address of the peer.
requestedRemoteAddress
)

Implements abstract io.netty5.channel.AbstractChannel.doFinishConnect.

Finish a connect request.
protected int
doReadBytes(Buffer buffer)

Implements abstract io.netty5.channel.nio.AbstractNioByteChannel.doReadBytes.

Read bytes into the given Buffer and return the amount.
protected void
doShutdown(ChannelShutdownDirection
the direction to shut down.
direction
)

Implements abstract io.netty5.channel.AbstractChannel.doShutdown.

Shutdown one direction of the Channel.
protected int
doWriteBytes(Buffer
the Buffer from which the bytes should be written
buf
)

Implements abstract io.netty5.channel.nio.AbstractNioByteChannel.doWriteBytes.

Write bytes form the given Buffer to the underlying java.nio.channels.Channel.
protected long
doWriteFileRegion(FileRegion
the FileRegion from which the bytes should be written
region
)

Implements abstract io.netty5.channel.nio.AbstractNioByteChannel.doWriteFileRegion.

Write a FileRegion
protected void
doWriteNow(AbstractChannel<NioServerSocketChannel, SocketAddress, SocketAddress>.WriteSink
the WriteSink that must be completed with the write progress. WriteSink#complete(long, long, int, boolean) or WriteSink#complete(long, Throwable, boolean) must be called exactly once before this method returns non-exceptional.
writeSink
)

Overrides io.netty5.channel.nio.AbstractNioByteChannel.doWriteNow.

Called in a loop when writes should be performed until this method returns false or there are no more messages to write.
protected <T> T
public boolean
isActive()

Implements io.netty5.channel.Channel.isActive.

Return true if the Channel is active and so connected.
protected boolean
public boolean
isShutdown(ChannelShutdownDirection direction)

Implements io.netty5.channel.Channel.isShutdown.

Returns true if the ChannelShutdownDirection of the Channel was shutdown before.
protected SocketChannel
protected SocketAddress
localAddress0()

Implements abstract io.netty5.channel.AbstractChannel.localAddress0.

Returns the SocketAddress which is bound locally.
private static SocketChannel
protected Future<Executor>
protected SocketAddress
remoteAddress0()

Implements abstract io.netty5.channel.AbstractChannel.remoteAddress0.

Return the SocketAddress which the Channel is connected to.
protected <T> void
setExtendedOption(ChannelOption<T> option, T value)

Overrides io.netty5.channel.AbstractChannel.setExtendedOption.

Override to add support for more ChannelOptions.
Inherited from io.netty5.channel.nio.AbstractNioByteChannel:
doReadNowfilterOutboundMessage

Field Detail

collectorback to summary
private final ByteBufferCollector collector
DEFAULT_SELECTOR_PROVIDERback to summary
private static final SelectorProvider DEFAULT_SELECTOR_PROVIDER
familyback to summary
private final ProtocolFamily family
inputShutdownback to summary
private volatile boolean inputShutdown
OPEN_SOCKET_CHANNEL_WITH_FAMILYback to summary
private static final Method OPEN_SOCKET_CHANNEL_WITH_FAMILY
outputShutdownback to summary
private volatile boolean outputShutdown

Constructor Detail

NioSocketChannelback to summary
public NioSocketChannel(EventLoop eventLoop)

Create a new instance

NioSocketChannelback to summary
public NioSocketChannel(EventLoop eventLoop, SelectorProvider provider)

Create a new instance using the given SelectorProvider.

NioSocketChannelback to summary
public NioSocketChannel(EventLoop eventLoop, SelectorProvider provider, ProtocolFamily family)

Create a new instance using the given SelectorProvider and protocol family (supported only since JDK 15).

NioSocketChannelback to summary
public NioSocketChannel(EventLoop eventLoop, SocketChannel socket)

Create a new instance using the given SocketChannel.

NioSocketChannelback to summary
public NioSocketChannel(NioServerSocketChannel parent, EventLoop eventLoop, SocketChannel socket)

Create a new instance

Parameters
parent:NioServerSocketChannel

the Channel which created this instance or null if it was created by the user

eventLoop:EventLoop

the EventLoop to use for IO.

socket:SocketChannel

the SocketChannel which will be used

NioSocketChannelback to summary
public NioSocketChannel(NioServerSocketChannel parent, EventLoop eventLoop, SocketChannel socket, ProtocolFamily family)

Create a new instance

Parameters
parent:NioServerSocketChannel

the Channel which created this instance or null if it was created by the user

eventLoop:EventLoop

the EventLoop to use for IO.

socket:SocketChannel

the SocketChannel which will be used

family:ProtocolFamily

the ProtocolFamily that was used to create th SocketChannel

Method Detail

doBindback to summary
protected void doBind(SocketAddress localAddress) throws Exception

Implements abstract io.netty5.channel.AbstractChannel.doBind.

Doc from io.netty5.channel.AbstractChannel.doBind.

Bind the Channel to the SocketAddress

Parameters
localAddress:SocketAddress

the SocketAddress to bound to.

Annotations
@Override
Exceptions
Exception:
when an error happens.
doBind0back to summary
private void doBind0(SocketAddress localAddress) throws Exception
doConnectback to summary
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress, Buffer data) throws Exception

Implements abstract io.netty5.channel.AbstractChannel.doConnect.

Doc from io.netty5.channel.AbstractChannel.doConnect.

Connect to remote peer. This method should never be directly called.

Parameters
remoteAddress:SocketAddress

the address of the remote peer.

localAddress:SocketAddress

the local address of this channel.

data:Buffer

the initial data that is written during connect (if ChannelOption#TCP_FASTOPEN_CONNECT is supported and configured). If data is written care must be taken to update the reader offset.

Returns:boolean

true if the connect operation was completed, false if finishConnect() will be called later again to try finish connecting.

Annotations
@Override
Exceptions
Exception:
thrown on error.
doDisconnectback to summary
protected void doDisconnect() throws Exception

Implements abstract io.netty5.channel.AbstractChannel.doDisconnect.

Doc from io.netty5.channel.AbstractChannel.doDisconnect.

Disconnect this Channel from its remote peer

Annotations
@Override
Exceptions
Exception:
thrown on error.
doFinishConnectback to summary
protected boolean doFinishConnect(SocketAddress requestedRemoteAddress) throws Exception

Implements abstract io.netty5.channel.AbstractChannel.doFinishConnect.

Doc from io.netty5.channel.AbstractChannel.doFinishConnect.

Finish a connect request. This method should never be directly called, use finishConnect() instead.

Parameters
requestedRemoteAddress:SocketAddress

the remote address of the peer.

Returns:boolean

true if the connect operations was completed, false if finishConnect() will be called later again to try finishing the connect operation.

Annotations
@Override
Exceptions
Exception:
thrown on error.
doReadBytesback to summary
protected int doReadBytes(Buffer buffer) throws Exception

Implements abstract io.netty5.channel.nio.AbstractNioByteChannel.doReadBytes.

Doc from io.netty5.channel.nio.AbstractNioByteChannel.doReadBytes.

Read bytes into the given Buffer and return the amount.

Annotations
@Override
doShutdownback to summary
protected void doShutdown(ChannelShutdownDirection direction) throws Exception

Implements abstract io.netty5.channel.AbstractChannel.doShutdown.

Doc from io.netty5.channel.AbstractChannel.doShutdown.

Shutdown one direction of the Channel.

Parameters
direction:ChannelShutdownDirection

the direction to shut down.

Annotations
@Override
Exceptions
Exception:
thrown on error.
doWriteBytesback to summary
protected int doWriteBytes(Buffer buf) throws Exception

Implements abstract io.netty5.channel.nio.AbstractNioByteChannel.doWriteBytes.

Doc from io.netty5.channel.nio.AbstractNioByteChannel.doWriteBytes.

Write bytes form the given Buffer to the underlying java.nio.channels.Channel.

Parameters
buf:Buffer

the Buffer from which the bytes should be written

Returns:int

amount the amount of written bytes

Annotations
@Override
doWriteFileRegionback to summary
protected long doWriteFileRegion(FileRegion region) throws Exception

Implements abstract io.netty5.channel.nio.AbstractNioByteChannel.doWriteFileRegion.

Doc from io.netty5.channel.nio.AbstractNioByteChannel.doWriteFileRegion.

Write a FileRegion

Parameters
region:FileRegion

the FileRegion from which the bytes should be written

Returns:long

amount the amount of written bytes

Annotations
@Override
doWriteNowback to summary
protected void doWriteNow(AbstractChannel<NioServerSocketChannel, SocketAddress, SocketAddress>.WriteSink writeSink) throws Exception

Overrides io.netty5.channel.nio.AbstractNioByteChannel.doWriteNow.

Doc from io.netty5.channel.AbstractChannel.doWriteNow.

Called in a loop when writes should be performed until this method returns false or there are no more messages to write. Implementations are responsible for handling partial writes, which for example means that if Buffers are written partial implementations need to ensure the readerOffset is updated accordingly.

Parameters
writeSink:AbstractChannel<NioServerSocketChannel, SocketAddress, SocketAddress>.WriteSink

the WriteSink that must be completed with the write progress. WriteSink#complete(long, long, int, boolean) or WriteSink#complete(long, Throwable, boolean) must be called exactly once before this method returns non-exceptional.

Annotations
@Override
Exceptions
Exception:
if an error happened during writing. This will also terminate the write loop.
getExtendedOptionback to summary
protected <T> T getExtendedOption(ChannelOption<T> option)

Overrides io.netty5.channel.AbstractChannel.getExtendedOption.

Doc from io.netty5.channel.AbstractChannel.getExtendedOption.

Override to add support for more ChannelOptions. You need to also call super after handling the extra options.

Parameters
<T>
the value type.
option:ChannelOption<T>

the ChannelOption.

Returns:T

the value for the option.

Annotations
@SuppressWarnings:unchecked
@Override
isActiveback to summary
public boolean isActive()

Implements io.netty5.channel.Channel.isActive.

Doc from io.netty5.channel.Channel.isActive.

Return true if the Channel is active and so connected.

Annotations
@Override
isExtendedOptionSupportedback to summary
protected boolean isExtendedOptionSupported(ChannelOption<?> option)

Overrides io.netty5.channel.AbstractChannel.isExtendedOptionSupported.

Doc from io.netty5.channel.AbstractChannel.isExtendedOptionSupported.

Override to add support for more ChannelOptions. You need to also call super after handling the extra options.

Parameters
option:ChannelOption<?>

the ChannelOption.

Returns:boolean

true if supported, false otherwise.

Annotations
@Override
isShutdownback to summary
public boolean isShutdown(ChannelShutdownDirection direction)

Implements io.netty5.channel.Channel.isShutdown.

Doc from io.netty5.channel.Channel.isShutdown.

Returns true if the ChannelShutdownDirection of the Channel was shutdown before.

Annotations
@Override
javaChannelback to summary
protected SocketChannel javaChannel()

Overrides io.netty5.channel.nio.AbstractNioChannel.javaChannel.

Annotations
@Override
localAddress0back to summary
protected SocketAddress localAddress0()

Implements abstract io.netty5.channel.AbstractChannel.localAddress0.

Doc from io.netty5.channel.AbstractChannel.localAddress0.

Returns the SocketAddress which is bound locally.

Returns:SocketAddress

the local address if any, null otherwise.

Annotations
@Override
newChannelback to summary
private static SocketChannel newChannel(SelectorProvider provider, ProtocolFamily family)
prepareToCloseback to summary
protected Future<Executor> prepareToClose()

Overrides io.netty5.channel.AbstractChannel.prepareToClose.

Doc from io.netty5.channel.AbstractChannel.prepareToClose.

Prepares to close the Channel. If this method returns an Executor, the caller must call the Executor#execute(Runnable) method with a task that calls doClose() on the returned Executor. If this method returns null, doClose() must be called from the caller thread. (i.e. EventLoop)

Annotations
@Override
remoteAddress0back to summary
protected SocketAddress remoteAddress0()

Implements abstract io.netty5.channel.AbstractChannel.remoteAddress0.

Doc from io.netty5.channel.AbstractChannel.remoteAddress0.

Return the SocketAddress which the Channel is connected to.

Returns:SocketAddress

the remote address if any, null otherwise.

Annotations
@Override
setExtendedOptionback to summary
protected <T> void setExtendedOption(ChannelOption<T> option, T value)

Overrides io.netty5.channel.AbstractChannel.setExtendedOption.

Doc from io.netty5.channel.AbstractChannel.setExtendedOption.

Override to add support for more ChannelOptions. You need to also call super after handling the extra options.

Parameters
<T>
the value type.
option:ChannelOption<T>

the ChannelOption.

Annotations
@Override