public class NioSocketChannel extends AbstractNioByteChannel implements SocketChannel
SocketChannel
which uses NIO selector based implementation.Modifier and Type | Class and Description |
---|---|
private class |
NioSocketChannel.NioSocketChannelConfig |
private class |
NioSocketChannel.NioSocketChannelUnsafe |
AbstractNioByteChannel.NioByteUnsafe
AbstractNioChannel.AbstractNioUnsafe, AbstractNioChannel.NioUnsafe
AbstractChannel.AbstractUnsafe
Channel.Unsafe
Modifier and Type | Field and Description |
---|---|
private SocketChannelConfig |
config |
private static java.nio.channels.spi.SelectorProvider |
DEFAULT_SELECTOR_PROVIDER |
private static InternalLogger |
logger |
readInterestOp
Constructor and Description |
---|
NioSocketChannel()
Create a new instance
|
NioSocketChannel(Channel parent,
java.nio.channels.SocketChannel socket)
Create a new instance
|
NioSocketChannel(java.nio.channels.spi.SelectorProvider provider)
Create a new instance using the given
SelectorProvider . |
NioSocketChannel(java.nio.channels.SocketChannel socket)
Create a new instance using the given
SocketChannel . |
Modifier and Type | Method and Description |
---|---|
SocketChannelConfig |
config()
Returns the configuration of this channel.
|
protected void |
doBind(java.net.SocketAddress localAddress)
Bind the
Channel to the SocketAddress |
private void |
doBind0(java.net.SocketAddress localAddress) |
protected void |
doClose()
Close the
Channel |
protected boolean |
doConnect(java.net.SocketAddress remoteAddress,
java.net.SocketAddress localAddress)
Connect to the remote peer
|
protected void |
doDisconnect()
Disconnect this
Channel from its remote peer |
protected void |
doFinishConnect()
Finish the connect
|
protected int |
doReadBytes(ByteBuf byteBuf)
Read bytes into the given
ByteBuf and return the amount. |
protected void |
doWrite(ChannelOutboundBuffer in)
Flush the content of the given buffer to the remote peer.
|
protected int |
doWriteBytes(ByteBuf buf)
Write bytes form the given
ByteBuf to the underlying Channel . |
protected long |
doWriteFileRegion(FileRegion region)
Write a
FileRegion |
boolean |
isActive()
Return
true if the Channel is active and so connected. |
boolean |
isInputShutdown()
Returns
true if and only if the remote peer shut down its output so that no more
data is received from this channel. |
protected boolean |
isInputShutdown0() |
boolean |
isOutputShutdown() |
boolean |
isShutdown()
Determine if both the input and output of this channel have been shutdown.
|
protected java.nio.channels.SocketChannel |
javaChannel() |
java.net.InetSocketAddress |
localAddress()
Returns the local address where this channel is bound to.
|
protected java.net.SocketAddress |
localAddress0()
Returns the
SocketAddress which is bound locally. |
private static java.nio.channels.SocketChannel |
newSocket(java.nio.channels.spi.SelectorProvider provider) |
protected AbstractNioChannel.AbstractNioUnsafe |
newUnsafe()
Create a new
AbstractChannel.AbstractUnsafe instance which will be used for the life-time of the Channel |
ServerSocketChannel |
parent()
Returns the parent of this channel.
|
java.net.InetSocketAddress |
remoteAddress()
Returns the remote address where this channel is connected to.
|
protected java.net.SocketAddress |
remoteAddress0()
Return the
SocketAddress which the Channel is connected to. |
ChannelFuture |
shutdown()
Will shutdown the input and output sides of this channel.
|
ChannelFuture |
shutdown(ChannelPromise promise)
Will shutdown the input and output sides of this channel.
|
private void |
shutdown0(ChannelPromise promise) |
ChannelFuture |
shutdownInput()
Shutdown the input side of the channel.
|
ChannelFuture |
shutdownInput(ChannelPromise promise)
Will shutdown the input and notify
ChannelPromise . |
private void |
shutdownInput0() |
private void |
shutdownInput0(ChannelPromise promise) |
ChannelFuture |
shutdownOutput() |
ChannelFuture |
shutdownOutput(ChannelPromise promise)
Will shutdown the output and notify
ChannelPromise . |
private void |
shutdownOutput0() |
private void |
shutdownOutput0(ChannelPromise promise) |
clearOpWrite, filterOutboundMessage, incompleteWrite, metadata, setOpWrite
clearReadPending, doBeginRead, doDeregister, doRegister, eventLoop, isCompatible, isOpen, isReadPending, newDirectBuffer, newDirectBuffer, selectionKey, setReadPending, unsafe
alloc, bind, bind, bytesBeforeUnwritable, bytesBeforeWritable, close, close, closeFuture, compareTo, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, equals, flush, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, isWritable, newChannelPipeline, newFailedFuture, newId, newProgressivePromise, newPromise, newSucceededFuture, pipeline, read, toString, voidPromise, write, write, writeAndFlush, writeAndFlush
attr, hasAttr
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
alloc, bytesBeforeUnwritable, bytesBeforeWritable, closeFuture, eventLoop, flush, id, isOpen, isRegistered, isWritable, metadata, pipeline, read, unsafe
attr, hasAttr
bind, bind, close, close, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, voidPromise, write, write, writeAndFlush, writeAndFlush
private static final InternalLogger logger
private static final java.nio.channels.spi.SelectorProvider DEFAULT_SELECTOR_PROVIDER
private final SocketChannelConfig config
public NioSocketChannel()
public NioSocketChannel(java.nio.channels.spi.SelectorProvider provider)
SelectorProvider
.public NioSocketChannel(java.nio.channels.SocketChannel socket)
SocketChannel
.private static java.nio.channels.SocketChannel newSocket(java.nio.channels.spi.SelectorProvider provider)
public ServerSocketChannel parent()
Channel
parent
in interface Channel
parent
in interface SocketChannel
parent
in class AbstractChannel
null
if this channel does not have a parent channel.public SocketChannelConfig config()
Channel
config
in interface Channel
config
in interface SocketChannel
protected java.nio.channels.SocketChannel javaChannel()
javaChannel
in class AbstractNioChannel
public boolean isActive()
Channel
true
if the Channel
is active and so connected.public boolean isOutputShutdown()
isOutputShutdown
in interface DuplexChannel
Socket.isOutputShutdown()
public boolean isInputShutdown()
DuplexChannel
true
if 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 of Socket.shutdownInput()
and Socket.isInputShutdown()
.isInputShutdown
in interface DuplexChannel
public boolean isShutdown()
DuplexChannel
isShutdown
in interface DuplexChannel
public java.net.InetSocketAddress localAddress()
Channel
SocketAddress
is supposed to be down-cast into more concrete
type such as InetSocketAddress
to retrieve the detailed
information.localAddress
in interface Channel
localAddress
in interface SocketChannel
localAddress
in class AbstractChannel
null
if this channel is not bound.public java.net.InetSocketAddress remoteAddress()
Channel
SocketAddress
is supposed to be down-cast into more
concrete type such as InetSocketAddress
to retrieve the detailed
information.remoteAddress
in interface Channel
remoteAddress
in interface SocketChannel
remoteAddress
in class AbstractChannel
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
,
use DefaultAddressedEnvelope.recipient()
to determine
the origination of the received message as this method will
return null
.public ChannelFuture shutdownOutput()
shutdownOutput
in interface DuplexChannel
Socket.shutdownOutput()
public ChannelFuture shutdownOutput(ChannelPromise promise)
DuplexChannel
ChannelPromise
.shutdownOutput
in interface DuplexChannel
Socket.shutdownOutput()
public ChannelFuture shutdownInput()
AbstractNioByteChannel
shutdownInput
in interface DuplexChannel
shutdownInput
in class AbstractNioByteChannel
Socket.shutdownInput()
protected boolean isInputShutdown0()
isInputShutdown0
in class AbstractNioByteChannel
public ChannelFuture shutdownInput(ChannelPromise promise)
DuplexChannel
ChannelPromise
.shutdownInput
in interface DuplexChannel
Socket.shutdownInput()
public ChannelFuture shutdown()
DuplexChannel
shutdown
in interface DuplexChannel
public ChannelFuture shutdown(ChannelPromise promise)
DuplexChannel
shutdown
in interface DuplexChannel
promise
- will be completed when both shutdown operations complete.private void shutdownOutput0(ChannelPromise promise)
private void shutdownOutput0() throws java.lang.Exception
java.lang.Exception
private void shutdownInput0(ChannelPromise promise)
private void shutdownInput0() throws java.lang.Exception
java.lang.Exception
private void shutdown0(ChannelPromise promise)
protected java.net.SocketAddress localAddress0()
AbstractChannel
SocketAddress
which is bound locally.localAddress0
in class AbstractChannel
protected java.net.SocketAddress remoteAddress0()
AbstractChannel
SocketAddress
which the Channel
is connected to.remoteAddress0
in class AbstractChannel
protected void doBind(java.net.SocketAddress localAddress) throws java.lang.Exception
AbstractChannel
Channel
to the SocketAddress
doBind
in class AbstractChannel
java.lang.Exception
private void doBind0(java.net.SocketAddress localAddress) throws java.lang.Exception
java.lang.Exception
protected boolean doConnect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress) throws java.lang.Exception
AbstractNioChannel
doConnect
in class AbstractNioChannel
java.lang.Exception
protected void doFinishConnect() throws java.lang.Exception
AbstractNioChannel
doFinishConnect
in class AbstractNioChannel
java.lang.Exception
protected void doDisconnect() throws java.lang.Exception
AbstractChannel
Channel
from its remote peerdoDisconnect
in class AbstractChannel
java.lang.Exception
protected void doClose() throws java.lang.Exception
AbstractChannel
Channel
doClose
in class AbstractNioChannel
java.lang.Exception
protected int doReadBytes(ByteBuf byteBuf) throws java.lang.Exception
AbstractNioByteChannel
ByteBuf
and return the amount.doReadBytes
in class AbstractNioByteChannel
java.lang.Exception
protected int doWriteBytes(ByteBuf buf) throws java.lang.Exception
AbstractNioByteChannel
ByteBuf
to the underlying Channel
.doWriteBytes
in class AbstractNioByteChannel
buf
- the ByteBuf
from which the bytes should be writtenjava.lang.Exception
protected long doWriteFileRegion(FileRegion region) throws java.lang.Exception
AbstractNioByteChannel
FileRegion
doWriteFileRegion
in class AbstractNioByteChannel
region
- the FileRegion
from which the bytes should be writtenjava.lang.Exception
protected void doWrite(ChannelOutboundBuffer in) throws java.lang.Exception
AbstractChannel
doWrite
in class AbstractNioByteChannel
java.lang.Exception
protected AbstractNioChannel.AbstractNioUnsafe newUnsafe()
AbstractChannel
AbstractChannel.AbstractUnsafe
instance which will be used for the life-time of the Channel
newUnsafe
in class AbstractNioByteChannel