Class NioSocketChannel
java.lang.Object
io.netty.util.DefaultAttributeMap
io.netty.channel.AbstractChannel
io.netty.channel.nio.AbstractNioChannel
io.netty.channel.nio.AbstractNioByteChannel
io.netty.channel.socket.nio.NioSocketChannel
- All Implemented Interfaces:
Channel, ChannelOutboundInvoker, DuplexChannel, SocketChannel, AttributeMap, Comparable<Channel>
SocketChannel which uses NIO selector based implementation.-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractNioByteChannel
AbstractNioByteChannel.NioByteUnsafeNested classes/interfaces inherited from class AbstractNioChannel
AbstractNioChannel.AbstractNioUnsafe, AbstractNioChannel.NioUnsafeNested classes/interfaces inherited from class AbstractChannel
AbstractChannel.AbstractUnsafeNested classes/interfaces inherited from interface Channel
Channel.Unsafe -
Field Summary
Fields inherited from class AbstractNioChannel
readInterestOp, readOps -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instanceNioSocketChannel(Channel parent, SocketChannel socket) Create a new instanceNioSocketChannel(SocketChannel socket) Create a new instance using the givenSocketChannel.NioSocketChannel(SelectorProvider provider) Create a new instance using the givenSelectorProvider.NioSocketChannel(SelectorProvider provider, InternetProtocolFamily family) Deprecated.NioSocketChannel(SelectorProvider provider, SocketProtocolFamily family) Create a new instance using the givenSelectorProviderand protocol family (supported only since JDK 15). -
Method Summary
Modifier and TypeMethodDescriptionconfig()Returns the configuration of this channel.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 intdoReadBytes(ByteBuf byteBuf) Read bytes into the givenByteBufand return the amount.protected final voidCalled when conditions justify shutting down the output portion of the channel.protected voidFlush the content of the given buffer to the remote peer.protected intdoWriteBytes(ByteBuf buf) protected longdoWriteFileRegion(FileRegion region) Write aFileRegionbooleanisActive()Returntrueif theChannelis active and so connected.booleanReturnstrueif and only if the remote peer shut down its output so that no more data is received from this channel.protected booleanbooleanbooleanDetermine if both the input and output of this channel have been shutdown.protected SocketChannelReturns the local address where this channel is bound to.protected SocketAddressReturns theSocketAddresswhich is bound locally.protected AbstractNioChannel.AbstractNioUnsafeCreate a newAbstractChannel.AbstractUnsafeinstance which will be used for the life-time of theChannelparent()Returns the parent of this channel.Returns the remote address where this channel is connected to.protected SocketAddressReturn theSocketAddresswhich theChannelis connected to.shutdown()Will shutdown the input and output sides of this channel.shutdown(ChannelPromise promise) Will shutdown the input and output sides of this channel.Shutdown the input side of the channel.shutdownInput(ChannelPromise promise) Will shutdown the input and notifyChannelPromise.shutdownOutput(ChannelPromise promise) Will shutdown the output and notifyChannelPromise.Methods inherited from class AbstractNioByteChannel
clearOpWrite, doWrite0, filterOutboundMessage, incompleteWrite, metadata, setOpWriteMethods inherited from class AbstractNioChannel
addAndSubmit, clearReadPending, doBeginRead, doDeregister, doRegister, isCompatible, isOpen, isReadPending, newDirectBuffer, newDirectBuffer, registration, removeAndSubmit, selectionKey, setReadPending, unsafeMethods inherited from class AbstractChannel
closeFuture, compareTo, doRegister, equals, eventLoop, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, maxMessagesPerWrite, newChannelPipeline, newId, pipeline, toString, validateFileRegion, voidPromiseMethods inherited from class DefaultAttributeMap
attr, hasAttrMethods inherited from interface AttributeMap
attr, hasAttrMethods inherited from interface Channel
alloc, bind, bind, bytesBeforeUnwritable, bytesBeforeWritable, close, close, closeFuture, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, eventLoop, flush, getOption, id, isOpen, isRegistered, isWritable, metadata, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, pipeline, read, setOption, unsafe, voidPromise, write, write, writeAndFlush, writeAndFlushMethods inherited from interface Comparable
compareTo
-
Constructor Details
-
NioSocketChannel
public NioSocketChannel()Create a new instance -
NioSocketChannel
Create a new instance using the givenSelectorProvider. -
NioSocketChannel
Deprecated.Create a new instance using the givenSelectorProviderand protocol family (supported only since JDK 15). -
NioSocketChannel
Create a new instance using the givenSelectorProviderand protocol family (supported only since JDK 15). -
NioSocketChannel
Create a new instance using the givenSocketChannel. -
NioSocketChannel
Create a new instance- Parameters:
parent- theChannelwhich created this instance ornullif it was created by the usersocket- theSocketChannelwhich will be used
-
-
Method Details
-
parent
Description copied from interface:ChannelReturns the parent of this channel.- Specified by:
parentin interfaceChannel- Specified by:
parentin interfaceSocketChannel- Overrides:
parentin classAbstractChannel- Returns:
- the parent channel.
nullif this channel does not have a parent channel.
-
config
Description copied from interface:ChannelReturns the configuration of this channel.- Specified by:
configin interfaceChannel- Specified by:
configin interfaceSocketChannel
-
javaChannel
- Overrides:
javaChannelin classAbstractNioChannel
-
isActive
-
isOutputShutdown
public boolean isOutputShutdown()- Specified by:
isOutputShutdownin interfaceDuplexChannel- See Also:
-
isInputShutdown
public boolean isInputShutdown()Description copied from interface:DuplexChannelReturnstrueif and only if the remote peer shut down its output so that no more data is received from this channel. Note that the semantic of this method is different from that ofSocket.shutdownInput()andSocket.isInputShutdown().- Specified by:
isInputShutdownin interfaceDuplexChannel
-
isShutdown
public boolean isShutdown()Description copied from interface:DuplexChannelDetermine if both the input and output of this channel have been shutdown.- Specified by:
isShutdownin interfaceDuplexChannel
-
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 interfaceSocketChannel- 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 interfaceSocketChannel- 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.
-
doShutdownOutput
Description copied from class:AbstractChannelCalled when conditions justify shutting down the output portion of the channel. This may happen if a write operation throws an exception.- Overrides:
doShutdownOutputin classAbstractChannel- Throws:
Exception
-
shutdownOutput
- Specified by:
shutdownOutputin interfaceDuplexChannel- See Also:
-
shutdownOutput
Description copied from interface:DuplexChannelWill shutdown the output and notifyChannelPromise.- Specified by:
shutdownOutputin interfaceDuplexChannel- See Also:
-
shutdownInput
Description copied from class:AbstractNioByteChannelShutdown the input side of the channel.- Specified by:
shutdownInputin interfaceDuplexChannel- Specified by:
shutdownInputin classAbstractNioByteChannel- See Also:
-
isInputShutdown0
protected boolean isInputShutdown0()- Overrides:
isInputShutdown0in classAbstractNioByteChannel
-
shutdownInput
Description copied from interface:DuplexChannelWill shutdown the input and notifyChannelPromise.- Specified by:
shutdownInputin interfaceDuplexChannel- See Also:
-
shutdown
Description copied from interface:DuplexChannelWill shutdown the input and output sides of this channel.- Specified by:
shutdownin interfaceDuplexChannel- Returns:
- will be completed when both shutdown operations complete.
-
shutdown
Description copied from interface:DuplexChannelWill shutdown the input and output sides of this channel.- Specified by:
shutdownin interfaceDuplexChannel- Parameters:
promise- will be completed when both shutdown operations complete.- Returns:
- will be completed when both shutdown operations complete.
-
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
-
doReadBytes
Description copied from class:AbstractNioByteChannelRead bytes into the givenByteBufand return the amount.- Specified by:
doReadBytesin classAbstractNioByteChannel- Throws:
Exception
-
doWriteBytes
Description copied from class:AbstractNioByteChannel- Specified by:
doWriteBytesin classAbstractNioByteChannel- Parameters:
buf- theByteBuffrom which the bytes should be written- Returns:
- amount the amount of written bytes
- Throws:
Exception
-
doWriteFileRegion
Description copied from class:AbstractNioByteChannelWrite aFileRegion- Specified by:
doWriteFileRegionin classAbstractNioByteChannel- Parameters:
region- theFileRegionfrom which the bytes should be written- Returns:
- amount the amount of written bytes
- Throws:
Exception
-
doWrite
Description copied from class:AbstractChannelFlush the content of the given buffer to the remote peer.- Overrides:
doWritein classAbstractNioByteChannel- Throws:
Exception
-
newUnsafe
Description copied from class:AbstractChannelCreate a newAbstractChannel.AbstractUnsafeinstance which will be used for the life-time of theChannel- Overrides:
newUnsafein classAbstractNioByteChannel
-
NioSocketChannel(SelectorProvider, SocketProtocolFamily)