public class EmbeddedChannel extends AbstractChannel
Channel
implementations that are used in an embedded fashion.Modifier and Type | Class and Description |
---|---|
private class |
EmbeddedChannel.DefaultUnsafe |
private class |
EmbeddedChannel.EmbeddedChannelPipeline |
AbstractChannel.AbstractUnsafe
Channel.Unsafe
Modifier and Type | Field and Description |
---|---|
private ChannelConfig |
config |
private java.util.Queue<java.lang.Object> |
inboundMessages |
private java.lang.Throwable |
lastException |
private java.net.SocketAddress |
localAddress |
private static InternalLogger |
logger |
private EmbeddedEventLoop |
loop |
private ChannelMetadata |
metadata |
private static ChannelMetadata |
METADATA_DISCONNECT |
private static ChannelMetadata |
METADATA_NO_DISCONNECT |
private java.util.Queue<java.lang.Object> |
outboundMessages |
private ChannelFutureListener |
recordExceptionListener |
private java.net.SocketAddress |
remoteAddress |
private int |
state |
Constructor and Description |
---|
EmbeddedChannel(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(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
|
Modifier and Type | Method and Description |
---|---|
void |
checkException()
Check if there was any
Throwable received and if so rethrow it. |
ChannelFuture |
close()
Request to close this
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 this
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. |
private boolean |
finish(boolean releaseAll)
Mark this
Channel as finished. |
boolean |
finishAndReleaseAll()
Mark this
Channel as finished and release all pending message in the inbound and outbound buffer. |
private void |
finishPendingTasks(boolean cancel) |
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. |
private static boolean |
isNotEmpty(java.util.Queue<java.lang.Object> queue) |
boolean |
isOpen()
Returns
true if the Channel is open and may get active later |
java.util.Queue<java.lang.Object> |
lastInboundBuffer()
Deprecated.
|
java.util.Queue<java.lang.Object> |
lastOutboundBuffer()
Deprecated.
|
protected java.net.SocketAddress |
localAddress0()
Returns the
SocketAddress which is bound locally. |
ChannelMetadata |
metadata()
|
private static ChannelMetadata |
metadata(boolean hasDisconnect) |
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()
|
private static java.lang.Object |
poll(java.util.Queue<java.lang.Object> queue) |
java.lang.Object |
readInbound()
Return received data from this
Channel |
java.lang.Object |
readOutbound()
Read data from the outbound.
|
private void |
recordException(ChannelFuture future) |
private void |
recordException(java.lang.Throwable cause) |
private static boolean |
releaseAll(java.util.Queue<java.lang.Object> queue) |
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()
|
private void |
setup(ChannelHandler... handlers) |
boolean |
writeInbound(java.lang.Object... msgs)
Write messages to the inbound of this
Channel . |
boolean |
writeOutbound(java.lang.Object... msgs)
Write messages to the outbound of this
Channel . |
alloc, bind, bind, closeFuture, compareTo, connect, connect, connect, connect, deregister, deregister, doDeregister, equals, eventLoop, filterOutboundMessage, flush, hashCode, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, isWritable, localAddress, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, parent, pipeline, read, remoteAddress, toString, unsafe, voidPromise, write, write, writeAndFlush, writeAndFlush
attr
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
attr
private static final InternalLogger logger
private static final ChannelMetadata METADATA_NO_DISCONNECT
private static final ChannelMetadata METADATA_DISCONNECT
private final EmbeddedEventLoop loop
private final ChannelFutureListener recordExceptionListener
private final ChannelMetadata metadata
private final ChannelConfig config
private final java.net.SocketAddress localAddress
private final java.net.SocketAddress remoteAddress
private java.util.Queue<java.lang.Object> inboundMessages
private java.util.Queue<java.lang.Object> outboundMessages
private java.lang.Throwable lastException
private int state
public EmbeddedChannel(ChannelHandler... handlers)
handlers
- the @link ChannelHandler}s which will be add in the ChannelPipeline
public EmbeddedChannel(boolean hasDisconnect, ChannelHandler... handlers)
hasDisconnect
- false
if this Channel
will delegate disconnect()
to close()
, false
otherwise.handlers
- the ChannelHandler
s which will be add in the ChannelPipeline
public EmbeddedChannel(boolean hasDisconnect, ChannelConfig config, ChannelHandler... handlers)
hasDisconnect
- false
if this Channel
will delegate disconnect()
to close()
, false
otherwise.config
- the ChannelConfig
which will be returned by config()
.handlers
- the ChannelHandler
s which will be add in the ChannelPipeline
private static ChannelMetadata metadata(boolean hasDisconnect)
private void setup(ChannelHandler... handlers)
protected final DefaultChannelPipeline newChannelPipeline()
AbstractChannel
DefaultChannelPipeline
instance.newChannelPipeline
in class AbstractChannel
public ChannelMetadata metadata()
Channel
public ChannelConfig config()
Channel
public boolean isOpen()
Channel
true
if the Channel
is open and may get active laterpublic boolean isActive()
Channel
true
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 java.lang.Object readInbound()
Channel
public java.lang.Object 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 boolean writeOutbound(java.lang.Object... msgs)
Channel
.msgs
- the messages to be writtentrue
if the write operation did add something to the outbound bufferpublic boolean finish()
Channel
as finished. Any futher 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 futher try to write data to it will fail.true
if any of the used buffers has something left to readprivate boolean finish(boolean releaseAll)
Channel
as finished. Any futher try to write data to it will fail.releaseAll
- if true
all pending message in the inbound and outbound buffer are released.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.private static boolean releaseAll(java.util.Queue<java.lang.Object> queue)
private void finishPendingTasks(boolean cancel)
public final ChannelFuture close()
Channel
Channel
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
in interface Channel
close
in class AbstractChannel
public final ChannelFuture disconnect()
Channel
ChannelFuture
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
in interface Channel
disconnect
in class AbstractChannel
public final ChannelFuture close(ChannelPromise promise)
Channel
Channel
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
in interface Channel
close
in class AbstractChannel
public final ChannelFuture disconnect(ChannelPromise promise)
Channel
ChannelFuture
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
in interface Channel
disconnect
in class AbstractChannel
private static boolean isNotEmpty(java.util.Queue<java.lang.Object> queue)
private static java.lang.Object poll(java.util.Queue<java.lang.Object> queue)
public void runPendingTasks()
public long runScheduledPendingTasks()
private void recordException(ChannelFuture future)
private void recordException(java.lang.Throwable cause)
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)
AbstractChannel
true
if the given EventLoop
is compatible with this instance.isCompatible
in class AbstractChannel
protected java.net.SocketAddress localAddress0()
AbstractChannel
SocketAddress
which is bound locally.localAddress0
in class AbstractChannel
protected java.net.SocketAddress remoteAddress0()
AbstractChannel
SocketAddress
which the Channel
is connected to.remoteAddress0
in class AbstractChannel
protected void doRegister() throws java.lang.Exception
AbstractChannel
Channel
is registered with its EventLoop
as part of the register process.
Sub-classes may override this methoddoRegister
in class AbstractChannel
java.lang.Exception
protected void doBind(java.net.SocketAddress localAddress) throws java.lang.Exception
AbstractChannel
Channel
to the SocketAddress
doBind
in class AbstractChannel
java.lang.Exception
protected void doDisconnect() throws java.lang.Exception
AbstractChannel
Channel
from its remote peerdoDisconnect
in class AbstractChannel
java.lang.Exception
protected void doClose() throws java.lang.Exception
AbstractChannel
Channel
doClose
in class AbstractChannel
java.lang.Exception
protected void doBeginRead() throws java.lang.Exception
AbstractChannel
doBeginRead
in class AbstractChannel
java.lang.Exception
protected AbstractChannel.AbstractUnsafe newUnsafe()
AbstractChannel
AbstractChannel.AbstractUnsafe
instance which will be used for the life-time of the Channel
newUnsafe
in class AbstractChannel
protected void doWrite(ChannelOutboundBuffer in) throws java.lang.Exception
AbstractChannel
doWrite
in class AbstractChannel
java.lang.Exception