- 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.NioServerSocketChannel
-
- All Implemented Interfaces:
Channel
,ChannelOutboundInvoker
,IoHandle
,ServerChannel
,ServerSocketChannel
,AttributeMap
,FuturePromiseFactory
,Comparable<Channel>
public class NioServerSocketChannel extends AbstractNioMessageChannel<Channel,SocketAddress,SocketAddress> implements ServerSocketChannel
AServerSocketChannel
implementation which uses NIO selector based implementation to accept new connections.Available options
In addition to the options provided bySocketChannel
,NioSocketChannel
allows the following options in the option map:ChannelOption
INET
INET6
{@code UNIX {@link NioChannelOption} X X X
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty5.channel.AbstractChannel
AbstractChannel.DefaultAbstractChannelPipeline
-
-
Field Summary
-
Fields inherited from class io.netty5.channel.nio.AbstractNioChannel
readInterestOp
-
-
Constructor Summary
Constructors Constructor Description NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup)
Create a new instanceNioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, ServerSocketChannel channel)
Create a new instance using the givenServerSocketChannel
.NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, ServerSocketChannel channel, ProtocolFamily family)
Create a new instance using the givenServerSocketChannel
.NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, SelectorProvider provider)
Create a new instance using the givenSelectorProvider
.NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, SelectorProvider provider, ProtocolFamily protocolFamily)
Create a new instance using the givenSelectorProvider
and protocol family (supported only since JDK 15).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
autoReadCleared()
Is called onceAbstractChannel.setAutoRead(boolean)
is called withfalse
andAbstractChannel.isAutoRead()
wastrue
before.EventLoopGroup
childEventLoopGroup()
Returns theEventLoopGroup
that is used to register the childChannel
s on.protected boolean
closeOnReadError(Throwable cause)
protected void
doBind(SocketAddress localAddress)
Bind theChannel
to theSocketAddress
protected boolean
doConnect(SocketAddress remoteAddress, SocketAddress localAddress)
Connect to remote peer.protected void
doDisconnect()
Disconnect thisChannel
from its remote peerprotected boolean
doFinishConnect(SocketAddress requestedRemoteAddress)
Finish a connect request.protected int
doReadMessages(List<Object> buf)
Read messages into the given array and return the amount which was read.protected void
doShutdown(ChannelShutdownDirection direction)
Shutdown one direction of theChannel
.protected boolean
doWriteMessage(Object msg, ChannelOutboundBuffer in)
Write a message to the underlyingChannel
.protected Object
filterOutboundMessage(Object msg)
Invoked when a new message is added to aChannelOutboundBuffer
of thisAbstractChannel
, so that theChannel
implementation converts the message to another.protected <T> T
getExtendedOption(ChannelOption<T> option)
Override to add support for moreChannelOption
s.boolean
isActive()
Returntrue
if theChannel
is active and so connected.protected boolean
isExtendedOptionSupported(ChannelOption<?> option)
Override to add support for moreChannelOption
s.boolean
isShutdown(ChannelShutdownDirection direction)
protected ServerSocketChannel
javaChannel()
protected SocketAddress
localAddress0()
Returns theSocketAddress
which is bound locally.protected SocketAddress
remoteAddress0()
Return theSocketAddress
which theChannel
is connected to.protected <T> void
setExtendedOption(ChannelOption<T> option, T value)
Override to add support for moreChannelOption
s.-
Methods inherited from class io.netty5.channel.nio.AbstractNioMessageChannel
continueOnWriteError, continueReading, doBeginRead, doWrite, readNow
-
Methods inherited from class io.netty5.channel.nio.AbstractNioChannel
clearReadPending, doClose, isOpen, isReadPending, newDirectBuffer, newDirectBuffer, removeReadOp, selectionKey, setReadPending, writeFlushed
-
Methods inherited from class io.netty5.channel.AbstractChannel
annotateConnectException, assertEventLoop, bufferAllocator, cacheAddresses, closeForciblyTransport, closeFuture, closeIfClosed, closeTransport, compareTo, deregisterTransport, ensureOpen, equals, executor, finishConnect, fireChannelActiveIfNotActiveBefore, getMaxMessagesPerWrite, getOption, getWriteSpinCount, handleWriteError, hashCode, id, isAllowHalfClosure, isAutoRead, isConnectPending, isOptionSupported, isRegistered, localAddress, metadata, newChannelPipeline, newSupportedIdentityOptionsSet, outboundBuffer, parent, pipeline, prepareToClose, readIfIsAutoRead, recvBufAllocHandle, remoteAddress, runAfterTransportAction, safeSetFailure, safeSetSuccess, setBufferAllocator, setOption, shutdownTransport, toString, validate, validateEventLoopGroup, validateFileRegion, writableBytes
-
Methods inherited from class io.netty5.util.DefaultAttributeMap
attr, hasAttr
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.netty5.util.AttributeMap
attr, hasAttr
-
Methods inherited from interface io.netty5.channel.Channel
bind, bufferAllocator, close, closeFuture, connect, connect, deregister, disconnect, executor, flush, getOption, id, isOpen, isOptionSupported, isWritable, localAddress, metadata, parent, pipeline, 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
-
NioServerSocketChannel
public NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup)
Create a new instance
-
NioServerSocketChannel
public NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, SelectorProvider provider)
Create a new instance using the givenSelectorProvider
.
-
NioServerSocketChannel
public NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, SelectorProvider provider, ProtocolFamily protocolFamily)
Create a new instance using the givenSelectorProvider
and protocol family (supported only since JDK 15).
-
NioServerSocketChannel
public NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, ServerSocketChannel channel)
Create a new instance using the givenServerSocketChannel
.
-
NioServerSocketChannel
public NioServerSocketChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, ServerSocketChannel channel, ProtocolFamily family)
Create a new instance using the givenServerSocketChannel
.
-
-
Method Detail
-
childEventLoopGroup
public EventLoopGroup childEventLoopGroup()
Description copied from interface:ServerChannel
Returns theEventLoopGroup
that is used to register the childChannel
s on.- Specified by:
childEventLoopGroup
in interfaceServerChannel
-
isActive
public boolean isActive()
Description copied from interface:Channel
Returntrue
if theChannel
is active and so connected.
-
getExtendedOption
protected <T> T getExtendedOption(ChannelOption<T> option)
Description copied from class:AbstractChannel
Override to add support for moreChannelOption
s. You need to also call {@link super} after handling the extra options.- Overrides:
getExtendedOption
in 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:AbstractChannel
Override to add support for moreChannelOption
s. You need to also call {@link super} after handling the extra options.- Overrides:
setExtendedOption
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Type Parameters:
T
- the value type.- Parameters:
option
- theChannelOption
.
-
isExtendedOptionSupported
protected boolean isExtendedOptionSupported(ChannelOption<?> option)
Description copied from class:AbstractChannel
Override to add support for moreChannelOption
s. You need to also call {@link super} after handling the extra options.- Overrides:
isExtendedOptionSupported
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Parameters:
option
- theChannelOption
.- Returns:
true
if supported,false
otherwise.
-
javaChannel
protected ServerSocketChannel javaChannel()
- Overrides:
javaChannel
in classAbstractNioChannel<Channel,SocketAddress,SocketAddress>
-
localAddress0
protected SocketAddress localAddress0()
Description copied from class:AbstractChannel
Returns theSocketAddress
which is bound locally.- Specified by:
localAddress0
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
-
doShutdown
protected void doShutdown(ChannelShutdownDirection direction) throws Exception
Description copied from class:AbstractChannel
Shutdown one direction of theChannel
.- Specified by:
doShutdown
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Parameters:
direction
- the direction to shutdown.- Throws:
Exception
- thrown on error.
-
isShutdown
public boolean isShutdown(ChannelShutdownDirection direction)
Description copied from interface:Channel
- Specified by:
isShutdown
in interfaceChannel
-
doBind
protected void doBind(SocketAddress localAddress) throws Exception
Description copied from class:AbstractChannel
Bind theChannel
to theSocketAddress
- Specified by:
doBind
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Throws:
Exception
-
doReadMessages
protected int doReadMessages(List<Object> buf) throws Exception
Description copied from class:AbstractNioMessageChannel
Read messages into the given array and return the amount which was read.- Specified by:
doReadMessages
in classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
- Throws:
Exception
-
doConnect
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress)
Description copied from class:AbstractChannel
Connect to remote peer.- Specified by:
doConnect
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Parameters:
remoteAddress
- the address of the remote peer.localAddress
- the local address of this channel.- Returns:
true
if the connect was completed,false
ifAbstractChannel.finishConnect()
will be called later again to try finishing the connect.
-
doFinishConnect
protected boolean doFinishConnect(SocketAddress requestedRemoteAddress)
Description copied from class:AbstractChannel
Finish a connect request.- Specified by:
doFinishConnect
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
- Parameters:
requestedRemoteAddress
- the remote address of the peer.- Returns:
true
if the connect was completed,false
ifAbstractChannel.finishConnect()
will be called later again to try finishing the connect.
-
remoteAddress0
protected SocketAddress remoteAddress0()
Description copied from class:AbstractChannel
Return theSocketAddress
which theChannel
is connected to.- Specified by:
remoteAddress0
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
-
doDisconnect
protected void doDisconnect()
Description copied from class:AbstractChannel
Disconnect thisChannel
from its remote peer- Specified by:
doDisconnect
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
-
doWriteMessage
protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in)
Description copied from class:AbstractNioMessageChannel
Write a message to the underlyingChannel
.- Specified by:
doWriteMessage
in classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
- Returns:
true
if and only if the message has been written
-
filterOutboundMessage
protected final Object filterOutboundMessage(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<Channel,SocketAddress,SocketAddress>
-
autoReadCleared
protected void autoReadCleared()
Description copied from class:AbstractChannel
Is called onceAbstractChannel.setAutoRead(boolean)
is called withfalse
andAbstractChannel.isAutoRead()
wastrue
before.- Overrides:
autoReadCleared
in classAbstractChannel<Channel,SocketAddress,SocketAddress>
-
closeOnReadError
protected boolean closeOnReadError(Throwable cause)
- Overrides:
closeOnReadError
in classAbstractNioMessageChannel<Channel,SocketAddress,SocketAddress>
-
-