public abstract class AbstractChannel extends DefaultAttributeMap implements Channel
Channel
implementation.限定符和类型 | 类和说明 |
---|---|
protected class |
AbstractChannel.AbstractUnsafe
Unsafe implementation which sub-classes must extend and use. |
Channel.Unsafe
限定符 | 构造器和说明 |
---|---|
protected |
AbstractChannel(Channel parent)
Creates a new instance.
|
protected |
AbstractChannel(Channel parent,
ChannelId id)
Creates a new instance.
|
限定符和类型 | 方法和说明 |
---|---|
ByteBufAllocator |
alloc()
Return the assigned
ByteBufAllocator which will be used to allocate ByteBuf s. |
ChannelFuture |
bind(java.net.SocketAddress localAddress)
Request to bind to the given
SocketAddress and notify the ChannelFuture 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 given
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error. |
long |
bytesBeforeUnwritable()
Get how many bytes can be written until
Channel.isWritable() returns false . |
long |
bytesBeforeWritable()
Get how many bytes must be drained from underlying buffers until
Channel.isWritable() returns true . |
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. |
ChannelFuture |
closeFuture()
Returns the
ChannelFuture which will be notified when this
channel is closed. |
int |
compareTo(Channel o) |
ChannelFuture |
connect(java.net.SocketAddress remoteAddress)
Request to connect to the given
SocketAddress and notify the ChannelFuture 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 given
SocketAddress and notify the ChannelFuture 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 given
SocketAddress while bind to the localAddress and notify the
ChannelFuture 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 given
SocketAddress while bind to the localAddress and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error. |
ChannelFuture |
deregister()
Request to deregister from the previous assigned
EventExecutor and notify the
ChannelFuture 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 assigned
EventExecutor and notify the
ChannelFuture 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 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 abstract void |
doBeginRead()
Schedule a read operation.
|
protected abstract void |
doBind(java.net.SocketAddress localAddress)
Bind the
Channel to the SocketAddress |
protected abstract void |
doClose()
Close the
Channel |
protected void |
doDeregister()
|
protected abstract void |
doDisconnect()
Disconnect this
Channel from its remote peer |
protected void |
doRegister()
|
protected void |
doShutdownOutput()
Called when conditions justify shutting down the output portion of the channel.
|
protected abstract void |
doWrite(ChannelOutboundBuffer in)
Flush the content of the given buffer to the remote peer.
|
boolean |
equals(java.lang.Object o)
Returns
true if and only if the specified object is identical
with this channel (i.e: this == o ). |
EventLoop |
eventLoop()
|
protected java.lang.Object |
filterOutboundMessage(java.lang.Object msg)
Invoked when a new message is added to a
ChannelOutboundBuffer of this AbstractChannel , so that
the Channel implementation converts the message to another. |
Channel |
flush()
Request to flush all pending messages via this ChannelOutboundInvoker.
|
int |
hashCode()
Returns the ID of this channel.
|
ChannelId |
id()
Returns the globally unique identifier of this
Channel . |
protected void |
invalidateLocalAddress()
已过时。
no use-case for this.
|
protected void |
invalidateRemoteAddress()
已过时。
no use-case for this.
|
protected abstract boolean |
isCompatible(EventLoop loop)
Return
true if the given EventLoop is compatible with this instance. |
boolean |
isRegistered()
|
boolean |
isWritable()
Returns
true if and only if the I/O thread will perform the
requested write operation immediately. |
java.net.SocketAddress |
localAddress()
Returns the local address where this channel is bound to.
|
protected abstract java.net.SocketAddress |
localAddress0()
Returns the
SocketAddress which is bound locally. |
protected int |
maxMessagesPerWrite() |
protected DefaultChannelPipeline |
newChannelPipeline()
Returns a new
DefaultChannelPipeline instance. |
ChannelFuture |
newFailedFuture(java.lang.Throwable cause)
Create a new
ChannelFuture which is marked as failed already. |
protected ChannelId |
newId()
Returns a new
DefaultChannelId instance. |
ChannelProgressivePromise |
newProgressivePromise()
Return an new
ChannelProgressivePromise |
ChannelPromise |
newPromise()
Return a new
ChannelPromise . |
ChannelFuture |
newSucceededFuture()
Create a new
ChannelFuture which is marked as succeeded already. |
protected abstract AbstractChannel.AbstractUnsafe |
newUnsafe()
Create a new
AbstractChannel.AbstractUnsafe instance which will be used for the life-time of the Channel |
Channel |
parent()
Returns the parent of this channel.
|
ChannelPipeline |
pipeline()
Return the assigned
ChannelPipeline . |
Channel |
read()
Request to Read data from the
Channel into the first inbound buffer, triggers an
ChannelInboundHandler.channelRead(ChannelHandlerContext, Object) event if data was
read, and triggers a
channelReadComplete event so the
handler can decide to continue reading. |
java.net.SocketAddress |
remoteAddress()
Returns the remote address where this channel is connected to.
|
protected abstract java.net.SocketAddress |
remoteAddress0()
Return the
SocketAddress which the Channel is connected to. |
java.lang.String |
toString()
Returns the
String representation of this channel. |
Channel.Unsafe |
unsafe()
Returns an internal-use-only object that provides unsafe operations.
|
protected void |
validateFileRegion(DefaultFileRegion region,
long position) |
ChannelPromise |
voidPromise()
Return a special ChannelPromise which can be reused for different operations.
|
ChannelFuture |
write(java.lang.Object msg)
Request to write a message via this
ChannelHandlerContext through the ChannelPipeline . |
ChannelFuture |
write(java.lang.Object msg,
ChannelPromise promise)
Request to write a message via this
ChannelHandlerContext through the ChannelPipeline . |
ChannelFuture |
writeAndFlush(java.lang.Object msg)
Shortcut for call
ChannelOutboundInvoker.write(Object) and ChannelOutboundInvoker.flush() . |
ChannelFuture |
writeAndFlush(java.lang.Object msg,
ChannelPromise promise)
Shortcut for call
ChannelOutboundInvoker.write(Object, ChannelPromise) and ChannelOutboundInvoker.flush() . |
attr, hasAttr
attr, hasAttr
protected AbstractChannel(Channel parent)
parent
- the parent of this channel. null
if there's no parent.protected final int maxMessagesPerWrite()
public final ChannelId id()
Channel
Channel
.protected ChannelId newId()
DefaultChannelId
instance. Subclasses may override this method to assign custom
ChannelId
s to Channel
s that use the AbstractChannel(Channel)
constructor.protected DefaultChannelPipeline newChannelPipeline()
DefaultChannelPipeline
instance.public boolean isWritable()
Channel
true
if and only if the I/O thread will perform the
requested write operation immediately. Any write requests made when
this method returns false
are queued until the I/O thread is
ready to process the queued write requests.
WriteBufferWaterMark
can be used to configure on which condition
the write buffer would cause this channel to change writability.isWritable
在接口中 Channel
public long bytesBeforeUnwritable()
Channel
Channel.isWritable()
returns false
.
This quantity will always be non-negative. If Channel.isWritable()
is false
then 0.
WriteBufferWaterMark
can be used to define writability settings.bytesBeforeUnwritable
在接口中 Channel
public long bytesBeforeWritable()
Channel
Channel.isWritable()
returns true
.
This quantity will always be non-negative. If Channel.isWritable()
is true
then 0.
WriteBufferWaterMark
can be used to define writability settings.bytesBeforeWritable
在接口中 Channel
public ChannelPipeline pipeline()
Channel
ChannelPipeline
.public ByteBufAllocator alloc()
Channel
ByteBufAllocator
which will be used to allocate ByteBuf
s.public java.net.SocketAddress localAddress()
Channel
SocketAddress
is supposed to be down-cast into more concrete
type such as InetSocketAddress
to retrieve the detailed
information.localAddress
在接口中 Channel
null
if this channel is not bound.@Deprecated protected void invalidateLocalAddress()
public java.net.SocketAddress remoteAddress()
Channel
SocketAddress
is supposed to be down-cast into more
concrete type such as InetSocketAddress
to retrieve the detailed
information.remoteAddress
在接口中 Channel
null
if this channel is not connected.
If this channel is not connected but it can receive messages
from arbitrary remote addresses (e.g. DatagramChannel
,
use DefaultAddressedEnvelope.recipient()
to determine
the origination of the received message as this method will
return null
.@Deprecated protected void invalidateRemoteAddress()
public boolean isRegistered()
Channel
isRegistered
在接口中 Channel
public ChannelFuture bind(java.net.SocketAddress localAddress)
ChannelOutboundInvoker
SocketAddress
and notify the ChannelFuture
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 next ChannelOutboundHandler
contained in the ChannelPipeline
of the
Channel
.
bind
在接口中 ChannelOutboundInvoker
public ChannelFuture connect(java.net.SocketAddress remoteAddress)
ChannelOutboundInvoker
SocketAddress
and notify the ChannelFuture
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
a ConnectTimeoutException
. If it fails because of connection refused a ConnectException
will be used.
This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the next ChannelOutboundHandler
contained in the ChannelPipeline
of the
Channel
.
connect
在接口中 ChannelOutboundInvoker
public ChannelFuture connect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress)
ChannelOutboundInvoker
SocketAddress
while bind to the localAddress and notify the
ChannelFuture
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 next ChannelOutboundHandler
contained in the ChannelPipeline
of the
Channel
.
connect
在接口中 ChannelOutboundInvoker
public ChannelFuture disconnect()
ChannelOutboundInvoker
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
在接口中 ChannelOutboundInvoker
public ChannelFuture close()
ChannelOutboundInvoker
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
在接口中 ChannelOutboundInvoker
public ChannelFuture deregister()
ChannelOutboundInvoker
EventExecutor
and notify the
ChannelFuture
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 next ChannelOutboundHandler
contained in the ChannelPipeline
of the
Channel
.
deregister
在接口中 ChannelOutboundInvoker
public Channel flush()
ChannelOutboundInvoker
flush
在接口中 Channel
flush
在接口中 ChannelOutboundInvoker
public ChannelFuture bind(java.net.SocketAddress localAddress, ChannelPromise promise)
ChannelOutboundInvoker
SocketAddress
and notify the 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.bind(ChannelHandlerContext, SocketAddress, ChannelPromise)
method
called of the next ChannelOutboundHandler
contained in the ChannelPipeline
of the
Channel
.
bind
在接口中 ChannelOutboundInvoker
public ChannelFuture connect(java.net.SocketAddress remoteAddress, ChannelPromise promise)
ChannelOutboundInvoker
SocketAddress
and notify the ChannelFuture
once the operation
completes, either because the operation was successful or because of an error.
The given ChannelFuture
will be notified.
If the connection fails because of a connection timeout, the ChannelFuture
will get failed with
a ConnectTimeoutException
. If it fails because of connection refused a ConnectException
will be used.
This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the next ChannelOutboundHandler
contained in the ChannelPipeline
of the
Channel
.
connect
在接口中 ChannelOutboundInvoker
public ChannelFuture connect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, ChannelPromise promise)
ChannelOutboundInvoker
SocketAddress
while bind to the localAddress and notify the
ChannelFuture
once the operation completes, either because the operation was successful or because of
an error.
The given ChannelPromise
will be notified and also returned.
This will result in having the
ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the next ChannelOutboundHandler
contained in the ChannelPipeline
of the
Channel
.
connect
在接口中 ChannelOutboundInvoker
public ChannelFuture disconnect(ChannelPromise promise)
ChannelOutboundInvoker
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
在接口中 ChannelOutboundInvoker
public ChannelFuture close(ChannelPromise promise)
ChannelOutboundInvoker
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
在接口中 ChannelOutboundInvoker
public ChannelFuture deregister(ChannelPromise promise)
ChannelOutboundInvoker
EventExecutor
and notify the
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.deregister(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOutboundHandler
contained in the ChannelPipeline
of the
Channel
.
deregister
在接口中 ChannelOutboundInvoker
public Channel read()
ChannelOutboundInvoker
Channel
into the first inbound buffer, triggers an
ChannelInboundHandler.channelRead(ChannelHandlerContext, Object)
event if data was
read, and triggers a
channelReadComplete
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 next ChannelOutboundHandler
contained in the ChannelPipeline
of the
Channel
.
read
在接口中 Channel
read
在接口中 ChannelOutboundInvoker
public ChannelFuture write(java.lang.Object msg)
ChannelOutboundInvoker
ChannelHandlerContext
through the ChannelPipeline
.
This method will not request to actual flush, so be sure to call ChannelOutboundInvoker.flush()
once you want to request to flush all pending data to the actual transport.write
在接口中 ChannelOutboundInvoker
public ChannelFuture write(java.lang.Object msg, ChannelPromise promise)
ChannelOutboundInvoker
ChannelHandlerContext
through the ChannelPipeline
.
This method will not request to actual flush, so be sure to call ChannelOutboundInvoker.flush()
once you want to request to flush all pending data to the actual transport.write
在接口中 ChannelOutboundInvoker
public ChannelFuture writeAndFlush(java.lang.Object msg)
ChannelOutboundInvoker
ChannelOutboundInvoker.write(Object)
and ChannelOutboundInvoker.flush()
.writeAndFlush
在接口中 ChannelOutboundInvoker
public ChannelFuture writeAndFlush(java.lang.Object msg, ChannelPromise promise)
ChannelOutboundInvoker
ChannelOutboundInvoker.write(Object, ChannelPromise)
and ChannelOutboundInvoker.flush()
.writeAndFlush
在接口中 ChannelOutboundInvoker
public ChannelPromise newPromise()
ChannelOutboundInvoker
ChannelPromise
.newPromise
在接口中 ChannelOutboundInvoker
public ChannelProgressivePromise newProgressivePromise()
ChannelOutboundInvoker
ChannelProgressivePromise
newProgressivePromise
在接口中 ChannelOutboundInvoker
public ChannelFuture newSucceededFuture()
ChannelOutboundInvoker
ChannelFuture
which is marked as succeeded already. So Future.isSuccess()
will return true
. All FutureListener
added to it will be notified directly. Also
every call of blocking methods will just return without blocking.newSucceededFuture
在接口中 ChannelOutboundInvoker
public ChannelFuture newFailedFuture(java.lang.Throwable cause)
ChannelOutboundInvoker
ChannelFuture
which is marked as failed already. So Future.isSuccess()
will return false
. All FutureListener
added to it will be notified directly. Also
every call of blocking methods will just return without blocking.newFailedFuture
在接口中 ChannelOutboundInvoker
public ChannelFuture closeFuture()
Channel
ChannelFuture
which will be notified when this
channel is closed. This method always returns the same future instance.closeFuture
在接口中 Channel
public Channel.Unsafe unsafe()
Channel
protected abstract AbstractChannel.AbstractUnsafe newUnsafe()
AbstractChannel.AbstractUnsafe
instance which will be used for the life-time of the Channel
public final int hashCode()
hashCode
在类中 java.lang.Object
public final boolean equals(java.lang.Object o)
true
if and only if the specified object is identical
with this channel (i.e: this == o
).equals
在类中 java.lang.Object
public java.lang.String toString()
String
representation of this channel. The returned
string contains the ID, local address,
and remote address of this channel for
easier identification.toString
在类中 java.lang.Object
public final ChannelPromise voidPromise()
ChannelOutboundInvoker
It's only supported to use
it for ChannelOutboundInvoker.write(Object, ChannelPromise)
.
Be aware that the returned ChannelPromise
will not support most operations and should only be used
if you want to save an object allocation for every write operation. You will not be able to detect if the
operation was complete, only if it failed as the implementation will call
ChannelPipeline.fireExceptionCaught(Throwable)
in this case.
voidPromise
在接口中 ChannelOutboundInvoker
protected abstract boolean isCompatible(EventLoop loop)
true
if the given EventLoop
is compatible with this instance.protected abstract java.net.SocketAddress localAddress0()
SocketAddress
which is bound locally.protected abstract java.net.SocketAddress remoteAddress0()
SocketAddress
which the Channel
is connected to.protected void doRegister() throws java.lang.Exception
Channel
is registered with its EventLoop
as part of the register process.
Sub-classes may override this methodjava.lang.Exception
protected abstract void doBind(java.net.SocketAddress localAddress) throws java.lang.Exception
Channel
to the SocketAddress
java.lang.Exception
protected abstract void doDisconnect() throws java.lang.Exception
Channel
from its remote peerjava.lang.Exception
protected abstract void doClose() throws java.lang.Exception
Channel
java.lang.Exception
@UnstableApi protected void doShutdownOutput() throws java.lang.Exception
java.lang.Exception
protected void doDeregister() throws java.lang.Exception
java.lang.Exception
protected abstract void doBeginRead() throws java.lang.Exception
java.lang.Exception
protected abstract void doWrite(ChannelOutboundBuffer in) throws java.lang.Exception
java.lang.Exception
protected java.lang.Object filterOutboundMessage(java.lang.Object msg) throws java.lang.Exception
ChannelOutboundBuffer
of this AbstractChannel
, so that
the Channel
implementation converts the message to another. (e.g. heap buffer -> direct buffer)java.lang.Exception
protected void validateFileRegion(DefaultFileRegion region, long position) throws java.io.IOException
java.io.IOException