public class EmbeddedChannel extends AbstractChannel
Channel implementations that are used in an embedded fashion.AbstractChannel.AbstractUnsafeChannel.Unsafe| 构造器和说明 |
|---|
EmbeddedChannel()
Create a new instance with an
EmbeddedChannelId 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(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.
|
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.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
advanceTimeBy(long duration,
java.util.concurrent.TimeUnit unit)
Advance the clock of the event loop of this channel by the given duration.
|
void |
checkException()
Check if there was any
Throwable received and if so rethrow it. |
ChannelFuture |
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. |
ChannelFuture |
close(ChannelPromise promise)
Request to close the
Channel and notify the ChannelFuture once the operation completes,
either because the operation was successful or because of
an error. |
ChannelConfig |
config()
Returns the configuration of this channel.
|
ChannelFuture |
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. |
ChannelFuture |
disconnect(ChannelPromise promise)
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()
Schedule a read operation.
|
protected void |
doBind(java.net.SocketAddress localAddress)
Bind the
Channel to the SocketAddress |
protected void |
doClose()
Close the
Channel |
protected void |
doDisconnect()
Disconnect this
Channel from its remote peer |
protected void |
doRegister()
|
protected void |
doWrite(ChannelOutboundBuffer in)
Flush the content of the given buffer to the remote peer.
|
protected void |
ensureOpen()
Ensure the
Channel is open and if not throw an exception. |
boolean |
finish()
Mark this
Channel as finished. |
boolean |
finishAndReleaseAll()
Mark this
Channel as finished and release all pending message in the inbound and outbound buffer. |
EmbeddedChannel |
flushInbound()
Flushes the inbound of this
Channel. |
EmbeddedChannel |
flushOutbound()
Flushes the outbound of this
Channel. |
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 to
runPendingTasks(). |
java.util.Queue<java.lang.Object> |
inboundMessages()
|
boolean |
isActive()
Return
true if the Channel is active and so connected. |
protected boolean |
isCompatible(EventLoop loop)
Return
true if the given EventLoop is compatible with this instance. |
boolean |
isOpen()
Returns
true if the Channel is open and may get active later |
java.util.Queue<java.lang.Object> |
lastInboundBuffer()
已过时。
|
java.util.Queue<java.lang.Object> |
lastOutboundBuffer()
已过时。
|
protected java.net.SocketAddress |
localAddress0()
Returns the
SocketAddress which is bound locally. |
ChannelMetadata |
metadata()
|
protected DefaultChannelPipeline |
newChannelPipeline()
Returns a new
DefaultChannelPipeline instance. |
protected AbstractChannel.AbstractUnsafe |
newUnsafe()
Create a new
AbstractChannel.AbstractUnsafe instance which will be used for the life-time of the Channel |
java.util.Queue<java.lang.Object> |
outboundMessages()
|
<T> T |
readInbound()
Return received data from this
Channel |
<T> T |
readOutbound()
Read data from the outbound.
|
void |
register()
Register this
Channel on its EventLoop. |
boolean |
releaseInbound()
Release all buffered inbound messages and return
true if any were in the inbound buffer, false
otherwise. |
boolean |
releaseOutbound()
Release all buffered outbound messages and return
true if any were in the outbound buffer, false
otherwise. |
protected java.net.SocketAddress |
remoteAddress0()
Return the
SocketAddress which the Channel is connected to. |
void |
runPendingTasks()
|
long |
runScheduledPendingTasks()
|
void |
unfreezeTime()
Unfreeze an event loop that was
frozen. |
Channel.Unsafe |
unsafe()
Returns an internal-use-only object that provides unsafe operations.
|
boolean |
writeInbound(java.lang.Object... msgs)
Write messages to the inbound of this
Channel. |
ChannelFuture |
writeOneInbound(java.lang.Object msg)
Writes one message to the inbound of this
Channel and does not flush it. |
ChannelFuture |
writeOneInbound(java.lang.Object msg,
ChannelPromise promise)
Writes one message to the inbound of this
Channel and does not flush it. |
ChannelFuture |
writeOneOutbound(java.lang.Object msg)
Writes one message to the outbound of this
Channel and does not flush it. |
ChannelFuture |
writeOneOutbound(java.lang.Object msg,
ChannelPromise promise)
Writes one message to the outbound of this
Channel and does not flush it. |
boolean |
writeOutbound(java.lang.Object... msgs)
Write messages to the outbound of this
Channel. |
alloc, bind, bind, bytesBeforeUnwritable, bytesBeforeWritable, closeFuture, compareTo, connect, connect, connect, connect, deregister, deregister, doDeregister, doShutdownOutput, equals, eventLoop, filterOutboundMessage, flush, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, isWritable, localAddress, maxMessagesPerWrite, newFailedFuture, newId, newProgressivePromise, newPromise, newSucceededFuture, parent, pipeline, read, remoteAddress, toString, validateFileRegion, voidPromise, write, write, writeAndFlush, writeAndFlushattr, hasAttrattr, hasAttrpublic EmbeddedChannel()
EmbeddedChannelId and an empty pipeline.public EmbeddedChannel(ChannelId channelId)
channelId - the ChannelId that will be used to identify this channelpublic EmbeddedChannel(ChannelHandler... handlers)
handlers - the ChannelHandlers which will be add in the ChannelPipelinepublic EmbeddedChannel(boolean hasDisconnect,
ChannelHandler... handlers)
hasDisconnect - false if this Channel will delegate disconnect()
to close(), true otherwise.handlers - the ChannelHandlers which will be added to the ChannelPipelinepublic EmbeddedChannel(boolean register,
boolean hasDisconnect,
ChannelHandler... handlers)
register - true if this Channel is registered to the EventLoop in the
constructor. If false the user will need to call register().hasDisconnect - false if this Channel will delegate disconnect()
to close(), true otherwise.handlers - the ChannelHandlers which will be added to the ChannelPipelinepublic EmbeddedChannel(ChannelId channelId, ChannelHandler... handlers)
channelId - the ChannelId that will be used to identify this channelhandlers - the ChannelHandlers which will be added to the ChannelPipelinepublic EmbeddedChannel(ChannelId channelId, boolean hasDisconnect, ChannelHandler... handlers)
channelId - the ChannelId that will be used to identify this channelhasDisconnect - false if this Channel will delegate disconnect()
to close(), true otherwise.handlers - the ChannelHandlers which will be added to the ChannelPipelinepublic EmbeddedChannel(ChannelId channelId, boolean register, boolean hasDisconnect, ChannelHandler... handlers)
channelId - the ChannelId that will be used to identify this channelregister - true if this Channel is registered to the EventLoop in the
constructor. If false the user will need to call register().hasDisconnect - false if this Channel will delegate disconnect()
to close(), true otherwise.handlers - the ChannelHandlers which will be added to the ChannelPipelinepublic EmbeddedChannel(Channel parent, ChannelId channelId, boolean register, boolean hasDisconnect, ChannelHandler... handlers)
parent - the parent Channel of this EmbeddedChannel.channelId - the ChannelId that will be used to identify this channelregister - true if this Channel is registered to the EventLoop in the
constructor. If false the user will need to call register().hasDisconnect - false if this Channel will delegate disconnect()
to close(), true otherwise.handlers - the ChannelHandlers which will be added to the ChannelPipelinepublic EmbeddedChannel(ChannelId channelId, boolean hasDisconnect, ChannelConfig config, ChannelHandler... handlers)
channelId - the ChannelId that will be used to identify this channelhasDisconnect - false if this Channel will delegate disconnect()
to close(), true otherwise.config - the ChannelConfig which will be returned by config().handlers - the ChannelHandlers which will be added to the ChannelPipelinepublic void register()
throws java.lang.Exception
Channel on its EventLoop.java.lang.Exceptionprotected final DefaultChannelPipeline newChannelPipeline()
AbstractChannelDefaultChannelPipeline instance.newChannelPipeline 在类中 AbstractChannelpublic ChannelMetadata metadata()
Channelpublic ChannelConfig config()
Channelpublic boolean isOpen()
Channeltrue if the Channel is open and may get active laterpublic boolean isActive()
Channeltrue if the Channel is active and so connected.public java.util.Queue<java.lang.Object> inboundMessages()
@Deprecated public java.util.Queue<java.lang.Object> lastInboundBuffer()
inboundMessages()public java.util.Queue<java.lang.Object> outboundMessages()
@Deprecated public java.util.Queue<java.lang.Object> lastOutboundBuffer()
outboundMessages()public <T> T readInbound()
Channelpublic <T> T readOutbound()
null if nothing is readable.public boolean writeInbound(java.lang.Object... msgs)
Channel.msgs - the messages to be writtentrue if the write operation did add something to the inbound bufferpublic ChannelFuture writeOneInbound(java.lang.Object msg)
Channel and does not flush it. This
method is conceptually equivalent to AbstractChannel.write(Object).writeOneOutbound(Object)public ChannelFuture writeOneInbound(java.lang.Object msg, ChannelPromise promise)
Channel and does not flush it. This
method is conceptually equivalent to AbstractChannel.write(Object, ChannelPromise).public EmbeddedChannel flushInbound()
Channel. This method is conceptually equivalent to AbstractChannel.flush().flushOutbound()public boolean writeOutbound(java.lang.Object... msgs)
Channel.msgs - the messages to be writtentrue if the write operation did add something to the outbound bufferpublic ChannelFuture writeOneOutbound(java.lang.Object msg)
Channel and does not flush it. This
method is conceptually equivalent to AbstractChannel.write(Object).writeOneInbound(Object)public ChannelFuture writeOneOutbound(java.lang.Object msg, ChannelPromise promise)
Channel and does not flush it. This
method is conceptually equivalent to AbstractChannel.write(Object, ChannelPromise).public EmbeddedChannel flushOutbound()
Channel. This method is conceptually equivalent to AbstractChannel.flush().flushInbound()public boolean finish()
Channel as finished. Any further try to write data to it will fail.true if any of the used buffers has something left to readpublic boolean finishAndReleaseAll()
Channel as finished and release all pending message in the inbound and outbound buffer.
Any further try to write data to it will fail.true if any of the used buffers has something left to readpublic boolean releaseInbound()
true if any were in the inbound buffer, false
otherwise.public boolean releaseOutbound()
true if any were in the outbound buffer, false
otherwise.public final ChannelFuture close()
ChannelOutboundInvokerChannel and notify the ChannelFuture 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 next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
close 在接口中 ChannelOutboundInvokerclose 在类中 AbstractChannelpublic final ChannelFuture disconnect()
ChannelOutboundInvokerChannelFuture 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 next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
disconnect 在接口中 ChannelOutboundInvokerdisconnect 在类中 AbstractChannelpublic final ChannelFuture close(ChannelPromise promise)
ChannelOutboundInvokerChannel and notify the ChannelFuture 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 given ChannelPromise will be notified.
This will result in having the
ChannelOutboundHandler.close(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
close 在接口中 ChannelOutboundInvokerclose 在类中 AbstractChannelpublic final ChannelFuture disconnect(ChannelPromise promise)
ChannelOutboundInvokerChannelFuture once the operation completes,
either because the operation was successful or because of an error.
The given ChannelPromise will be notified.
This will result in having the
ChannelOutboundHandler.disconnect(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
disconnect 在接口中 ChannelOutboundInvokerdisconnect 在类中 AbstractChannelpublic void runPendingTasks()
public boolean hasPendingTasks()
runPendingTasks().
This includes normal tasks, and scheduled tasks where the deadline has expired. If this method returns
false, a call to runPendingTasks() would do nothing.true if there are any pending tasks, false otherwise.public long runScheduledPendingTasks()
public void advanceTimeBy(long duration,
java.util.concurrent.TimeUnit unit)
runScheduledPendingTasks() still needs to be called).public void freezeTime()
runScheduledPendingTasks() calls. While the event loop is frozen, it is still possible to
advance time manually so that scheduled tasks execute.public void unfreezeTime()
frozen. Time will continue at the point where
freezeTime() stopped it: if a task was scheduled ten minutes in the future and freezeTime()
was called, it will run ten minutes after this method is called again (assuming no
advanceTimeBy(long, TimeUnit) calls, and assuming pending scheduled tasks are run at that time using
runScheduledPendingTasks()).public void checkException()
Throwable received and if so rethrow it.protected final void ensureOpen()
Channel is open and if not throw an exception.protected boolean isCompatible(EventLoop loop)
AbstractChanneltrue if the given EventLoop is compatible with this instance.isCompatible 在类中 AbstractChannelprotected java.net.SocketAddress localAddress0()
AbstractChannelSocketAddress which is bound locally.localAddress0 在类中 AbstractChannelprotected java.net.SocketAddress remoteAddress0()
AbstractChannelSocketAddress which the Channel is connected to.remoteAddress0 在类中 AbstractChannelprotected void doRegister()
throws java.lang.Exception
AbstractChannelChannel is registered with its EventLoop as part of the register process.
Sub-classes may override this methoddoRegister 在类中 AbstractChanneljava.lang.Exceptionprotected void doBind(java.net.SocketAddress localAddress)
throws java.lang.Exception
AbstractChannelChannel to the SocketAddressdoBind 在类中 AbstractChanneljava.lang.Exceptionprotected void doDisconnect()
throws java.lang.Exception
AbstractChannelChannel from its remote peerdoDisconnect 在类中 AbstractChanneljava.lang.Exceptionprotected void doClose()
throws java.lang.Exception
AbstractChannelChanneldoClose 在类中 AbstractChanneljava.lang.Exceptionprotected void doBeginRead()
throws java.lang.Exception
AbstractChanneldoBeginRead 在类中 AbstractChanneljava.lang.Exceptionprotected AbstractChannel.AbstractUnsafe newUnsafe()
AbstractChannelAbstractChannel.AbstractUnsafe instance which will be used for the life-time of the ChannelnewUnsafe 在类中 AbstractChannelpublic Channel.Unsafe unsafe()
Channelunsafe 在接口中 Channelunsafe 在类中 AbstractChannelprotected void doWrite(ChannelOutboundBuffer in) throws java.lang.Exception
AbstractChanneldoWrite 在类中 AbstractChanneljava.lang.Exceptionprotected void handleOutboundMessage(java.lang.Object msg)
protected void handleInboundMessage(java.lang.Object msg)