Top Description Methods
io.netty5.channel

public Interface Channel

extends AttributeMap, ChannelOutboundInvoker, Comparable<Channel>, IoHandle
Known Direct Subinterfaces
io.netty5.channel.ServerChannel, io.netty5.channel.socket.DatagramChannel, io.netty5.channel.socket.SocketChannel
Known Direct Implementers
io.netty5.channel.AbstractChannel
Imports
io.netty5.buffer.Buffer, .BufferAllocator, io.netty5.channel.socket.DatagramChannel, .DatagramPacket, .ServerSocketChannel, .SocketChannel, io.netty5.util.AttributeKey, .AttributeMap, io.netty5.util.concurrent.Future, java.net.InetSocketAddress, .SocketAddress

A nexus to a network socket or a component which is capable of I/O operations such as read, write, connect, and bind.

A channel provides a user:

All I/O operations are asynchronous.

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.

Channels are hierarchical

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.

Downcast to access transport-specific operations

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.

Storing stateful information

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.

Release resources

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.

Configuration / Option map

An option map property is a dynamic write-only property which allows the configuration of a Channel without down-casting. To update an option map, please call setOption(ChannelOption, Object).

All Channel types have the following options:

Name
ChannelOption#CONNECT_TIMEOUT_MILLIS
ChannelOption#WRITE_BUFFER_WATER_MARK
ChannelOption#BUFFER_ALLOCATOR
ChannelOption#AUTO_READ
ChannelOption#ALLOW_HALF_CLOSURE
ChannelOption#WRITE_HANDLE_FACTORY
ChannelOption#READ_HANDLE_FACTORY
ChannelOption#ALLOW_HALF_CLOSURE

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.

Method Summary

Modifier and TypeMethod and Description
public default Future<Void>
bind(SocketAddress localAddress)

Implements io.netty5.channel.ChannelOutboundInvoker.bind.

Request to bind to the given SocketAddress and notify the Future once the operation completes, either because the operation was successful or because of an error.
public BufferAllocator
bufferAllocator()

Return the assigned BufferAllocator which will be used to allocate Buffers.

public default Future<Void>
close()

Implements io.netty5.channel.ChannelOutboundInvoker.close.

Request to close the Channel and notify the Future once the operation completes, either because the operation was successful or because of an error.
public Future<Void>
closeFuture()

Returns the Future which will be notified when this channel is closed.

public default Future<Void>
connect(SocketAddress remoteAddress)

Implements io.netty5.channel.ChannelOutboundInvoker.connect.

Request to connect to the given SocketAddress and notify the Future once the operation completes, either because the operation was successful or because of an error.
public default Future<Void>
connect(SocketAddress remoteAddress, SocketAddress localAddress)

Implements io.netty5.channel.ChannelOutboundInvoker.connect.

Request to connect to the given 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<Void>
deregister()

Implements io.netty5.channel.ChannelOutboundInvoker.deregister.

Request to deregister from the previous assigned EventExecutor and notify the Future once the operation completes, either because the operation was successful or because of an error.
public default Future<Void>
disconnect()

Implements io.netty5.channel.ChannelOutboundInvoker.disconnect.

Request to disconnect from the remote peer and notify the Future once the operation completes, either because the operation was successful or because of an error.
public EventLoop
executor()

Redeclares io.netty5.channel.ChannelOutboundInvoker.executor.

Return the EventLoop this Channel was registered to.
public default Channel
flush()

Implements io.netty5.channel.ChannelOutboundInvoker.flush.

Request to flush all pending messages via this ChannelOutboundInvoker.
public <
the type of the value.
T
>
T

Returns:

the value for the ChannelOption
getOption
(ChannelOption<T> option)

Return the value of the given ChannelOption

public ChannelId
id()

Returns the globally unique identifier of this Channel.

public boolean
isActive()

Return true if the Channel is active and so connected.

public boolean
isOpen()

Returns true if the Channel is open and may get active later

public boolean

Returns:

true if supported, false otherwise.
isOptionSupported
(ChannelOption<?>
the option.
option
)

Returns true if the given ChannelOption is supported by this Channel implementation.

public boolean
isShutdown(ChannelShutdownDirection direction)

Returns true if the ChannelShutdownDirection of the Channel was shutdown before.

public default boolean
isWritable()

Returns true if and only if the I/O thread will perform the requested flush operation immediately.

public SocketAddress

Returns:

the local address of this channel. null if this channel is not bound.
localAddress
()

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.
parent
()

Returns the parent of this channel.

public ChannelPipeline
pipeline()

Return the assigned ChannelPipeline.

public default Channel
read(ReadBufferAllocator
The ReadBufferAllocator that should be used to allocate a Buffer if needed (for reading the data).
readBufferAllocator
)

Implements io.netty5.channel.ChannelOutboundInvoker.read.

Request to read data from the 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<Void>
register()

Implements io.netty5.channel.ChannelOutboundInvoker.register.

Request to register on the 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.
remoteAddress
()

Returns the remote address where this channel is connected to.

public default Future<Void>
public <
the type of the value.
T
>
Channel

Returns:

itself.
setOption
(ChannelOption<T> option, T
the value for the ChannelOption
value
)

Sets a configuration property with the specified name and value.

public default Future<Void>
shutdown(ChannelShutdownDirection direction)

Implements io.netty5.channel.ChannelOutboundInvoker.shutdown.

Request shutdown one direction of the 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 the Channel becomes unwritable.
writableBytes
()

Returns how many bytes can be written before the Channel becomes 'unwritable'.

public default Future<Void>
write(Object msg)

Implements io.netty5.channel.ChannelOutboundInvoker.write.

Request to write a message via this ChannelHandlerContext through the ChannelPipeline.
public default Future<Void>
Inherited from io.netty5.channel.ChannelOutboundInvoker:
newFailedFuturenewPromisenewSucceededFuturenewSucceededFuture
Inherited from io.netty5.channel.IoHandle:
isRegistered
Inherited from io.netty5.util.AttributeMap:
attrhasAttr
Inherited from java.lang.Comparable:
compareTo

Method Detail

bindback to summary
public default Future<Void> bind(SocketAddress localAddress)

Implements io.netty5.channel.ChannelOutboundInvoker.bind.

Doc from io.netty5.channel.ChannelOutboundInvoker.bind.

Request to bind to the given SocketAddress and notify the Future once the operation completes, either because the operation was successful or because of an error.

This will result in having the ChannelHandler#bind(ChannelHandlerContext, SocketAddress) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
bufferAllocatorback to summary
public BufferAllocator bufferAllocator()

Return the assigned BufferAllocator which will be used to allocate Buffers.

closeback to summary
public default Future<Void> close()

Implements io.netty5.channel.ChannelOutboundInvoker.close.

Doc from io.netty5.channel.ChannelOutboundInvoker.close.

Request to close the Channel and notify the Future 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 ChannelHandler#close(ChannelHandlerContext) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
closeFutureback to summary
public Future<Void> closeFuture()

Returns the Future which will be notified when this channel is closed. This method always returns the same future instance.

connectback to summary
public default Future<Void> connect(SocketAddress remoteAddress)

Implements io.netty5.channel.ChannelOutboundInvoker.connect.

Doc from io.netty5.channel.ChannelOutboundInvoker.connect.

Request to connect to the given SocketAddress and notify the Future 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 Future will get failed with a ConnectTimeoutException. If it fails because of connection refused a ConnectException will be used.

This will result in having the ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
connectback to summary
public default Future<Void> connect(SocketAddress remoteAddress, SocketAddress localAddress)

Implements io.netty5.channel.ChannelOutboundInvoker.connect.

Doc from io.netty5.channel.ChannelOutboundInvoker.connect.

Request to connect to the given 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.

This will result in having the ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
deregisterback to summary
public default Future<Void> deregister()

Implements io.netty5.channel.ChannelOutboundInvoker.deregister.

Doc from io.netty5.channel.ChannelOutboundInvoker.deregister.

Request to deregister from the previous assigned EventExecutor and notify the Future once the operation completes, either because the operation was successful or because of an error.

This will result in having the ChannelHandler#deregister(ChannelHandlerContext) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
disconnectback to summary
public default Future<Void> disconnect()

Implements io.netty5.channel.ChannelOutboundInvoker.disconnect.

Doc from io.netty5.channel.ChannelOutboundInvoker.disconnect.

Request to disconnect from the remote peer and notify the Future once the operation completes, either because the operation was successful or because of an error.

This will result in having the ChannelHandler#disconnect(ChannelHandlerContext) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
executorback to summary
public EventLoop executor()

Redeclares io.netty5.channel.ChannelOutboundInvoker.executor.

Return the EventLoop this Channel was registered to.

Returns:EventLoop

Doc from io.netty5.channel.ChannelOutboundInvoker.executor.

the executor.

Annotations
@Override
flushback to summary
public default Channel flush()

Implements io.netty5.channel.ChannelOutboundInvoker.flush.

Doc from io.netty5.channel.ChannelOutboundInvoker.flush.

Request to flush all pending messages via this ChannelOutboundInvoker.

Annotations
@Override
getOptionback to summary
public <T> T getOption(ChannelOption<T> option)

Return the value of the given ChannelOption

Parameters
<T>
the type of the value.
option:ChannelOption<T>

the ChannelOption.

Returns:T

the value for the ChannelOption

Exceptions
ChannelException:
thrown on error.
UnsupportedOperationException:
if the ChannelOption is not supported.
idback to summary
public ChannelId id()

Returns the globally unique identifier of this Channel.

isActiveback to summary
public boolean isActive()

Return true if the Channel is active and so connected.

isOpenback to summary
public boolean isOpen()

Returns true if the Channel is open and may get active later

isOptionSupportedback to summary
public boolean isOptionSupported(ChannelOption<?> option)

Returns true if the given ChannelOption is supported by this Channel implementation. If this methods returns false, calls to setOption(ChannelOption, Object) and getOption(ChannelOption) with the ChannelOption will throw an UnsupportedOperationException.

Parameters
option:ChannelOption<?>

the option.

Returns:boolean

true if supported, false otherwise.

isShutdownback to summary
public boolean isShutdown(ChannelShutdownDirection direction)

Returns true if the ChannelShutdownDirection of the Channel was shutdown before.

isWritableback to summary
public default boolean isWritable()

Returns true if and only if the I/O thread will perform the requested flush operation immediately. Any write requests made when this method returns false are queued until the I/O thread is ready to process the queued write requests.

localAddressback to summary
public SocketAddress localAddress()

Returns the local address where this channel is bound to. The returned SocketAddress is supposed to be down-cast into more concrete type such as InetSocketAddress to retrieve the detailed information.

Returns:SocketAddress

the local address of this channel. null if this channel is not bound.

parentback to summary
public Channel parent()

Returns the parent of this channel.

Returns:Channel

the parent channel. null if this channel does not have a parent channel.

pipelineback to summary
public ChannelPipeline pipeline()

Return the assigned ChannelPipeline.

readback to summary
public default Channel read(ReadBufferAllocator readBufferAllocator)

Implements io.netty5.channel.ChannelOutboundInvoker.read.

Doc from io.netty5.channel.ChannelOutboundInvoker.read.

Request to read data from the 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. If there's a pending read operation already, this method does nothing.

This will result in having the ChannelHandler#read(ChannelHandlerContext, ReadBufferAllocator) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Parameters
readBufferAllocator:ReadBufferAllocator

The ReadBufferAllocator that should be used to allocate a Buffer if needed (for reading the data).

Annotations
@Override
readback to summary
public default Channel read()

Implements io.netty5.channel.ChannelOutboundInvoker.read.

Annotations
@Override
registerback to summary
public default Future<Void> register()

Implements io.netty5.channel.ChannelOutboundInvoker.register.

Doc from io.netty5.channel.ChannelOutboundInvoker.register.

Request to register on the EventExecutor for I/O processing. Future once the operation completes, either because the operation was successful or because of an error.

This will result in having the ChannelHandler#register(ChannelHandlerContext) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
remoteAddressback to summary
public SocketAddress remoteAddress()

Returns the remote address where this channel is connected to. The returned SocketAddress is supposed to be down-cast into more concrete type such as InetSocketAddress to retrieve the detailed information.

Returns:SocketAddress

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.

sendOutboundEventback to summary
public default Future<Void> sendOutboundEvent(Object event)

Implements io.netty5.channel.ChannelOutboundInvoker.sendOutboundEvent.

Doc from io.netty5.channel.ChannelOutboundInvoker.sendOutboundEvent.

Send a custom outbound event via this ChannelOutboundInvoker through the ChannelPipeline.

This will result in having the ChannelHandler#sendOutboundEvent(ChannelHandlerContext, Object) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
setOptionback to summary
public <T> Channel setOption(ChannelOption<T> option, T value)

Sets a configuration property with the specified name and value.

Parameters
<T>
the type of the value.
option:ChannelOption<T>

the ChannelOption.

value:T

the value for the ChannelOption

Returns:Channel

itself.

Exceptions
ChannelException:
thrown on error.
UnsupportedOperationException:
if the ChannelOption is not supported.
shutdownback to summary
public default Future<Void> shutdown(ChannelShutdownDirection direction)

Implements io.netty5.channel.ChannelOutboundInvoker.shutdown.

Doc from io.netty5.channel.ChannelOutboundInvoker.shutdown.

Request shutdown one direction of the Channel and notify the Future once the operation completes, either because the operation was successful or because of an error.

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 ChannelShutdownDirection.

Depending on the transport implementation shutting down the ChannelShutdownDirection#Outbound or ChannelShutdownDirection#Inbound might also result in data transferred over the network. Like for example in case of TCP shutting down the ChannelShutdownDirection#Outbound will result in a FIN that is transmitted to the remote peer that will as a result shutdown ChannelShutdownDirection#Inbound.

This will result in having the ChannelHandler#shutdown(ChannelHandlerContext, ChannelShutdownDirection). method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
writableBytesback to summary
public long writableBytes()

Returns how many bytes can be written before the Channel becomes 'unwritable'. Once a Channel becomes unwritable, all messages will be queued until the I/O thread is ready to process the queued write requests.

Returns:long

the number of bytes that can be written before the Channel becomes unwritable.

writeback to summary
public default Future<Void> write(Object msg)

Implements io.netty5.channel.ChannelOutboundInvoker.write.

Doc from io.netty5.channel.ChannelOutboundInvoker.write.

Request to write a message via this ChannelHandlerContext through the ChannelPipeline. This method will not request to actual flush, so be sure to call flush() once you want to request to flush all pending data to the actual transport.

Annotations
@Override
writeAndFlushback to summary
public default Future<Void> writeAndFlush(Object msg)

Implements io.netty5.channel.ChannelOutboundInvoker.writeAndFlush.

Doc from io.netty5.channel.ChannelOutboundInvoker.writeAndFlush.

Shortcut for call write(Object) and flush().

Annotations
@Override