Class EmbeddedChannel
- java.lang.Object
-
- io.netty.util.DefaultAttributeMap
-
- io.netty.channel.AbstractChannel
-
- io.netty.channel.embedded.EmbeddedChannel
-
- All Implemented Interfaces:
Channel,ChannelOutboundInvoker,AttributeMap,java.lang.Comparable<Channel>
public class EmbeddedChannel extends AbstractChannel
Base class forChannelimplementations that are used in an embedded fashion.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEmbeddedChannel.Builder-
Nested classes/interfaces inherited from class io.netty.channel.AbstractChannel
AbstractChannel.AbstractUnsafe
-
Nested classes/interfaces inherited from interface io.netty.channel.Channel
Channel.Unsafe
-
-
Constructor Summary
Constructors Modifier Constructor Description EmbeddedChannel()Create 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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadvanceTimeBy(long duration, java.util.concurrent.TimeUnit unit)Advance the clock of the event loop of this channel by the given duration.ChannelFuturebind(java.net.SocketAddress localAddress)Request to bind to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.ChannelFuturebind(java.net.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()voidcheckException()Check if there was anyThrowablereceived and if so rethrow it.ChannelFutureclose()Request to close theChanneland notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.ChannelFutureclose(ChannelPromise promise)Request to close theChanneland notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.ChannelConfigconfig()Returns the configuration of this channel.ChannelFutureconnect(java.net.SocketAddress remoteAddress)Request to connect to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.ChannelFutureconnect(java.net.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.ChannelFutureconnect(java.net.SocketAddress remoteAddress, java.net.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.ChannelFutureconnect(java.net.SocketAddress remoteAddress, java.net.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.ChannelFuturederegister()Request to deregister from the previous assignedEventExecutorand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.ChannelFuturederegister(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.ChannelFuturedisconnect()Request to disconnect from the remote peer and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.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 voiddoBeginRead()Schedule a read operation.protected voiddoBind(java.net.SocketAddress localAddress)Bind theChannelto theSocketAddressprotected voiddoClose()Close theChannelprotected voiddoDisconnect()Disconnect thisChannelfrom its remote peerprotected voiddoRegister()protected voiddoWrite(ChannelOutboundBuffer in)Flush the content of the given buffer to the remote peer.protected voidensureOpen()Ensure theChannelis open and if not throw an exception.booleanfinish()Mark thisChannelas finished.booleanfinishAndReleaseAll()Mark thisChannelas finished and release all pending message in the inbound and outbound buffer.Channelflush()Request to flush all pending messages via this ChannelOutboundInvoker.EmbeddedChannelflushInbound()Flushes the inbound of thisChannel.EmbeddedChannelflushOutbound()Flushes the outbound of thisChannel.voidfreezeTime()Freeze the clock of this channel's event loop.protected voidhandleInboundMessage(java.lang.Object msg)Called for each inbound message.protected voidhandleOutboundMessage(java.lang.Object msg)Called for each outbound message.booleanhasPendingTasks()Check whether this channel has any pending tasks that would be executed by a call torunPendingTasks().java.util.Queue<java.lang.Object>inboundMessages()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 laterjava.util.Queue<java.lang.Object>lastInboundBuffer()Deprecated.java.util.Queue<java.lang.Object>lastOutboundBuffer()Deprecated.protected java.net.SocketAddresslocalAddress0()Returns theSocketAddresswhich is bound locally.ChannelMetadatametadata()protected DefaultChannelPipelinenewChannelPipeline()Returns a newDefaultChannelPipelineinstance.protected AbstractChannel.AbstractUnsafenewUnsafe()Create a newAbstractChannel.AbstractUnsafeinstance which will be used for the life-time of theChanneljava.util.Queue<java.lang.Object>outboundMessages()Channelread()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> TreadInbound()Return received data from thisChannel<T> TreadOutbound()Read data from the outbound.voidregister()Register thisChannelon itsEventLoop.booleanreleaseInbound()Release all buffered inbound messages and returntrueif any were in the inbound buffer,falseotherwise.booleanreleaseOutbound()Release all buffered outbound messages and returntrueif any were in the outbound buffer,falseotherwise.protected java.net.SocketAddressremoteAddress0()Return theSocketAddresswhich theChannelis connected to.voidrunPendingTasks()longrunScheduledPendingTasks()voidunfreezeTime()Unfreeze an event loop that wasfrozen.Channel.Unsafeunsafe()Returns an internal-use-only object that provides unsafe operations.ChannelFuturewrite(java.lang.Object msg)Request to write a message via thisChannelHandlerContextthrough theChannelPipeline.ChannelFuturewrite(java.lang.Object msg, ChannelPromise promise)Request to write a message via thisChannelHandlerContextthrough theChannelPipeline.ChannelFuturewriteAndFlush(java.lang.Object msg)Shortcut for callChannelOutboundInvoker.write(Object)andChannelOutboundInvoker.flush().ChannelFuturewriteAndFlush(java.lang.Object msg, ChannelPromise promise)Shortcut for callChannelOutboundInvoker.write(Object, ChannelPromise)andChannelOutboundInvoker.flush().booleanwriteInbound(java.lang.Object... msgs)Write messages to the inbound of thisChannel.ChannelFuturewriteOneInbound(java.lang.Object msg)Writes one message to the inbound of thisChanneland does not flush it.ChannelFuturewriteOneInbound(java.lang.Object msg, ChannelPromise promise)Writes one message to the inbound of thisChanneland does not flush it.ChannelFuturewriteOneOutbound(java.lang.Object msg)Writes one message to the outbound of thisChanneland does not flush it.ChannelFuturewriteOneOutbound(java.lang.Object msg, ChannelPromise promise)Writes one message to the outbound of thisChanneland does not flush it.booleanwriteOutbound(java.lang.Object... msgs)Write messages to the outbound of thisChannel.-
Methods inherited from class io.netty.channel.AbstractChannel
closeFuture, compareTo, doDeregister, doRegister, doShutdownOutput, equals, eventLoop, filterOutboundMessage, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, localAddress, maxMessagesPerWrite, newId, parent, pipeline, remoteAddress, toString, validateFileRegion, voidPromise
-
Methods inherited from class io.netty.util.DefaultAttributeMap
attr, hasAttr
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.netty.util.AttributeMap
attr, hasAttr
-
Methods inherited from interface io.netty.channel.Channel
alloc, bytesBeforeUnwritable, bytesBeforeWritable, getOption, isWritable, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, setOption
-
-
-
-
Constructor Detail
-
EmbeddedChannel
public EmbeddedChannel()
Create a new instance with anEmbeddedChannelIdand an empty pipeline.
-
EmbeddedChannel
public EmbeddedChannel(ChannelId channelId)
Create a new instance with the specified ID and an empty pipeline.- Parameters:
channelId- theChannelIdthat will be used to identify this channel
-
EmbeddedChannel
public EmbeddedChannel(ChannelHandler... handlers)
Create a new instance with the pipeline initialized with the specified handlers.- Parameters:
handlers- theChannelHandlers which will be add in theChannelPipeline
-
EmbeddedChannel
public EmbeddedChannel(boolean hasDisconnect, ChannelHandler... handlers)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
public EmbeddedChannel(boolean register, boolean hasDisconnect, ChannelHandler... handlers)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
public 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.- Parameters:
channelId- theChannelIdthat will be used to identify this channelhandlers- theChannelHandlers which will be added to theChannelPipeline
-
EmbeddedChannel
public 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.- 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
protected EmbeddedChannel(EmbeddedChannel.Builder builder)
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 Detail
-
register
public void register() throws java.lang.ExceptionRegister thisChannelon itsEventLoop.- Throws:
java.lang.Exception
-
newChannelPipeline
protected final DefaultChannelPipeline newChannelPipeline()
Description copied from class:AbstractChannelReturns a newDefaultChannelPipelineinstance.- Overrides:
newChannelPipelinein classAbstractChannel
-
metadata
public ChannelMetadata metadata()
Description copied from interface:Channel
-
config
public ChannelConfig config()
Description copied from interface:ChannelReturns the configuration of this channel.
-
isOpen
public boolean isOpen()
Description copied from interface:ChannelReturnstrueif theChannelis open and may get active later
-
isActive
public boolean isActive()
Description copied from interface:ChannelReturntrueif theChannelis active and so connected.
-
inboundMessages
public java.util.Queue<java.lang.Object> inboundMessages()
-
lastInboundBuffer
@Deprecated public java.util.Queue<java.lang.Object> lastInboundBuffer()
Deprecated.
-
outboundMessages
public java.util.Queue<java.lang.Object> outboundMessages()
-
lastOutboundBuffer
@Deprecated public java.util.Queue<java.lang.Object> 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
public boolean writeInbound(java.lang.Object... msgs)
Write messages to the inbound of thisChannel.- Parameters:
msgs- the messages to be written- Returns:
trueif the write operation did add something to the inbound buffer
-
writeOneInbound
public ChannelFuture writeOneInbound(java.lang.Object msg)
Writes one message to the inbound of thisChanneland does not flush it. This method is conceptually equivalent towrite(Object).- See Also:
writeOneOutbound(Object)
-
writeOneInbound
public ChannelFuture writeOneInbound(java.lang.Object msg, ChannelPromise promise)
Writes one message to the inbound of thisChanneland does not flush it. This method is conceptually equivalent towrite(Object, ChannelPromise).- See Also:
writeOneOutbound(Object, ChannelPromise)
-
flushInbound
public EmbeddedChannel flushInbound()
- See Also:
flushOutbound()
-
writeOutbound
public boolean writeOutbound(java.lang.Object... msgs)
Write messages to the outbound of thisChannel.- Parameters:
msgs- the messages to be written- Returns:
- bufferReadable returns
trueif the write operation did add something to the outbound buffer
-
writeOneOutbound
public ChannelFuture writeOneOutbound(java.lang.Object msg)
Writes one message to the outbound of thisChanneland does not flush it. This method is conceptually equivalent towrite(Object).- See Also:
writeOneInbound(Object)
-
writeOneOutbound
public ChannelFuture writeOneOutbound(java.lang.Object msg, ChannelPromise promise)
Writes one message to the outbound of thisChanneland does not flush it. This method is conceptually equivalent towrite(Object, ChannelPromise).- See Also:
writeOneInbound(Object, ChannelPromise)
-
flushOutbound
public EmbeddedChannel flushOutbound()
- See Also:
flushInbound()
-
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
public final ChannelFuture 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
public final ChannelFuture 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
public final ChannelFuture close(ChannelPromise promise)
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
public final ChannelFuture disconnect(ChannelPromise promise)
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
public ChannelFuture bind(java.net.SocketAddress localAddress)
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
public ChannelFuture connect(java.net.SocketAddress remoteAddress)
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
public ChannelFuture connect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress)
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
public ChannelFuture 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
public Channel flush()
Description copied from interface:ChannelOutboundInvokerRequest to flush all pending messages via this ChannelOutboundInvoker.
-
bind
public ChannelFuture bind(java.net.SocketAddress localAddress, ChannelPromise promise)
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
public ChannelFuture connect(java.net.SocketAddress remoteAddress, ChannelPromise promise)
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(java.net.SocketAddress remoteAddress, java.net.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
public ChannelFuture deregister(ChannelPromise promise)
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
public Channel 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
public ChannelFuture write(java.lang.Object msg)
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
public ChannelFuture write(java.lang.Object msg, ChannelPromise promise)
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
public ChannelFuture writeAndFlush(java.lang.Object msg)
Description copied from interface:ChannelOutboundInvokerShortcut for callChannelOutboundInvoker.write(Object)andChannelOutboundInvoker.flush().
-
writeAndFlush
public ChannelFuture writeAndFlush(java.lang.Object msg, ChannelPromise promise)
Description copied from interface:ChannelOutboundInvokerShortcut for callChannelOutboundInvoker.write(Object, ChannelPromise)andChannelOutboundInvoker.flush().
-
runPendingTasks
public void 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
public long runScheduledPendingTasks()
-
advanceTimeBy
public void advanceTimeBy(long duration, java.util.concurrent.TimeUnit unit)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
protected boolean isCompatible(EventLoop loop)
Description copied from class:AbstractChannelReturntrueif the givenEventLoopis compatible with this instance.- Specified by:
isCompatiblein classAbstractChannel
-
localAddress0
protected java.net.SocketAddress localAddress0()
Description copied from class:AbstractChannelReturns theSocketAddresswhich is bound locally.- Specified by:
localAddress0in classAbstractChannel
-
remoteAddress0
protected java.net.SocketAddress remoteAddress0()
Description copied from class:AbstractChannelReturn theSocketAddresswhich theChannelis connected to.- Specified by:
remoteAddress0in classAbstractChannel
-
doRegister
protected void doRegister() throws java.lang.ExceptionDescription copied from class:AbstractChannelIs called after theChannelis registered with itsEventLoopas part of the register process. Subclasses may override this method- Overrides:
doRegisterin classAbstractChannel- Throws:
java.lang.Exception
-
doBind
protected void doBind(java.net.SocketAddress localAddress) throws java.lang.ExceptionDescription copied from class:AbstractChannelBind theChannelto theSocketAddress- Specified by:
doBindin classAbstractChannel- Throws:
java.lang.Exception
-
doDisconnect
protected void doDisconnect() throws java.lang.ExceptionDescription copied from class:AbstractChannelDisconnect thisChannelfrom its remote peer- Specified by:
doDisconnectin classAbstractChannel- Throws:
java.lang.Exception
-
doClose
protected void doClose() throws java.lang.ExceptionDescription copied from class:AbstractChannelClose theChannel- Specified by:
doClosein classAbstractChannel- Throws:
java.lang.Exception
-
doBeginRead
protected void doBeginRead() throws java.lang.ExceptionDescription copied from class:AbstractChannelSchedule a read operation.- Specified by:
doBeginReadin classAbstractChannel- Throws:
java.lang.Exception
-
newUnsafe
protected AbstractChannel.AbstractUnsafe newUnsafe()
Description copied from class:AbstractChannelCreate a newAbstractChannel.AbstractUnsafeinstance which will be used for the life-time of theChannel- Specified by:
newUnsafein classAbstractChannel
-
unsafe
public Channel.Unsafe unsafe()
Description copied from interface:ChannelReturns an internal-use-only object that provides unsafe operations.- Specified by:
unsafein interfaceChannel- Overrides:
unsafein classAbstractChannel
-
doWrite
protected void doWrite(ChannelOutboundBuffer in) throws java.lang.Exception
Description copied from class:AbstractChannelFlush the content of the given buffer to the remote peer.- Specified by:
doWritein classAbstractChannel- Throws:
java.lang.Exception
-
handleOutboundMessage
protected void handleOutboundMessage(java.lang.Object msg)
Called for each outbound message.- See Also:
doWrite(ChannelOutboundBuffer)
-
handleInboundMessage
protected void handleInboundMessage(java.lang.Object msg)
Called for each inbound message.
-
builder
public static EmbeddedChannel.Builder builder()
-
-