Top Description Inners Fields Constructors Methods
io.netty5.channel.embedded

public Class EmbeddedChannel

extends AbstractChannel<Channel, SocketAddress, SocketAddress>
Class Inheritance
Imports
io.netty5.buffer.Buffer, io.netty5.buffer.internal.ResourceSupport, .InternalBufferUtils, io.netty5.channel.AdaptiveReadHandleFactory, .ChannelShutdownDirection, .MaxMessagesWriteHandleFactory, .AbstractChannel, .Channel, .ChannelHandler, .ChannelHandlerContext, .ChannelId, .ChannelInitializer, .ChannelPipeline, .DefaultChannelPipeline, .EventLoop, io.netty5.util.Resource, .ReferenceCountUtil, io.netty5.util.concurrent.Future, .FutureListener, io.netty5.util.internal.RecyclableArrayList, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.net.SocketAddress, java.nio.channels.ClosedChannelException, java.util.ArrayDeque, .Queue, java.util.concurrent.TimeUnit

Base class for Channel implementations that are used in an embedded fashion.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static enum

Field Summary

Modifier and TypeField and Description
private static final ChannelHandler[]
private Queue<Object>
private boolean
private Throwable
private static final SocketAddress
private static final InternalLogger
private Queue<Object>
private boolean
private final FutureListener<Void>
private static final SocketAddress
private EmbeddedChannel.State

Constructor Summary

AccessConstructor and Description
public
EmbeddedChannel()

Create a new instance with an EmbeddedChannelId and an empty pipeline.

public
EmbeddedChannel(ChannelId
the ChannelId that will be used to identify this channel
channelId
)

Create a new instance with the specified ID and an empty pipeline.

public
EmbeddedChannel(ChannelHandler...
the ChannelHandlers which will be add in the ChannelPipeline
handlers
)

Create a new instance with the pipeline initialized with the specified handlers.

public
EmbeddedChannel(boolean
false if this Channel will delegate disconnect() to close(), false otherwise.
hasDisconnect
,
ChannelHandler...
the ChannelHandlers which will be add in the ChannelPipeline
handlers
)

Create a new instance with the pipeline initialized with the specified handlers.

public
EmbeddedChannel(boolean
true if this Channel is registered to the EventLoop in the constructor. If false the user will need to call register().
register
,
boolean
false if this Channel will delegate disconnect() to close(), false otherwise.
hasDisconnect
,
ChannelHandler...
the ChannelHandlers which will be add in the ChannelPipeline
handlers
)

Create a new instance with the pipeline initialized with the specified handlers.

public
EmbeddedChannel(ChannelId
the ChannelId that will be used to identify this channel
channelId
,
ChannelHandler...
the ChannelHandlers which will be add in the ChannelPipeline
handlers
)

Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.

public
EmbeddedChannel(ChannelId
the ChannelId that will be used to identify this channel
channelId
,
boolean
false if this Channel will delegate disconnect() to close(), false otherwise.
hasDisconnect
,
ChannelHandler...
the ChannelHandlers which will be add in the ChannelPipeline
handlers
)

Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.

public
EmbeddedChannel(ChannelId
the ChannelId that will be used to identify this channel
channelId
,
boolean
true if this Channel is registered to the EventLoop in the constructor. If false the user will need to call register().
register
,
boolean
false if this Channel will delegate disconnect() to close(), false otherwise.
hasDisconnect
,
ChannelHandler...
the ChannelHandlers which will be add in the ChannelPipeline
handlers
)

Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.

public
EmbeddedChannel(Channel
the parent Channel of this EmbeddedChannel.
parent
,
ChannelId
the ChannelId that will be used to identify this channel
channelId
,
boolean
true if this Channel is registered to the EventLoop in the constructor. If false the user will need to call register().
register
,
boolean
false if this Channel will delegate disconnect() to close(), false otherwise.
hasDisconnect
,
final ChannelHandler...
the ChannelHandlers which will be add in the ChannelPipeline
handlers
)

Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.

Method Summary

Modifier and TypeMethod and Description
public void
advanceTimeBy(long duration, TimeUnit unit)

Advance the clock of the event loop of this channel by the given duration.

public void
checkException()

Check if there was any Throwable received and if so rethrow it.

private Future<Void>
checkException0()

Checks for the presence of an Exception.

private boolean
checkOpen(boolean recordException)

Returns true if the Channel is open and records optionally an Exception if it isn't.

public final Future<Void>
close()

Overrides default io.netty5.channel.Channel.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 final Future<Void>
disconnect()

Overrides default io.netty5.channel.Channel.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.
protected void
doBind(SocketAddress
the SocketAddress to bound to.
localAddress
)

Implements abstract io.netty5.channel.AbstractChannel.doBind.

Bind the Channel to the SocketAddress
protected void
protected boolean
doConnect(SocketAddress
the address of the remote peer.
remoteAddress
,
SocketAddress
the local address of this channel.
localAddress
,
Buffer
the initial data that is written during connect (if ChannelOption#TCP_FASTOPEN_CONNECT is supported and configured). If data is written care must be taken to update the reader offset.
initialData
)

Implements abstract io.netty5.channel.AbstractChannel.doConnect.

Connect to remote peer.
protected void
doDisconnect()

Implements abstract io.netty5.channel.AbstractChannel.doDisconnect.

Disconnect this Channel from its remote peer
protected boolean
doFinishConnect(SocketAddress
the remote address of the peer.
requestedRemoteAddress
)

Implements abstract io.netty5.channel.AbstractChannel.doFinishConnect.

Finish a connect request.
protected void
doRead(boolean
true if a read was already pending when read() was called.
wasReadPendingAlready
)

Implements abstract io.netty5.channel.AbstractChannel.doRead.

Schedule a read operation.
protected boolean
doReadNow(AbstractChannel<Channel, SocketAddress, SocketAddress>.ReadSink
the ReadSink that should be called with messages that are read from the transport to propagate these.
readSink
)

Implements abstract io.netty5.channel.AbstractChannel.doReadNow.

Try to read a message from the transport and dispatch it via ReadSink#processRead(int, int, Object).
protected void
doShutdown(ChannelShutdownDirection
the direction to shut down.
direction
)

Implements abstract io.netty5.channel.AbstractChannel.doShutdown.

Shutdown one direction of the Channel.
protected void
doWriteNow(AbstractChannel<Channel, SocketAddress, SocketAddress>.WriteSink
the WriteSink that must be completed with the write progress. WriteSink#complete(long, long, int, boolean) or WriteSink#complete(long, Throwable, boolean) must be called exactly once before this method returns non-exceptional.
writeSink
)

Implements abstract io.netty5.channel.AbstractChannel.doWriteNow.

Called in a loop when writes should be performed until this method returns false or there are no more messages to write.
private EmbeddedEventLoop
protected final void
ensureOpen()

Ensure the Channel is open and if not throw an exception.

public boolean

Returns:

bufferReadable returns true if any of the used buffers has something left to read
finish
()

Mark this Channel as finished.

private boolean

Returns:

bufferReadable returns true if any of the used buffers has something left to read
finish
(boolean
if true all pending message in the inbound and outbound buffer are released.
releaseAll
)

Mark this Channel as finished.

public boolean

Returns:

bufferReadable returns true if any of the used buffers has something left to read
finishAndReleaseAll
()

Mark this Channel as finished and release all pending message in the inbound and outbound buffer.

private void
finishPendingTasks(boolean cancel)

public EmbeddedChannel
flushInbound()

Flushes the inbound of this Channel.

private void
flushInbound(boolean recordException)

public EmbeddedChannel
flushOutbound()

Flushes the outbound of this Channel.

private void
public void
freezeTime()

Freeze the clock of this channel's event loop.

protected void
handleInboundMessage(Object msg)

Called for each inbound message.

protected void
handleOutboundMessage(Object msg)

Called for each outbound message.

public boolean

Returns:

true if there are any pending tasks, false otherwise.
hasPendingTasks
()

Check whether this channel has any pending tasks that would be executed by a call to runPendingTasks().

public Queue<Object>
inboundMessages()

Returns the Queue which holds all the Objects that were received by this Channel.

public boolean
isActive()

Implements io.netty5.channel.Channel.isActive.

Return true if the Channel is active and so connected.
private static boolean
public boolean
isOpen()

Implements io.netty5.channel.Channel.isOpen.

Returns true if the Channel is open and may get active later
public boolean
isShutdown(ChannelShutdownDirection direction)

Implements io.netty5.channel.Channel.isShutdown.

Returns true if the ChannelShutdownDirection of the Channel was shutdown before.
protected SocketAddress
localAddress0()

Implements abstract io.netty5.channel.AbstractChannel.localAddress0.

Returns the SocketAddress which is bound locally.
protected final DefaultChannelPipeline
public Queue<Object>
outboundMessages()

Returns the Queue which holds all the Objects that were written by this Channel.

private static Object
poll(Queue<Object> queue)

public <T> T
readInbound()

Return received data from this Channel

public <T> T
readOutbound()

Read data from the outbound.

private void
private void
public Future<Void>
register()

Overrides default io.netty5.channel.Channel.register.

Request to register on the EventExecutor for I/O processing.
private static boolean
public boolean
releaseInbound()

Release all buffered inbound messages and return true if any were in the inbound buffer, false otherwise.

public boolean
releaseOutbound()

Release all buffered outbound messages and return true if any were in the outbound buffer, false otherwise.

protected SocketAddress
remoteAddress0()

Implements abstract io.netty5.channel.AbstractChannel.remoteAddress0.

Return the SocketAddress which the Channel is connected to.
public void
runPendingTasks()

Run all tasks (which also includes scheduled tasks) that are pending in the EventLoop for this Channel

public long
runScheduledPendingTasks()

Run all pending scheduled tasks in the EventLoop for this Channel and return the nanoseconds when the next scheduled task is ready to run.

pack-priv void
private void
setup(boolean register, final ChannelHandler... handlers)

public void
unfreezeTime()

Unfreeze an event loop that was frozen.

public boolean

Returns:

true if the write operation did add something to the inbound buffer
writeInbound
(Object...
the messages to be written
msgs
)

Write messages to the inbound of this Channel.

public Future<Void>
writeOneInbound(Object msg)

Writes one message to the inbound of this Channel and does not flush it.

public Future<Void>
writeOneOutbound(Object msg)

Writes one message to the outbound of this Channel and does not flush it.

public boolean

Returns:

bufferReadable returns true if the write operation did add something to the outbound buffer
writeOutbound
(Object...
the messages to be written
msgs
)

Write messages to the outbound of this Channel.

Inherited from io.netty5.channel.AbstractChannel:
bufferAllocatorcacheAddressescloseFuturecloseTransportcompareTodoClearScheduledReadequalsexecutorfilterOutboundMessagefinishConnectgetExtendedOptiongetOptionhashCodeidisConnectPendingisExtendedOptionSupportedisOptionSupportedisReadPendingisRegisteredisSupportingDisconnectisWriteFlushedScheduledlocalAddressnewSupportedIdentityOptionsSetparentpipelineprepareToClosereadBufferAllocatorreadHandlereadIfIsAutoReadreadLoopCompletereadNowremoteAddresssetExtendedOptionsetOptionshutdownReadSidetoStringvalidateEventLoopGroupvalidateFileRegionwritableByteswriteFlushedwriteFlushedNowwriteHandlewriteLoopComplete