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

public Class EmbeddedChannel

extends AbstractChannel
Class Inheritance
Imports
java.net.SocketAddress, java.nio.channels.ClosedChannelException, java.util.ArrayDeque, .Queue, java.util.concurrent.TimeUnit, io.netty.channel.AbstractChannel, .Channel, .ChannelConfig, .ChannelFuture, .ChannelFutureListener, .ChannelHandler, .ChannelHandlerContext, .ChannelId, .ChannelInitializer, .ChannelMetadata, .ChannelOutboundBuffer, .ChannelPipeline, .ChannelPromise, .DefaultChannelConfig, .DefaultChannelPipeline, .EventLoop, .RecvByteBufAllocator, io.netty.util.ReferenceCountUtil, io.netty.util.internal.ObjectUtil, .PlatformDependent, .RecyclableArrayList, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory

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 class
private static enum

Field Summary

Modifier and TypeField and Description
private final ChannelConfig
private static final ChannelHandler[]
private Queue<Object>
private Throwable
private static final SocketAddress
private static final InternalLogger
private final EmbeddedEventLoop
private final ChannelMetadata
private static final ChannelMetadata
private static final ChannelMetadata
private Queue<Object>
private final ChannelFutureListener
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(), true otherwise.
hasDisconnect
,
ChannelHandler...
the ChannelHandlers which will be added to 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(), true otherwise.
hasDisconnect
,
ChannelHandler...
the ChannelHandlers which will be added to 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 added to 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(), true otherwise.
hasDisconnect
,
ChannelHandler...
the ChannelHandlers which will be added to 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(), true otherwise.
hasDisconnect
,
ChannelHandler...
the ChannelHandlers which will be added to 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(), true otherwise.
hasDisconnect
,
final ChannelHandler...
the ChannelHandlers which will be added to 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(), true otherwise.
hasDisconnect
,
final ChannelConfig
the ChannelConfig which will be returned by config().
config
,
final ChannelHandler...
the ChannelHandlers which will be added to 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.

private ChannelFuture
checkException(ChannelPromise promise)

Checks for the presence of an Exception.

public void
checkException()

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

private boolean
checkOpen(boolean recordException)

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

public final ChannelFuture
close()

Overrides io.netty.channel.AbstractChannel.close.

Implements io.netty.channel.ChannelOutboundInvoker.close.

Request to close the Channel and notify the ChannelFuture once the operation completes, either because the operation was successful or because of an error.
public final ChannelFuture
close(ChannelPromise promise)

Overrides io.netty.channel.AbstractChannel.close.

Implements io.netty.channel.ChannelOutboundInvoker.close.

Request to close the Channel and notify the ChannelFuture once the operation completes, either because the operation was successful or because of an error.
public ChannelConfig
config()

Implements io.netty.channel.Channel.config.

Returns the configuration of this channel.
public final ChannelFuture
disconnect()

Overrides io.netty.channel.AbstractChannel.disconnect.

Implements io.netty.channel.ChannelOutboundInvoker.disconnect.

Request to disconnect from the remote peer and notify the ChannelFuture once the operation completes, either because the operation was successful or because of an error.
public final ChannelFuture
disconnect(ChannelPromise promise)

Overrides io.netty.channel.AbstractChannel.disconnect.

Implements io.netty.channel.ChannelOutboundInvoker.disconnect.

Request to disconnect 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
doBeginRead()

Implements abstract io.netty.channel.AbstractChannel.doBeginRead.

Schedule a read operation.
protected void
doBind(SocketAddress localAddress)

Implements abstract io.netty.channel.AbstractChannel.doBind.

Bind the Channel to the SocketAddress
protected void
protected void
doDisconnect()

Implements abstract io.netty.channel.AbstractChannel.doDisconnect.

Disconnect this Channel from its remote peer
protected void
doRegister()

Overrides io.netty.channel.AbstractChannel.doRegister.

Is called after the Channel is registered with its EventLoop as part of the register process.
protected void
doWrite(ChannelOutboundBuffer in)

Implements abstract io.netty.channel.AbstractChannel.doWrite.

Flush the content of the given buffer to the remote peer.
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 ChannelFuture
flushInbound(boolean recordException, ChannelPromise promise)

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.netty.channel.Channel.isActive.

Return true if the Channel is active and so connected.
protected boolean
isCompatible(EventLoop loop)

Implements abstract io.netty.channel.AbstractChannel.isCompatible.

Return true if the given EventLoop is compatible with this instance.
private static boolean
public boolean
isOpen()

Implements io.netty.channel.Channel.isOpen.

Returns true if the Channel is open and may get active later
public Queue<Object>
public Queue<Object>
protected SocketAddress
localAddress0()

Implements abstract io.netty.channel.AbstractChannel.localAddress0.

Returns the SocketAddress which is bound locally.
private static ChannelMetadata
metadata(boolean hasDisconnect)

public ChannelMetadata
metadata()

Implements io.netty.channel.Channel.metadata.

Return the ChannelMetadata of the Channel which describe the nature of the Channel.
protected final DefaultChannelPipeline
protected AbstractChannel.AbstractUnsafe
newUnsafe()

Implements abstract io.netty.channel.AbstractChannel.newUnsafe.

Create a new AbstractUnsafe instance which will be used for the life-time of the Channel
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 void
register()

Register this Channel on its EventLoop.

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

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

public void
unfreezeTime()

Unfreeze an event loop that was frozen.

public Channel.Unsafe
unsafe()

Overrides io.netty.channel.AbstractChannel.unsafe.

Implements io.netty.channel.Channel.unsafe.

Returns an internal-use-only object that provides unsafe operations.
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 ChannelFuture
writeOneInbound(Object msg)

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

public ChannelFuture
writeOneInbound(Object msg, ChannelPromise promise)

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

public ChannelFuture
writeOneOutbound(Object msg)

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

public ChannelFuture
writeOneOutbound(Object msg, ChannelPromise promise)

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.netty.channel.AbstractChannel:
allocbindbindbytesBeforeUnwritablebytesBeforeWritablecloseFuturecompareToconnectconnectconnectconnectderegisterderegisterdoDeregisterdoShutdownOutputequalseventLoopfilterOutboundMessageflushhashCodeidinvalidateLocalAddressinvalidateRemoteAddressisRegisteredisWritablelocalAddressmaxMessagesPerWritenewFailedFuturenewIdnewProgressivePromisenewPromisenewSucceededFutureparentpipelinereadremoteAddresstoStringvalidateFileRegionvoidPromisewritewritewriteAndFlushwriteAndFlush