Class EmbeddedChannel
- All Implemented Interfaces:
Channel, ChannelOutboundInvoker, AttributeMap, Comparable<Channel>
Channel implementations that are used in an embedded fashion.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class AbstractChannel
AbstractChannel.AbstractUnsafeNested classes/interfaces inherited from interface Channel
Channel.Unsafe -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreate a new instance with anEmbeddedChannelIdand an empty pipeline.EmbeddedChannel(boolean register, boolean hasDisconnect, ChannelHandler... handlers) Create a new instance with the pipeline initialized with the specified handlers.EmbeddedChannel(boolean hasDisconnect, ChannelHandler... handlers) Create a new instance with the pipeline initialized with the specified handlers.EmbeddedChannel(ChannelHandler... handlers) Create a new instance with the pipeline initialized with the specified handlers.EmbeddedChannel(ChannelId channelId) Create a new instance with the specified ID and an empty pipeline.EmbeddedChannel(ChannelId channelId, boolean register, boolean hasDisconnect, ChannelHandler... handlers) Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.EmbeddedChannel(ChannelId channelId, boolean hasDisconnect, ChannelConfig config, ChannelHandler... handlers) Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.EmbeddedChannel(ChannelId channelId, boolean hasDisconnect, ChannelHandler... handlers) Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.EmbeddedChannel(ChannelId channelId, ChannelHandler... handlers) Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.EmbeddedChannel(Channel parent, ChannelId channelId, boolean register, boolean hasDisconnect, ChannelHandler... handlers) Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.protectedEmbeddedChannel(EmbeddedChannel.Builder builder) Create a new instance with the configuration from the given builder. -
Method Summary
Modifier and TypeMethodDescriptionvoidadvanceTimeBy(long duration, TimeUnit unit) Advance the clock of the event loop of this channel by the given duration.bind(SocketAddress localAddress) Request to bind to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.bind(SocketAddress localAddress, ChannelPromise promise) Request to bind to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.static EmbeddedChannel.Builderbuilder()voidCheck if there was anyThrowablereceived and if so rethrow it.final ChannelFutureclose()Request to close theChanneland notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.final ChannelFutureclose(ChannelPromise promise) Request to close theChanneland notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.config()Returns the configuration of this channel.connect(SocketAddress remoteAddress) Request to connect to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.connect(SocketAddress remoteAddress, ChannelPromise promise) Request to connect to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.connect(SocketAddress remoteAddress, SocketAddress localAddress) Request to connect to the givenSocketAddresswhile bind to the localAddress and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) Request to connect to the givenSocketAddresswhile bind to the localAddress and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.Request to deregister from the previous assignedEventExecutorand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.deregister(ChannelPromise promise) Request to deregister from the previous assignedEventExecutorand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.final ChannelFutureRequest to disconnect from the remote peer and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.final ChannelFuturedisconnect(ChannelPromise promise) Request to disconnect from the remote peer and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.protected voidSchedule a read operation.protected voiddoBind(SocketAddress localAddress) Bind theChannelto theSocketAddressprotected voiddoClose()Close theChannelprotected voidDisconnect thisChannelfrom its remote peerprotected voidprotected voidFlush the content of the given buffer to the remote peer.protected final voidEnsure theChannelis open and if not throw an exception.booleanfinish()Mark thisChannelas finished.booleanMark thisChannelas finished and release all pending message in the inbound and outbound buffer.flush()Request to flush all pending messages via this ChannelOutboundInvoker.Flushes the inbound of thisChannel.Flushes the outbound of thisChannel.voidFreeze the clock of this channel's event loop.protected voidCalled for each inbound message.protected voidCalled for each outbound message.booleanCheck whether this channel has any pending tasks that would be executed by a call torunPendingTasks().booleanisActive()Returntrueif theChannelis active and so connected.protected booleanisCompatible(EventLoop loop) Returntrueif the givenEventLoopis compatible with this instance.booleanisOpen()Returnstrueif theChannelis open and may get active laterDeprecated.Deprecated.protected SocketAddressReturns theSocketAddresswhich is bound locally.metadata()protected final DefaultChannelPipelineReturns a newDefaultChannelPipelineinstance.protected AbstractChannel.AbstractUnsafeCreate a newAbstractChannel.AbstractUnsafeinstance which will be used for the life-time of theChannelread()Request to Read data from theChannelinto the first inbound buffer, triggers anChannelInboundHandler.channelRead(ChannelHandlerContext, Object)event if data was read, and triggers achannelReadCompleteevent so the handler can decide to continue reading.<T> TReturn received data from thisChannel<T> TRead data from the outbound.voidregister()Register thisChannelon itsEventLoop.booleanRelease all buffered inbound messages and returntrueif any were in the inbound buffer,falseotherwise.booleanRelease all buffered outbound messages and returntrueif any were in the outbound buffer,falseotherwise.protected SocketAddressReturn theSocketAddresswhich theChannelis connected to.voidlongvoidUnfreeze an event loop that wasfrozen.unsafe()Returns an internal-use-only object that provides unsafe operations.Request to write a message via thisChannelHandlerContextthrough theChannelPipeline.write(Object msg, ChannelPromise promise) Request to write a message via thisChannelHandlerContextthrough theChannelPipeline.writeAndFlush(Object msg) Shortcut for callChannelOutboundInvoker.write(Object)andChannelOutboundInvoker.flush().writeAndFlush(Object msg, ChannelPromise promise) Shortcut for callChannelOutboundInvoker.write(Object, ChannelPromise)andChannelOutboundInvoker.flush().booleanwriteInbound(Object... msgs) Write messages to the inbound of thisChannel.writeOneInbound(Object msg) Writes one message to the inbound of thisChanneland does not flush it.writeOneInbound(Object msg, ChannelPromise promise) Writes one message to the inbound of thisChanneland does not flush it.writeOneOutbound(Object msg) Writes one message to the outbound of thisChanneland does not flush it.writeOneOutbound(Object msg, ChannelPromise promise) Writes one message to the outbound of thisChanneland does not flush it.booleanwriteOutbound(Object... msgs) Write messages to the outbound of thisChannel.Methods inherited from class AbstractChannel
closeFuture, compareTo, doDeregister, doRegister, doShutdownOutput, equals, eventLoop, filterOutboundMessage, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, localAddress, maxMessagesPerWrite, newId, parent, pipeline, remoteAddress, toString, validateFileRegion, voidPromiseMethods inherited from class DefaultAttributeMap
attr, hasAttrMethods inherited from interface AttributeMap
attr, hasAttrMethods inherited from interface Channel
alloc, bytesBeforeUnwritable, bytesBeforeWritable, getOption, isWritable, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, setOption
-
Constructor Details
-
EmbeddedChannel
public EmbeddedChannel()Create a new instance with anEmbeddedChannelIdand an empty pipeline. -
EmbeddedChannel
-
EmbeddedChannel
Create a new instance with the pipeline initialized with the specified handlers.- Parameters:
handlers- theChannelHandlers which will be add in theChannelPipeline
-
EmbeddedChannel
Create a new instance with the pipeline initialized with the specified handlers.- Parameters:
hasDisconnect-falseif thisChannelwill delegatedisconnect()toclose(),trueotherwise.handlers- theChannelHandlers which will be added to theChannelPipeline
-
EmbeddedChannel
Create a new instance with the pipeline initialized with the specified handlers.- Parameters:
register-trueif thisChannelis registered to theEventLoopin the constructor. Iffalsethe user will need to callregister().hasDisconnect-falseif thisChannelwill delegatedisconnect()toclose(),trueotherwise.handlers- theChannelHandlers which will be added to theChannelPipeline
-
EmbeddedChannel
Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.- Parameters:
channelId- theChannelIdthat will be used to identify this channelhandlers- theChannelHandlers which will be added to theChannelPipeline
-
EmbeddedChannel
Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.- Parameters:
channelId- theChannelIdthat will be used to identify this channelhasDisconnect-falseif thisChannelwill delegatedisconnect()toclose(),trueotherwise.handlers- theChannelHandlers which will be added to theChannelPipeline
-
EmbeddedChannel
public EmbeddedChannel(ChannelId channelId, boolean register, boolean hasDisconnect, ChannelHandler... handlers) Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.- Parameters:
channelId- theChannelIdthat will be used to identify this channelregister-trueif thisChannelis registered to theEventLoopin the constructor. Iffalsethe user will need to callregister().hasDisconnect-falseif thisChannelwill delegatedisconnect()toclose(),trueotherwise.handlers- theChannelHandlers which will be added to theChannelPipeline
-
EmbeddedChannel
public EmbeddedChannel(Channel parent, ChannelId channelId, boolean register, boolean hasDisconnect, ChannelHandler... handlers) Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.- Parameters:
parent- the parentChannelof thisEmbeddedChannel.channelId- theChannelIdthat will be used to identify this channelregister-trueif thisChannelis registered to theEventLoopin the constructor. Iffalsethe user will need to callregister().hasDisconnect-falseif thisChannelwill delegatedisconnect()toclose(),trueotherwise.handlers- theChannelHandlers which will be added to theChannelPipeline
-
EmbeddedChannel
public EmbeddedChannel(ChannelId channelId, boolean hasDisconnect, ChannelConfig config, ChannelHandler... handlers) Create a new instance with the channel ID set to the given ID and the pipeline initialized with the specified handlers.- Parameters:
channelId- theChannelIdthat will be used to identify this channelhasDisconnect-falseif thisChannelwill delegatedisconnect()toclose(),trueotherwise.config- theChannelConfigwhich will be returned byconfig().handlers- theChannelHandlers which will be added to theChannelPipeline
-
EmbeddedChannel
Create a new instance with the configuration from the given builder. This method isprotectedfor use by subclasses; Otherwise, please useEmbeddedChannel.Builder.build().- Parameters:
builder- The builder
-
-
Method Details
-
register
-
newChannelPipeline
Description copied from class:AbstractChannelReturns a newDefaultChannelPipelineinstance.- Overrides:
newChannelPipelinein classAbstractChannel
-
metadata
Description copied from interface:Channel -
config
Description copied from interface:ChannelReturns the configuration of this channel. -
isOpen
-
isActive
-
inboundMessages
-
lastInboundBuffer
Deprecated. -
outboundMessages
-
lastOutboundBuffer
Deprecated. -
readInbound
public <T> T readInbound()Return received data from thisChannel -
readOutbound
public <T> T readOutbound()Read data from the outbound. This may returnnullif nothing is readable. -
writeInbound
-
writeOneInbound
Writes one message to the inbound of thisChanneland does not flush it. This method is conceptually equivalent towrite(Object).- See Also:
-
writeOneInbound
Writes one message to the inbound of thisChanneland does not flush it. This method is conceptually equivalent towrite(Object, ChannelPromise).- See Also:
-
flushInbound
- See Also:
-
writeOutbound
-
writeOneOutbound
Writes one message to the outbound of thisChanneland does not flush it. This method is conceptually equivalent towrite(Object).- See Also:
-
writeOneOutbound
Writes one message to the outbound of thisChanneland does not flush it. This method is conceptually equivalent towrite(Object, ChannelPromise).- See Also:
-
flushOutbound
- See Also:
-
finish
public boolean finish()Mark thisChannelas finished. Any further try to write data to it will fail.- Returns:
- bufferReadable returns
trueif any of the used buffers has something left to read
-
finishAndReleaseAll
public boolean finishAndReleaseAll()Mark thisChannelas finished and release all pending message in the inbound and outbound buffer. Any further try to write data to it will fail.- Returns:
- bufferReadable returns
trueif any of the used buffers has something left to read
-
releaseInbound
public boolean releaseInbound()Release all buffered inbound messages and returntrueif any were in the inbound buffer,falseotherwise. -
releaseOutbound
public boolean releaseOutbound()Release all buffered outbound messages and returntrueif any were in the outbound buffer,falseotherwise. -
close
Description copied from interface:ChannelOutboundInvokerRequest to close theChanneland notify theChannelFutureonce 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
ChannelOutboundHandler.close(ChannelHandlerContext, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
disconnect
Description copied from interface:ChannelOutboundInvokerRequest to disconnect from the remote peer and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.This will result in having the
ChannelOutboundHandler.disconnect(ChannelHandlerContext, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
close
Description copied from interface:ChannelOutboundInvokerRequest to close theChanneland notify theChannelFutureonce 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. The givenChannelPromisewill be notified.This will result in having the
ChannelOutboundHandler.close(ChannelHandlerContext, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
disconnect
Description copied from interface:ChannelOutboundInvokerRequest to disconnect from the remote peer and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error. The givenChannelPromisewill be notified.This will result in having the
ChannelOutboundHandler.disconnect(ChannelHandlerContext, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
bind
Description copied from interface:ChannelOutboundInvokerRequest to bind to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.This will result in having the
ChannelOutboundHandler.bind(ChannelHandlerContext, SocketAddress, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
connect
Description copied from interface:ChannelOutboundInvokerRequest to connect to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.If the connection fails because of a connection timeout, the
ChannelFuturewill get failed with aConnectTimeoutException. If it fails because of connection refused aConnectExceptionwill be used.This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
connect
Description copied from interface:ChannelOutboundInvokerRequest to connect to the givenSocketAddresswhile bind to the localAddress and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
deregister
Description copied from interface:ChannelOutboundInvokerRequest to deregister from the previous assignedEventExecutorand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.This will result in having the
ChannelOutboundHandler.deregister(ChannelHandlerContext, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
flush
Description copied from interface:ChannelOutboundInvokerRequest to flush all pending messages via this ChannelOutboundInvoker. -
bind
Description copied from interface:ChannelOutboundInvokerRequest to bind to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error. The givenChannelPromisewill be notified.This will result in having the
ChannelOutboundHandler.bind(ChannelHandlerContext, SocketAddress, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
connect
Description copied from interface:ChannelOutboundInvokerRequest to connect to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error. The givenChannelFuturewill be notified.If the connection fails because of a connection timeout, the
ChannelFuturewill get failed with aConnectTimeoutException. If it fails because of connection refused aConnectExceptionwill be used.This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
connect
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) Description copied from interface:ChannelOutboundInvokerRequest to connect to the givenSocketAddresswhile bind to the localAddress and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error. The givenChannelPromisewill be notified and also returned.This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
deregister
Description copied from interface:ChannelOutboundInvokerRequest to deregister from the previous assignedEventExecutorand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error. The givenChannelPromisewill be notified.This will result in having the
ChannelOutboundHandler.deregister(ChannelHandlerContext, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
read
Description copied from interface:ChannelOutboundInvokerRequest to Read data from theChannelinto the first inbound buffer, triggers anChannelInboundHandler.channelRead(ChannelHandlerContext, Object)event if data was read, and triggers achannelReadCompleteevent 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
ChannelOutboundHandler.read(ChannelHandlerContext)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel. -
write
Description copied from interface:ChannelOutboundInvokerRequest to write a message via thisChannelHandlerContextthrough theChannelPipeline. This method will not request to actual flush, so be sure to callChannelOutboundInvoker.flush()once you want to request to flush all pending data to the actual transport. -
write
Description copied from interface:ChannelOutboundInvokerRequest to write a message via thisChannelHandlerContextthrough theChannelPipeline. This method will not request to actual flush, so be sure to callChannelOutboundInvoker.flush()once you want to request to flush all pending data to the actual transport. -
writeAndFlush
Description copied from interface:ChannelOutboundInvokerShortcut for callChannelOutboundInvoker.write(Object)andChannelOutboundInvoker.flush(). -
writeAndFlush
Description copied from interface:ChannelOutboundInvokerShortcut for callChannelOutboundInvoker.write(Object, ChannelPromise)andChannelOutboundInvoker.flush(). -
runPendingTasks
-
hasPendingTasks
public boolean hasPendingTasks()Check whether this channel has any pending tasks that would be executed by a call torunPendingTasks(). This includes normal tasks, and scheduled tasks where the deadline has expired. If this method returnsfalse, a call torunPendingTasks()would do nothing.- Returns:
trueif there are any pending tasks,falseotherwise.
-
runScheduledPendingTasks
-
advanceTimeBy
Advance the clock of the event loop of this channel by the given duration. Any scheduled tasks will execute sooner by the given time (butrunScheduledPendingTasks()still needs to be called). -
freezeTime
public void freezeTime()Freeze the clock of this channel's event loop. Any scheduled tasks that are not already due will not run on futurerunScheduledPendingTasks()calls. While the event loop is frozen, it is still possible toadvance timemanually so that scheduled tasks execute. -
unfreezeTime
public void unfreezeTime()Unfreeze an event loop that wasfrozen. Time will continue at the point wherefreezeTime()stopped it: if a task was scheduled ten minutes in the future andfreezeTime()was called, it will run ten minutes after this method is called again (assuming noadvanceTimeBy(long, TimeUnit)calls, and assuming pending scheduled tasks are run at that time usingrunScheduledPendingTasks()). -
checkException
public void checkException()Check if there was anyThrowablereceived and if so rethrow it. -
ensureOpen
protected final void ensureOpen()Ensure theChannelis open and if not throw an exception. -
isCompatible
Description copied from class:AbstractChannelReturntrueif the givenEventLoopis compatible with this instance.- Specified by:
isCompatiblein classAbstractChannel
-
localAddress0
Description copied from class:AbstractChannelReturns theSocketAddresswhich is bound locally.- Specified by:
localAddress0in classAbstractChannel
-
remoteAddress0
Description copied from class:AbstractChannelReturn theSocketAddresswhich theChannelis connected to.- Specified by:
remoteAddress0in classAbstractChannel
-
doRegister
Description copied from class:AbstractChannelIs called after theChannelis registered with itsEventLoopas part of the register process. Subclasses may override this method- Overrides:
doRegisterin classAbstractChannel- Throws:
Exception
-
doBind
Description copied from class:AbstractChannelBind theChannelto theSocketAddress- Specified by:
doBindin classAbstractChannel- Throws:
Exception
-
doDisconnect
Description copied from class:AbstractChannelDisconnect thisChannelfrom its remote peer- Specified by:
doDisconnectin classAbstractChannel- Throws:
Exception
-
doClose
Description copied from class:AbstractChannelClose theChannel- Specified by:
doClosein classAbstractChannel- Throws:
Exception
-
doBeginRead
Description copied from class:AbstractChannelSchedule a read operation.- Specified by:
doBeginReadin classAbstractChannel- Throws:
Exception
-
newUnsafe
Description copied from class:AbstractChannelCreate a newAbstractChannel.AbstractUnsafeinstance which will be used for the life-time of theChannel- Specified by:
newUnsafein classAbstractChannel
-
unsafe
Description copied from interface:ChannelReturns an internal-use-only object that provides unsafe operations.- Specified by:
unsafein interfaceChannel- Overrides:
unsafein classAbstractChannel
-
doWrite
Description copied from class:AbstractChannelFlush the content of the given buffer to the remote peer.- Specified by:
doWritein classAbstractChannel- Throws:
Exception
-
handleOutboundMessage
-
handleInboundMessage
Called for each inbound message. -
builder
-
inboundMessages()