public class NioSocketChannel extends AbstractNioByteChannel implements SocketChannel
SocketChannel which uses NIO selector based implementation.AbstractNioChannel.AbstractNioUnsafe, AbstractNioChannel.NioUnsafeAbstractChannel.AbstractUnsafeChannel.UnsafereadInterestOp| Constructor and Description |
|---|
NioSocketChannel()
Create a new instance
|
NioSocketChannel(Channel parent,
Integer id,
SocketChannel socket)
Create a new instance
|
NioSocketChannel(SocketChannel socket)
Create a new instance using the given
SocketChannel. |
| Modifier and Type | Method and Description |
|---|---|
io.netty.buffer.ByteBufAllocator |
alloc()
Return the assigned
ByteBufAllocator which will be used for allocate ByteBufs. |
ChannelFuture |
bind(SocketAddress localAddress)
Request to bind to the given
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error. |
ChannelFuture |
bind(SocketAddress localAddress,
ChannelPromise promise)
Request to bind to the given
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error. |
ChannelFuture |
close()
Request to close this ChannelOutboundInvoker and notify the
ChannelFuture once the operation completes,
either because the operation was successful or because of
an error. |
ChannelFuture |
close(ChannelPromise promise)
Request to close this ChannelOutboundInvoker and notify the
ChannelFuture once the operation completes,
either because the operation was successful or because of
an error. |
SocketChannelConfig |
config()
Returns the configuration of this channel.
|
ChannelFuture |
connect(SocketAddress remoteAddress)
Request to connect to the given
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error. |
ChannelFuture |
connect(SocketAddress remoteAddress,
ChannelPromise promise)
Request to connect to the given
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error. |
ChannelFuture |
connect(SocketAddress remoteAddress,
SocketAddress localAddress)
Request to connect to the given
SocketAddress while bind to the localAddress and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error. |
ChannelFuture |
connect(SocketAddress remoteAddress,
SocketAddress localAddress,
ChannelPromise promise)
Request to connect to the given
SocketAddress while bind to the localAddress and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error. |
ChannelFuture |
deregister()
Request to deregister this ChannelOutboundInvoker from the previous assigned
EventExecutor and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error. |
ChannelFuture |
deregister(ChannelPromise promise)
Request to deregister this ChannelOutboundInvoker from the previous assigned
EventExecutor and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error. |
ChannelFuture |
disconnect()
Request to discconect from the remote peer and notify the
ChannelFuture once the operation completes,
either because the operation was successful or because of an error. |
ChannelFuture |
disconnect(ChannelPromise promise)
Request to discconect from the remote peer and notify the
ChannelFuture once the operation completes,
either because the operation was successful or because of an error. |
protected void |
doBind(SocketAddress localAddress)
Bind the
Channel to the SocketAddress |
protected void |
doClose()
Close the
Channel |
protected boolean |
doConnect(SocketAddress remoteAddress,
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(io.netty.buffer.ByteBuf byteBuf)
Read bytes into the given
ByteBuf and return the amount. |
protected int |
doWrite(MessageList<Object> msgs,
int index)
Flush the content of the given
ByteBuf to the remote peer. |
protected int |
doWriteBytes(io.netty.buffer.ByteBuf buf,
boolean lastSpin)
Write bytes form the given
ByteBuf to the underlying Channel. |
protected long |
doWriteFileRegion(FileRegion region,
boolean lastSpin)
Write a
FileRegion |
boolean |
isActive()
Return
true if the Channel is active and so connected. |
boolean |
isInputShutdown()
Return
true if the input of this Channel is shutdown |
boolean |
isOutputShutdown() |
protected SocketChannel |
javaChannel() |
InetSocketAddress |
localAddress()
Returns the local address where this channel is bound to.
|
protected SocketAddress |
localAddress0()
Returns the
SocketAddress which is bound locally. |
ChannelMetadata |
metadata()
|
ChannelFuture |
newFailedFuture(Throwable cause)
Create a new
ChannelFuture which is marked as fakued already. |
ChannelProgressivePromise |
newProgressivePromise()
Return an new
ChannelProgressivePromise |
ChannelPromise |
newPromise()
Return a new
ChannelPromise. |
ChannelFuture |
newSucceededFuture()
Create a new
ChannelFuture which is marked as successes already. |
ServerSocketChannel |
parent()
Returns the parent of this channel.
|
ChannelPipeline |
pipeline()
Return the assigned
ChannelPipeline |
void |
read()
Request to Read data from the
Channel into the first inbound buffer, triggers an
ChannelInboundHandler.messageReceived(ChannelHandlerContext, MessageList) event if data was
read, and triggers an
channelReadSuspended event so the
handler can decide to continue reading. |
InetSocketAddress |
remoteAddress()
Returns the remote address where this channel is connected to.
|
protected SocketAddress |
remoteAddress0()
Return the
SocketAddress which the Channel is connected to. |
ChannelFuture |
shutdownOutput() |
ChannelFuture |
shutdownOutput(ChannelPromise promise) |
ChannelPromise |
voidPromise()
Return a special ChannelPromise which can be reused for different operations.
|
ChannelFuture |
write(MessageList<?> msgs) |
ChannelFuture |
write(MessageList<?> msgs,
ChannelPromise promise) |
ChannelFuture |
write(Object msg)
Request to write a message via this ChannelOutboundInvoker and notify the
ChannelFuture
once the operation completes, either because the operation was successful or because of an error. |
ChannelFuture |
write(Object msg,
ChannelPromise promise)
Request to write a message via this ChannelOutboundInvoker and notify the
ChannelFuture
once the operation completes, either because the operation was successful or because of an error. |
newUnsafe, updateOpWritedoBeginRead, doDeregister, doRegister, eventLoop, isCompatible, isFlushPending, isOpen, selectionKey, unsafealloc, bind, bind, calculateMessageSize, checkEOF, close, close, closeFuture, compareTo, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, doPreClose, equals, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, isWritable, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, pipeline, read, toString, voidPromise, write, write, write, writeclone, finalize, getClass, notify, notifyAll, wait, wait, waitcloseFuture, eventLoop, id, isOpen, isRegistered, isWritable, unsafecompareTopublic NioSocketChannel()
public NioSocketChannel(SocketChannel socket)
SocketChannel.public NioSocketChannel(Channel parent, Integer id, SocketChannel socket)
parent - the Channel which created this instance or null if it was created by the userid - the id to use for this instance or null if a new one should be generatedsocket - the SocketChannel which will be usedpublic ServerSocketChannel parent()
Channelparent in interface Channelparent in interface SocketChannelparent in class AbstractChannelnull if this channel does not have a parent channel.public ChannelMetadata metadata()
Channelpublic SocketChannelConfig config()
Channelconfig in interface Channelconfig in interface SocketChannelprotected SocketChannel javaChannel()
javaChannel in class AbstractNioChannelpublic boolean isActive()
Channeltrue if the Channel is active and so connected.public boolean isInputShutdown()
AbstractNioChanneltrue if the input of this Channel is shutdownisInputShutdown in interface SocketChannelisInputShutdown in class AbstractNioChannelpublic InetSocketAddress localAddress()
ChannelSocketAddress is supposed to be down-cast into more concrete
type such as InetSocketAddress to retrieve the detailed
information.localAddress in interface ChannellocalAddress in interface SocketChannellocalAddress in class AbstractChannelnull if this channel is not bound.public InetSocketAddress remoteAddress()
ChannelSocketAddress is supposed to be down-cast into more
concrete type such as InetSocketAddress to retrieve the detailed
information.remoteAddress in interface ChannelremoteAddress in interface SocketChannelremoteAddress in class AbstractChannelnull 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 boolean isOutputShutdown()
isOutputShutdown in interface SocketChannelSocket.isOutputShutdown()public ChannelFuture shutdownOutput()
shutdownOutput in interface SocketChannelSocket.shutdownOutput()public ChannelFuture shutdownOutput(ChannelPromise promise)
shutdownOutput in interface SocketChannelWill notify the given {@link ChannelPromise}protected SocketAddress localAddress0()
AbstractChannelSocketAddress which is bound locally.localAddress0 in class AbstractChannelprotected SocketAddress remoteAddress0()
AbstractChannelSocketAddress which the Channel is connected to.remoteAddress0 in class AbstractChannelprotected void doBind(SocketAddress localAddress) throws Exception
AbstractChannelChannel to the SocketAddressdoBind in class AbstractChannelExceptionprotected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception
AbstractNioChanneldoConnect in class AbstractNioChannelExceptionprotected void doFinishConnect()
throws Exception
AbstractNioChanneldoFinishConnect in class AbstractNioChannelExceptionprotected void doDisconnect()
throws Exception
AbstractChannelChannel from its remote peerdoDisconnect in class AbstractChannelExceptionprotected void doClose()
throws Exception
AbstractChannelChanneldoClose in class AbstractChannelExceptionprotected int doReadBytes(io.netty.buffer.ByteBuf byteBuf)
throws Exception
AbstractNioByteChannelByteBuf and return the amount.doReadBytes in class AbstractNioByteChannelExceptionprotected int doWriteBytes(io.netty.buffer.ByteBuf buf,
boolean lastSpin)
throws Exception
AbstractNioByteChannelByteBuf to the underlying Channel.doWriteBytes in class AbstractNioByteChannelbuf - the ByteBuf from which the bytes should be writtenlastSpin - true if this is the last write tryException - thrown if an error accourprotected long doWriteFileRegion(FileRegion region, boolean lastSpin) throws Exception
AbstractNioByteChannelFileRegiondoWriteFileRegion in class AbstractNioByteChannelregion - the FileRegion from which the bytes should be writtenlastSpin - true if this is the last write tryException - thrown if an error accourprotected int doWrite(MessageList<Object> msgs, int index) throws Exception
AbstractChannelByteBuf to the remote peer.
Sub-classes may override this as this implementation will just thrown an UnsupportedOperationExceptiondoWrite in class AbstractNioByteChannelExceptionpublic ChannelFuture bind(SocketAddress localAddress)
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error.
This will result in having the
ChannelOutboundHandler.bind(ChannelHandlerContext, SocketAddress, ChannelPromise) method
called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture connect(SocketAddress remoteAddress)
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error.
If the connection fails because of a connection timeout, the ChannelFuture will get failed with
a ConnectTimeoutException. If it fails because of connection refused a ConnectException
will be used.
This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress)
SocketAddress while bind to the localAddress and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error.
This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture disconnect()
ChannelFuture once the operation completes,
either because the operation was successful or because of an error.
This will result in having the
ChannelOutboundHandler.disconnect(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture close()
ChannelFuture once the operation completes,
either because the operation was successful or because of
an error.
After it is closed it is not possible to reuse it again.
This will result in having the
ChannelOutboundHandler.close(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture deregister()
EventExecutor and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error.
This will result in having the
ChannelOutboundHandler.deregister(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture write(Object msg)
ChannelFuture
once the operation completes, either because the operation was successful or because of an error.public ChannelFuture write(MessageList<?> msgs)
public ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise)
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error.
The given ChannelPromise will be notified.
This will result in having the
ChannelOutboundHandler.bind(ChannelHandlerContext, SocketAddress, ChannelPromise) method
called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise)
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error.
The given ChannelFuture will be notified.
If the connection fails because of a connection timeout, the ChannelFuture will get failed with
a ConnectTimeoutException. If it fails because of connection refused a ConnectException
will be used.
This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise)
SocketAddress while bind to the localAddress and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error.
The given ChannelPromise will be notified and also returned.
This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture disconnect(ChannelPromise promise)
ChannelFuture once the operation completes,
either because the operation was successful or because of an error.
The given ChannelPromise will be notified.
This will result in having the
ChannelOutboundHandler.disconnect(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture close(ChannelPromise promise)
ChannelFuture once the operation completes,
either because the operation was successful or because of
an error.
After it is closed it is not possible to reuse it again.
The given ChannelPromise will be notified.
This will result in having the
ChannelOutboundHandler.close(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture deregister(ChannelPromise promise)
EventExecutor and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error.
The given ChannelPromise will be notified.
This will result in having the
ChannelOutboundHandler.deregister(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public void read()
Channel into the first inbound buffer, triggers an
ChannelInboundHandler.messageReceived(ChannelHandlerContext, MessageList) event if data was
read, and triggers an
channelReadSuspended event so the
handler can decide to continue reading. If there's a pending read operation already, this method does nothing.
This will result in having the
ChannelOutboundHandler.read(ChannelHandlerContext)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
public ChannelFuture write(Object msg, ChannelPromise promise)
ChannelFuture
once the operation completes, either because the operation was successful or because of an error.public ChannelFuture write(MessageList<?> msgs, ChannelPromise promise)
public ChannelPipeline pipeline()
ChannelPipelinepublic io.netty.buffer.ByteBufAllocator alloc()
ByteBufAllocator which will be used for allocate ByteBufs.public ChannelPromise newPromise()
ChannelPromise.public ChannelProgressivePromise newProgressivePromise()
ChannelProgressivePromisepublic ChannelFuture newSucceededFuture()
ChannelFuture which is marked as successes already. So Future.isSuccess()
will return true. All FutureListener added to it will be notified directly. Also
every call of blocking methods will just return without blocking.public ChannelFuture newFailedFuture(Throwable cause)
ChannelFuture which is marked as fakued already. So Future.isSuccess()
will return false. All FutureListener added to it will be notified directly. Also
every call of blocking methods will just return without blocking.public ChannelPromise voidPromise()
It's only supported to use
it for ChannelOutboundInvoker.write(Object, ChannelPromise) and,
ChannelOutboundInvoker.write(MessageList, ChannelPromise).
Be aware that the returned ChannelPromise will not support most operations and should only be used
if you want to safe object allocation for every operation. You will not be able to detect if the operation
was complete, only if it failed as the implementation will call
ChannelPipeline.fireExceptionCaught(Throwable) in this case.
Copyright © 2008-2013 The Netty Project. All Rights Reserved.