A channel provides a user:
ChannelPipeline which handles all I/O events and requests
associated with the channel.
All I/O operations in Netty are asynchronous. It means any I/O calls will
return immediately with no guarantee that the requested I/O operation has
been completed at the end of the call. Instead, you will be returned with
a ChannelFuture instance which will notify you when the requested I/O
operation has succeeded, failed, or canceled.
A Channel can have a parent depending on
how it was created. For instance, a SocketChannel, that was accepted
by ServerSocketChannel, will return the ServerSocketChannel
as its parent on parent().
The semantics of the hierarchical structure depends on the transport
implementation where the Channel belongs to. For example, you could
write a new Channel implementation that creates the sub-channels that
share one socket connection, as BEEP and
SSH do.
Some transports exposes additional operations that is specific to the
transport. Down-cast the Channel to sub-type to invoke such
operations. For example, with the old I/O datagram transport, multicast
join / leave operations are provided by DatagramChannel.
It is important to call close() or close(ChannelPromise) to release all
resources once you are done with the Channel. This ensures all resources are
released in a proper way, i.e. filehandles.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | Channel.
Unsafe operations that should never be called from user-code. |
| Modifier and Type | Method and Description |
|---|---|
| public ByteBufAllocator | |
| public long | |
| public long | bytesBeforeWritable()
Get how many bytes must be drained from underlying buffers until |
| public ChannelFuture | |
| public ChannelConfig | |
| public EventLoop | |
| public Channel | flush()
Redeclares io. |
| public ChannelId | |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | isWritable()
Returns |
| public SocketAddress | Returns: the local address of this channel.null if this channel is not bound.Returns the local address where this channel is bound to. |
| public ChannelMetadata | |
| public Channel | Returns: the parent channel.null if this channel does not have a parent channel.Returns the parent of this channel. |
| public ChannelPipeline | |
| public Channel | read()
Redeclares io. Channel into the first inbound buffer, triggers an
ChannelInboundHandler#channelRead(ChannelHandlerContext, Object) event if data was
read, and triggers a
channelReadComplete event so the
handler can decide to continue reading.
|
| public SocketAddress | Returns: the remote address of this channel.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 DatagramPacket#recipient() to determine
the origination of the received message as this method will
return null.Returns the remote address where this channel is connected to. |
| public Channel. |
| alloc | back to summary |
|---|---|
| public ByteBufAllocator alloc() Return the assigned | |
| bytesBeforeUnwritable | back to summary |
|---|---|
| public long bytesBeforeUnwritable() Get how many bytes can be written until | |
| bytesBeforeWritable | back to summary |
|---|---|
| public long bytesBeforeWritable() Get how many bytes must be drained from underlying buffers until | |
| closeFuture | back to summary |
|---|---|
| public ChannelFuture closeFuture() Returns the | |
| config | back to summary |
|---|---|
| public ChannelConfig config() Returns the configuration of this channel. | |
| eventLoop | back to summary |
|---|---|
| public EventLoop eventLoop() | |
| flush | back to summary |
|---|---|
| public Channel flush() Redeclares io. Doc from io. Request to flush all pending messages via this ChannelOutboundInvoker.
| |
| id | back to summary |
|---|---|
| public ChannelId id() Returns the globally unique identifier of this | |
| isActive | back to summary |
|---|---|
| public boolean isActive() Return | |
| isOpen | back to summary |
|---|---|
| public boolean isOpen() Returns | |
| isRegistered | back to summary |
|---|---|
| public boolean isRegistered() Returns | |
| isWritable | back to summary |
|---|---|
| public boolean isWritable() Returns | |
| localAddress | back to summary |
|---|---|
| public SocketAddress localAddress() Returns the local address where this channel is bound to. The returned
| |
| metadata | back to summary |
|---|---|
| public ChannelMetadata metadata() Return the | |
| parent | back to summary |
|---|---|
| public Channel parent() Returns the parent of this channel.
| |
| pipeline | back to summary |
|---|---|
| public ChannelPipeline pipeline() Return the assigned | |
| read | back to summary |
|---|---|
| public Channel read() Redeclares io. Doc from io. Request to Read data from the
This will result in having the
| |
| remoteAddress | back to summary |
|---|---|
| public SocketAddress remoteAddress() Returns the remote address where this channel is connected to. The
returned
| |
| unsafe | back to summary |
|---|---|
| public Channel. Returns an internal-use-only object that provides unsafe operations. | |
| Modifier and Type | Method and Description |
|---|---|
| public void | beginRead()
Schedules a read operation that fills the inbound buffer of the first |
| public void | bind(SocketAddress localAddress, ChannelPromise promise)
Bind the |
| public void | close(ChannelPromise promise)
Close the |
| public void | |
| public void | connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise)
Connect the |
| public void | deregister(ChannelPromise promise)
Deregister the |
| public void | disconnect(ChannelPromise promise)
Disconnect the |
| public void | |
| public SocketAddress | |
| public ChannelOutboundBuffer | outboundBuffer()
Returns the |
| public RecvByteBufAllocator. | recvBufAllocHandle()
Deprecated
as a consequence of
Return the assigned RecvByteBufAllocator.Handle being deprecated.
RecvByteBufAllocator. which will be used to allocate ByteBuf's when
receiving data.
|
| public void | register(EventLoop eventLoop, ChannelPromise promise)
Register the |
| public SocketAddress | |
| public ChannelPromise | voidPromise()
Return a special ChannelPromise which can be reused and passed to the operations in |
| public void |
| beginRead | back to summary |
|---|---|
| public void beginRead() Schedules a read operation that fills the inbound buffer of the first | |
| bind | back to summary |
|---|---|
| public void bind(SocketAddress localAddress, ChannelPromise promise) Bind the | |
| close | back to summary |
|---|---|
| public void close(ChannelPromise promise) Close the | |
| closeForcibly | back to summary |
|---|---|
| public void closeForcibly() Closes the | |
| connect | back to summary |
|---|---|
| public void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) Connect the | |
| deregister | back to summary |
|---|---|
| public void deregister(ChannelPromise promise) Deregister the | |
| disconnect | back to summary |
|---|---|
| public void disconnect(ChannelPromise promise) Disconnect the | |
| flush | back to summary |
|---|---|
| public void flush() Flush out all write operations scheduled via | |
| localAddress | back to summary |
|---|---|
| public SocketAddress localAddress() Return the | |
| outboundBuffer | back to summary |
|---|---|
| public ChannelOutboundBuffer outboundBuffer() Returns the | |
| recvBufAllocHandle | back to summary |
|---|---|
| public RecvByteBufAllocator. Deprecated as a consequence of Return the assigned | |
| register | back to summary |
|---|---|
| public void register(EventLoop eventLoop, ChannelPromise promise) Register the | |
| remoteAddress | back to summary |
|---|---|
| public SocketAddress remoteAddress() Return the | |
| voidPromise | back to summary |
|---|---|
| public ChannelPromise voidPromise() Return a special ChannelPromise which can be reused and passed to the operations in | |
| write | back to summary |
|---|---|
| public void write(Object msg, ChannelPromise promise) Schedules a write operation. | |