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

public Class NioServerSocketChannel

extends AbstractNioMessageChannel<Channel, SocketAddress, SocketAddress>
implements ServerSocketChannel
Class Inheritance
All Implemented Interfaces
io.netty5.channel.socket.ServerSocketChannel, io.netty5.channel.ServerChannel, 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, .EventLoopGroup, .ServerChannelReadHandleFactory, .ServerChannelWriteHandleFactory, io.netty5.channel.nio.AbstractNioMessageChannel, io.netty5.util.NetUtil, io.netty5.util.internal.SocketUtils, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.io.IOException, java.lang.reflect.Method, java.net.ProtocolFamily, .SocketAddress, .SocketOption, java.nio.channels.SelectionKey, .ServerSocketChannel, .SocketChannel, java.nio.channels.spi.SelectorProvider

A io.netty5.channel.socket.ServerSocketChannel implementation which uses NIO selector based implementation to accept new connections.

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 volatile int
private volatile boolean
private final EventLoopGroup
private static final SelectorProvider
private final ProtocolFamily
private static final InternalLogger
private static final Method

Constructor Summary

AccessConstructor and Description
public
NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup)

Create a new instance

public
NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, SelectorProvider provider)

Create a new instance using the given SelectorProvider.

public
NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, SelectorProvider provider, ProtocolFamily protocolFamily)

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

public
NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, ServerSocketChannel channel)

Create a new instance using the given ServerSocketChannel.

public
NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, ServerSocketChannel channel, ProtocolFamily family)

Create a new instance using the given ServerSocketChannel.

Method Summary

Modifier and TypeMethod and Description
public EventLoopGroup
childEventLoopGroup()

Implements io.netty5.channel.ServerChannel.childEventLoopGroup.

Returns the EventLoopGroup that is used to register the child Channels on after accepting these.
protected void
doBind(SocketAddress
the SocketAddress to bound to.
localAddress
)

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

Bind the Channel to the SocketAddress
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.
initialData
)

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
doReadMessages(AbstractChannel<Channel, SocketAddress, SocketAddress>.ReadSink readSink)

Implements abstract io.netty5.channel.nio.AbstractNioMessageChannel.doReadMessages.

Read messages into the given array and return the amount which was read.
protected void
doShutdown(ChannelShutdownDirection
the direction to shut down.
direction
)

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

Shutdown one direction of the Channel.
protected void
doWriteNow(AbstractChannel<Channel, 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.
writeHandle
)

Implements abstract 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.
protected final Object
filterOutboundMessage(Object
the message to filter / convert.
msg
)

Overrides io.netty5.channel.AbstractChannel.filterOutboundMessage.

Invoked when a new message is added to to the outbound queue of this AbstractChannel, so that the Channel implementation converts the message to another.
private int
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 ServerSocketChannel
protected SocketAddress
localAddress0()

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

Returns the SocketAddress which is bound locally.
private static ServerSocketChannel
protected SocketAddress
remoteAddress0()

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

Return the SocketAddress which the Channel is connected to.
private void
setBacklog(int backlog)

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.AbstractNioMessageChannel:
doReadNow

Field Detail

backlogback to summary
private volatile int backlog
boundback to summary
private volatile boolean bound
childEventLoopGroupback to summary
private final EventLoopGroup childEventLoopGroup
DEFAULT_SELECTOR_PROVIDERback to summary
private static final SelectorProvider DEFAULT_SELECTOR_PROVIDER
familyback to summary
private final ProtocolFamily family
loggerback to summary
private static final InternalLogger logger

Hides io.netty5.channel.nio.AbstractNioChannel.logger.

OPEN_SERVER_SOCKET_CHANNEL_WITH_FAMILYback to summary
private static final Method OPEN_SERVER_SOCKET_CHANNEL_WITH_FAMILY

Constructor Detail

NioServerSocketChannelback to summary
public NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup)

Create a new instance

NioServerSocketChannelback to summary
public NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, SelectorProvider provider)

Create a new instance using the given SelectorProvider.

NioServerSocketChannelback to summary
public NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, SelectorProvider provider, ProtocolFamily protocolFamily)

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

NioServerSocketChannelback to summary
public NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, ServerSocketChannel channel)

Create a new instance using the given ServerSocketChannel.

NioServerSocketChannelback to summary
public NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, ServerSocketChannel channel, ProtocolFamily family)

Create a new instance using the given ServerSocketChannel.

Method Detail

childEventLoopGroupback to summary
public EventLoopGroup childEventLoopGroup()

Implements io.netty5.channel.ServerChannel.childEventLoopGroup.

Doc from io.netty5.channel.ServerChannel.childEventLoopGroup.

Returns the EventLoopGroup that is used to register the child Channels on after accepting these.

Annotations
@Override
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.
doConnectback to summary
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress, Buffer initialData)

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.

initialData: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
doDisconnectback to summary
protected void doDisconnect()

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

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

Disconnect this Channel from its remote peer

Annotations
@Override
doFinishConnectback to summary
protected boolean doFinishConnect(SocketAddress requestedRemoteAddress)

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
doReadMessagesback to summary
protected int doReadMessages(AbstractChannel<Channel, SocketAddress, SocketAddress>.ReadSink readSink) throws Exception

Implements abstract io.netty5.channel.nio.AbstractNioMessageChannel.doReadMessages.

Doc from io.netty5.channel.nio.AbstractNioMessageChannel.doReadMessages.

Read messages into the given array and return the amount which was read.

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.
doWriteNowback to summary
protected void doWriteNow(AbstractChannel<Channel, SocketAddress, SocketAddress>.WriteSink writeHandle) throws Exception

Implements abstract io.netty5.channel.AbstractChannel.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
writeHandle:AbstractChannel<Channel, 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.
filterOutboundMessageback to summary
protected final Object filterOutboundMessage(Object msg)

Overrides io.netty5.channel.AbstractChannel.filterOutboundMessage.

Doc from io.netty5.channel.AbstractChannel.filterOutboundMessage.

Invoked when a new message is added to to the outbound queue of this AbstractChannel, so that the Channel implementation converts the message to another. (e.g. heap buffer -> direct buffer)

Parameters
msg:Object

the message to filter / convert.

Annotations
@Override
getBacklogback to summary
private int getBacklog()
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 ServerSocketChannel 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 ServerSocketChannel newChannel(SelectorProvider provider, ProtocolFamily family)
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
setBacklogback to summary
private void setBacklog(int backlog)
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