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 forChannel
implementations that are used in an embedded fashion.
-
-
Nested Class Summary
-
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 Constructor Description EmbeddedChannel()
Create a new instance with anEmbeddedChannelId
and 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
advanceTimeBy(long duration, java.util.concurrent.TimeUnit unit)
Advance the clock of the event loop of this channel by the given duration.ChannelFuture
bind(java.net.SocketAddress localAddress)
Request to bind to the givenSocketAddress
and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.ChannelFuture
bind(java.net.SocketAddress localAddress, ChannelPromise promise)
Request to bind to the givenSocketAddress
and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.void
checkException()
Check if there was anyThrowable
received and if so rethrow it.ChannelFuture
close()
Request to close theChannel
and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.ChannelFuture
close(ChannelPromise promise)
Request to close theChannel
and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.ChannelConfig
config()
Returns the configuration of this channel.ChannelFuture
connect(java.net.SocketAddress remoteAddress)
Request to connect to the givenSocketAddress
and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.ChannelFuture
connect(java.net.SocketAddress remoteAddress, ChannelPromise promise)
Request to connect to the givenSocketAddress
and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.ChannelFuture
connect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress)
Request to connect to the givenSocketAddress
while bind to the localAddress and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.ChannelFuture
connect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, ChannelPromise promise)
Request to connect to the givenSocketAddress
while bind to the localAddress and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.ChannelFuture
deregister()
Request to deregister from the previous assignedEventExecutor
and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.ChannelFuture
deregister(ChannelPromise promise)
Request to deregister from the previous assignedEventExecutor
and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.ChannelFuture
disconnect()
Request to disconnect from the remote peer and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.ChannelFuture
disconnect(ChannelPromise promise)
Request to disconnect from the remote peer and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error.protected void
doBeginRead()
Schedule a read operation.protected void
doBind(java.net.SocketAddress localAddress)
Bind theChannel
to theSocketAddress
protected void
doClose()
Close theChannel
protected void
doDisconnect()
Disconnect thisChannel
from its remote peerprotected void
doRegister()
protected void
doWrite(ChannelOutboundBuffer in)
Flush the content of the given buffer to the remote peer.protected void
ensureOpen()
Ensure theChannel
is open and if not throw an exception.boolean
finish()
Mark thisChannel
as finished.boolean
finishAndReleaseAll()
Mark thisChannel
as finished and release all pending message in the inbound and outbound buffer.Channel
flush()
Request to flush all pending messages via this ChannelOutboundInvoker.EmbeddedChannel
flushInbound()
Flushes the inbound of thisChannel
.EmbeddedChannel
flushOutbound()
Flushes the outbound of thisChannel
.void
freezeTime()
Freeze the clock of this channel's event loop.protected void
handleInboundMessage(java.lang.Object msg)
Called for each inbound message.protected void
handleOutboundMessage(java.lang.Object msg)
Called for each outbound message.boolean
hasPendingTasks()
Check whether this channel has any pending tasks that would be executed by a call torunPendingTasks()
.java.util.Queue<java.lang.Object>
inboundMessages()
boolean
isActive()
Returntrue
if theChannel
is active and so connected.protected boolean
isCompatible(EventLoop loop)
Returntrue
if the givenEventLoop
is compatible with this instance.boolean
isOpen()
Returnstrue
if theChannel
is open and may get active laterjava.util.Queue<java.lang.Object>
lastInboundBuffer()
Deprecated.java.util.Queue<java.lang.Object>
lastOutboundBuffer()
Deprecated.protected java.net.SocketAddress
localAddress0()
Returns theSocketAddress
which is bound locally.ChannelMetadata
metadata()
protected DefaultChannelPipeline
newChannelPipeline()
Returns a newDefaultChannelPipeline
instance.protected AbstractChannel.AbstractUnsafe
newUnsafe()
Create a newAbstractChannel.AbstractUnsafe
instance which will be used for the life-time of theChannel
java.util.Queue<java.lang.Object>
outboundMessages()
Channel
read()
Request to Read data from theChannel
into the first inbound buffer, triggers anChannelInboundHandler.channelRead(ChannelHandlerContext, Object)
event if data was read, and triggers achannelReadComplete
event so the handler can decide to continue reading.<T> T
readInbound()
Return received data from thisChannel
<T> T
readOutbound()
Read data from the outbound.void
register()
Register thisChannel
on itsEventLoop
.boolean
releaseInbound()
Release all buffered inbound messages and returntrue
if any were in the inbound buffer,false
otherwise.boolean
releaseOutbound()
Release all buffered outbound messages and returntrue
if any were in the outbound buffer,false
otherwise.protected java.net.SocketAddress
remoteAddress0()
Return theSocketAddress
which theChannel
is connected to.void
runPendingTasks()
long
runScheduledPendingTasks()
void
unfreezeTime()
Unfreeze an event loop that wasfrozen
.Channel.Unsafe
unsafe()
Returns an internal-use-only object that provides unsafe operations.ChannelFuture
write(java.lang.Object msg)
Request to write a message via thisChannelHandlerContext
through theChannelPipeline
.ChannelFuture
write(java.lang.Object msg, ChannelPromise promise)
Request to write a message via thisChannelHandlerContext
through theChannelPipeline
.ChannelFuture
writeAndFlush(java.lang.Object msg)
Shortcut for callChannelOutboundInvoker.write(Object)
andChannelOutboundInvoker.flush()
.ChannelFuture
writeAndFlush(java.lang.Object msg, ChannelPromise promise)
Shortcut for callChannelOutboundInvoker.write(Object, ChannelPromise)
andChannelOutboundInvoker.flush()
.boolean
writeInbound(java.lang.Object... msgs)
Write messages to the inbound of thisChannel
.ChannelFuture
writeOneInbound(java.lang.Object msg)
Writes one message to the inbound of thisChannel
and does not flush it.ChannelFuture
writeOneInbound(java.lang.Object msg, ChannelPromise promise)
Writes one message to the inbound of thisChannel
and does not flush it.ChannelFuture
writeOneOutbound(java.lang.Object msg)
Writes one message to the outbound of thisChannel
and does not flush it.ChannelFuture
writeOneOutbound(java.lang.Object msg, ChannelPromise promise)
Writes one message to the outbound of thisChannel
and does not flush it.boolean
writeOutbound(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 anEmbeddedChannelId
and an empty pipeline.
-
EmbeddedChannel
public EmbeddedChannel(ChannelId channelId)
Create a new instance with the specified ID and an empty pipeline.- Parameters:
channelId
- theChannelId
that 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
- theChannelHandler
s 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
-false
if thisChannel
will delegatedisconnect()
toclose()
,true
otherwise.handlers
- theChannelHandler
s 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
-true
if thisChannel
is registered to theEventLoop
in the constructor. Iffalse
the user will need to callregister()
.hasDisconnect
-false
if thisChannel
will delegatedisconnect()
toclose()
,true
otherwise.handlers
- theChannelHandler
s 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
- theChannelId
that will be used to identify this channelhandlers
- theChannelHandler
s 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
- theChannelId
that will be used to identify this channelhasDisconnect
-false
if thisChannel
will delegatedisconnect()
toclose()
,true
otherwise.handlers
- theChannelHandler
s 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
- theChannelId
that will be used to identify this channelregister
-true
if thisChannel
is registered to theEventLoop
in the constructor. Iffalse
the user will need to callregister()
.hasDisconnect
-false
if thisChannel
will delegatedisconnect()
toclose()
,true
otherwise.handlers
- theChannelHandler
s 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 parentChannel
of thisEmbeddedChannel
.channelId
- theChannelId
that will be used to identify this channelregister
-true
if thisChannel
is registered to theEventLoop
in the constructor. Iffalse
the user will need to callregister()
.hasDisconnect
-false
if thisChannel
will delegatedisconnect()
toclose()
,true
otherwise.handlers
- theChannelHandler
s 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
- theChannelId
that will be used to identify this channelhasDisconnect
-false
if thisChannel
will delegatedisconnect()
toclose()
,true
otherwise.config
- theChannelConfig
which will be returned byconfig()
.handlers
- theChannelHandler
s which will be added to theChannelPipeline
-
-
Method Detail
-
register
public void register() throws java.lang.Exception
Register thisChannel
on itsEventLoop
.- Throws:
java.lang.Exception
-
newChannelPipeline
protected final DefaultChannelPipeline newChannelPipeline()
Description copied from class:AbstractChannel
Returns a newDefaultChannelPipeline
instance.- Overrides:
newChannelPipeline
in classAbstractChannel
-
metadata
public ChannelMetadata metadata()
Description copied from interface:Channel
-
config
public ChannelConfig config()
Description copied from interface:Channel
Returns the configuration of this channel.
-
isOpen
public boolean isOpen()
Description copied from interface:Channel
Returnstrue
if theChannel
is open and may get active later
-
isActive
public boolean isActive()
Description copied from interface:Channel
Returntrue
if theChannel
is 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 returnnull
if 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:
true
if 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 thisChannel
and 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 thisChannel
and 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
true
if 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 thisChannel
and 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 thisChannel
and 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 thisChannel
as finished. Any further try to write data to it will fail.- Returns:
- bufferReadable returns
true
if any of the used buffers has something left to read
-
finishAndReleaseAll
public boolean finishAndReleaseAll()
Mark thisChannel
as 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
true
if any of the used buffers has something left to read
-
releaseInbound
public boolean releaseInbound()
Release all buffered inbound messages and returntrue
if any were in the inbound buffer,false
otherwise.
-
releaseOutbound
public boolean releaseOutbound()
Release all buffered outbound messages and returntrue
if any were in the outbound buffer,false
otherwise.
-
close
public final ChannelFuture close()
Description copied from interface:ChannelOutboundInvoker
Request to close theChannel
and notify theChannelFuture
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
ChannelOutboundHandler.close(ChannelHandlerContext, ChannelPromise)
method called of the nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
disconnect
public final ChannelFuture disconnect()
Description copied from interface:ChannelOutboundInvoker
Request to disconnect from the remote peer and notify theChannelFuture
once 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 nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
close
public final ChannelFuture close(ChannelPromise promise)
Description copied from interface:ChannelOutboundInvoker
Request to close theChannel
and notify theChannelFuture
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. The givenChannelPromise
will be notified.This will result in having the
ChannelOutboundHandler.close(ChannelHandlerContext, ChannelPromise)
method called of the nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
disconnect
public final ChannelFuture disconnect(ChannelPromise promise)
Description copied from interface:ChannelOutboundInvoker
Request to disconnect from the remote peer and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error. The givenChannelPromise
will be notified.This will result in having the
ChannelOutboundHandler.disconnect(ChannelHandlerContext, ChannelPromise)
method called of the nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
bind
public ChannelFuture bind(java.net.SocketAddress localAddress)
Description copied from interface:ChannelOutboundInvoker
Request to bind to the givenSocketAddress
and notify theChannelFuture
once 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 nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
connect
public ChannelFuture connect(java.net.SocketAddress remoteAddress)
Description copied from interface:ChannelOutboundInvoker
Request to connect to the givenSocketAddress
and notify theChannelFuture
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
ChannelFuture
will get failed with aConnectTimeoutException
. If it fails because of connection refused aConnectException
will be used.This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
connect
public ChannelFuture connect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress)
Description copied from interface:ChannelOutboundInvoker
Request to connect to the givenSocketAddress
while bind to the localAddress and notify theChannelFuture
once 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 nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
deregister
public ChannelFuture deregister()
Description copied from interface:ChannelOutboundInvoker
Request to deregister from the previous assignedEventExecutor
and notify theChannelFuture
once 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 nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
flush
public Channel flush()
Description copied from interface:ChannelOutboundInvoker
Request to flush all pending messages via this ChannelOutboundInvoker.
-
bind
public ChannelFuture bind(java.net.SocketAddress localAddress, ChannelPromise promise)
Description copied from interface:ChannelOutboundInvoker
Request to bind to the givenSocketAddress
and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error. The givenChannelPromise
will be notified.This will result in having the
ChannelOutboundHandler.bind(ChannelHandlerContext, SocketAddress, ChannelPromise)
method called of the nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
connect
public ChannelFuture connect(java.net.SocketAddress remoteAddress, ChannelPromise promise)
Description copied from interface:ChannelOutboundInvoker
Request to connect to the givenSocketAddress
and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error. The givenChannelFuture
will be notified.If the connection fails because of a connection timeout, the
ChannelFuture
will get failed with aConnectTimeoutException
. If it fails because of connection refused aConnectException
will be used.This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
connect
public ChannelFuture connect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, ChannelPromise promise)
Description copied from interface:ChannelOutboundInvoker
Request to connect to the givenSocketAddress
while bind to the localAddress and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error. The givenChannelPromise
will be notified and also returned.This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
deregister
public ChannelFuture deregister(ChannelPromise promise)
Description copied from interface:ChannelOutboundInvoker
Request to deregister from the previous assignedEventExecutor
and notify theChannelFuture
once the operation completes, either because the operation was successful or because of an error. The givenChannelPromise
will be notified.This will result in having the
ChannelOutboundHandler.deregister(ChannelHandlerContext, ChannelPromise)
method called of the nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
read
public Channel read()
Description copied from interface:ChannelOutboundInvoker
Request to Read data from theChannel
into the first inbound buffer, triggers anChannelInboundHandler.channelRead(ChannelHandlerContext, Object)
event if data was read, and triggers achannelReadComplete
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
ChannelOutboundHandler.read(ChannelHandlerContext)
method called of the nextChannelOutboundHandler
contained in theChannelPipeline
of theChannel
.
-
write
public ChannelFuture write(java.lang.Object msg)
Description copied from interface:ChannelOutboundInvoker
Request to write a message via thisChannelHandlerContext
through 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:ChannelOutboundInvoker
Request to write a message via thisChannelHandlerContext
through 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:ChannelOutboundInvoker
Shortcut for callChannelOutboundInvoker.write(Object)
andChannelOutboundInvoker.flush()
.
-
writeAndFlush
public ChannelFuture writeAndFlush(java.lang.Object msg, ChannelPromise promise)
Description copied from interface:ChannelOutboundInvoker
Shortcut 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:
true
if there are any pending tasks,false
otherwise.
-
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 time
manually 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 anyThrowable
received and if so rethrow it.
-
ensureOpen
protected final void ensureOpen()
Ensure theChannel
is open and if not throw an exception.
-
isCompatible
protected boolean isCompatible(EventLoop loop)
Description copied from class:AbstractChannel
Returntrue
if the givenEventLoop
is compatible with this instance.- Specified by:
isCompatible
in classAbstractChannel
-
localAddress0
protected java.net.SocketAddress localAddress0()
Description copied from class:AbstractChannel
Returns theSocketAddress
which is bound locally.- Specified by:
localAddress0
in classAbstractChannel
-
remoteAddress0
protected java.net.SocketAddress remoteAddress0()
Description copied from class:AbstractChannel
Return theSocketAddress
which theChannel
is connected to.- Specified by:
remoteAddress0
in classAbstractChannel
-
doRegister
protected void doRegister() throws java.lang.Exception
Description copied from class:AbstractChannel
Is called after theChannel
is registered with itsEventLoop
as part of the register process. Subclasses may override this method- Overrides:
doRegister
in classAbstractChannel
- Throws:
java.lang.Exception
-
doBind
protected void doBind(java.net.SocketAddress localAddress) throws java.lang.Exception
Description copied from class:AbstractChannel
Bind theChannel
to theSocketAddress
- Specified by:
doBind
in classAbstractChannel
- Throws:
java.lang.Exception
-
doDisconnect
protected void doDisconnect() throws java.lang.Exception
Description copied from class:AbstractChannel
Disconnect thisChannel
from its remote peer- Specified by:
doDisconnect
in classAbstractChannel
- Throws:
java.lang.Exception
-
doClose
protected void doClose() throws java.lang.Exception
Description copied from class:AbstractChannel
Close theChannel
- Specified by:
doClose
in classAbstractChannel
- Throws:
java.lang.Exception
-
doBeginRead
protected void doBeginRead() throws java.lang.Exception
Description copied from class:AbstractChannel
Schedule a read operation.- Specified by:
doBeginRead
in classAbstractChannel
- Throws:
java.lang.Exception
-
newUnsafe
protected AbstractChannel.AbstractUnsafe newUnsafe()
Description copied from class:AbstractChannel
Create a newAbstractChannel.AbstractUnsafe
instance which will be used for the life-time of theChannel
- Specified by:
newUnsafe
in classAbstractChannel
-
unsafe
public Channel.Unsafe unsafe()
Description copied from interface:Channel
Returns an internal-use-only object that provides unsafe operations.- Specified by:
unsafe
in interfaceChannel
- Overrides:
unsafe
in classAbstractChannel
-
doWrite
protected void doWrite(ChannelOutboundBuffer in) throws java.lang.Exception
Description copied from class:AbstractChannel
Flush the content of the given buffer to the remote peer.- Specified by:
doWrite
in 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.
-
-