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 Future 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.
attr(AttributeKey) allow you to
store and access stateful information that is related with a handler and its
context. Please refer to ChannelHandler to learn various recommended
ways to manage stateful information.
It is important to call close() to release all
resources once you are done with the Channel. This ensures all resources are
released in a proper way, i.e. filehandles.
Channel without down-casting.
To update an option map, please call setOption(ChannelOption, Object).
All Channel types have the following options:
More options are available in the sub-types of Channel. For
example, you can configure the parameters which are specific to a TCP/IP
socket as explained in SocketChannel.
| Modifier and Type | Method and Description |
|---|---|
| public default Future | bind(SocketAddress localAddress)
Implements io. SocketAddress and notify the Future once the operation
completes, either because the operation was successful or because of an error.
|
| public BufferAllocator | |
| public default Future | close()
Implements io. Channel and notify the Future once the operation completes,
either because the operation was successful or because of
an error.
|
| public Future | |
| public default Future | connect(SocketAddress remoteAddress)
Implements io. SocketAddress and notify the Future once the operation
completes, either because the operation was successful or because of an error.
|
| public default Future | connect(SocketAddress remoteAddress, SocketAddress localAddress)
Implements io. SocketAddress while bind to the localAddress and notify the
Future once the operation completes, either because the operation was successful or because of
an error.
|
| public default Future | deregister()
Implements io. EventExecutor and notify the
Future once the operation completes, either because the operation was successful or because of
an error.
|
| public default Future | disconnect()
Implements io. Future once the operation completes,
either because the operation was successful or because of an error.
|
| public EventLoop | executor()
Redeclares io. EventLoop this Channel was registered to.
|
| public default Channel | flush()
Implements io. |
| public < the type of the value. T> T | Returns: the value for theChannelOptionthe option)ChannelOption.Return the value of the given |
| public ChannelId | |
| public boolean | |
| public boolean | |
| public boolean | Returns: true if supported, false otherwise.the option. option)Returns |
| public boolean | isShutdown(ChannelShutdownDirection direction)
Returns |
| public default 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 Channel | Returns: the parent channel.null if this channel does not have a parent channel.Returns the parent of this channel. |
| public ChannelPipeline | |
| public default Channel | read(ReadBufferAllocator
The readBufferAllocator)ReadBufferAllocator that should be used to allocate a Buffer
if needed (for reading the data).Implements io. Channel, triggers an
ChannelHandler#channelRead(ChannelHandlerContext, Object) event if data was
read, and triggers a
channelReadComplete event so the
handler can decide to continue reading.
|
| public default Channel | |
| public default Future | register()
Implements io. EventExecutor for I/O processing.
|
| 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 default Future | sendOutboundEvent(Object event)
Implements io. ChannelOutboundInvoker through the
ChannelPipeline.
|
| public < the type of the value. T> Channel | Returns: itself.the option, T ChannelOption.the value for the value)ChannelOptionSets a configuration property with the specified name and value. |
| public default Future | shutdown(ChannelShutdownDirection direction)
Implements io. Channel and notify the Future once the operation completes,
either because the operation was successful or because of an error.
|
| public long | Returns: the number of bytes that can be written before theChannel becomes unwritable.Returns how many bytes can be written before the |
| public default Future | write(Object msg)
Implements io. ChannelHandlerContext through the ChannelPipeline.
|
| public default Future | writeAndFlush(Object msg)
Implements io. write(Object) and flush().
|
| bind | back to summary |
|---|---|
| public default Future Implements io. Doc from io. Request to bind to the given
This will result in having the
| |
| bufferAllocator | back to summary |
|---|---|
| public BufferAllocator bufferAllocator() Return the assigned | |
| close | back to summary |
|---|---|
| public default Future Implements io. Doc from io. Request to close the
This will result in having the
| |
| closeFuture | back to summary |
|---|---|
| public Future Returns the | |
| connect | back to summary |
|---|---|
| public default Future Implements io. Doc from io. Request to connect to the given
If the connection fails because of a connection timeout, the
This will result in having the
| |
| connect | back to summary |
|---|---|
| public default Future Implements io. Doc from io. Request to connect to the given
This will result in having the
| |
| deregister | back to summary |
|---|---|
| public default Future Implements io. Doc from io. Request to deregister from the previous assigned
This will result in having the
| |
| disconnect | back to summary |
|---|---|
| public default Future Implements io. Doc from io. Request to disconnect from the remote peer and notify the
This will result in having the
| |
| executor | back to summary |
|---|---|
| public EventLoop executor() Redeclares io. Return the
| |
| flush | back to summary |
|---|---|
| public default Channel flush() Implements io. Doc from io. Request to flush all pending messages via this ChannelOutboundInvoker.
| |
| getOption | back to summary |
|---|---|
| public <T> T getOption(ChannelOption<T> option) Return the value of the given
| |
| 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 | |
| isOptionSupported | back to summary |
|---|---|
| public boolean isOptionSupported(ChannelOption<?> option) Returns
| |
| isShutdown | back to summary |
|---|---|
| public boolean isShutdown(ChannelShutdownDirection direction) Returns | |
| isWritable | back to summary |
|---|---|
| public default boolean isWritable() Returns | |
| localAddress | back to summary |
|---|---|
| public SocketAddress localAddress() Returns the local address where this channel is bound to. The returned
| |
| 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 default Channel read(ReadBufferAllocator readBufferAllocator) Implements io. Doc from io. Request to read data from the
This will result in having the
| |
| read | back to summary |
|---|---|
| public default Channel read() Implements io.
| |
| register | back to summary |
|---|---|
| public default Future Implements io. Doc from io. Request to register on 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
| |
| sendOutboundEvent | back to summary |
|---|---|
| public default Future Implements io. Doc from io. Send a custom outbound event via this
This will result in having the
| |
| setOption | back to summary |
|---|---|
| public <T> Channel setOption(ChannelOption<T> option, T value) Sets a configuration property with the specified name and value.
| |
| shutdown | back to summary |
|---|---|
| public default Future Implements io. Doc from io. Request shutdown one direction of the
When completed, the channel will either not produce any inbound data anymore, or it will not be
possible to write data anymore, depending on the given
Depending on the transport implementation shutting down the
This will result in having the
| |
| writableBytes | back to summary |
|---|---|
| public long writableBytes() Returns how many bytes can be written before the
| |
| write | back to summary |
|---|---|
| public default Future Implements io. Doc from io. Request to write a message via this
| |
| writeAndFlush | back to summary |
|---|---|
| public default Future Implements io. Doc from io. Shortcut for call
| |