Class AbstractChannel
- All Implemented Interfaces:
Channel, ChannelOutboundInvoker, AttributeMap, Comparable<Channel>
- Direct Known Subclasses:
AbstractEpollServerChannel, AbstractEpollStreamChannel, AbstractKQueueServerChannel, AbstractKQueueStreamChannel, AbstractNioChannel, AbstractOioChannel, AbstractServerChannel, EmbeddedChannel, EpollDatagramChannel, EpollDomainDatagramChannel, KQueueDatagramChannel, KQueueDomainDatagramChannel, LocalChannel
Channel implementation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classChannel.Unsafeimplementation which sub-classes must extend and use.Nested classes/interfaces inherited from interface Channel
Channel.Unsafe -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractChannel(Channel parent) Creates a new instance.protectedAbstractChannel(Channel parent, ChannelId id) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionalloc()Return the assignedByteBufAllocatorwhich will be used to allocateByteBufs.bind(SocketAddress localAddress) Request to bind to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.bind(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.longGet how many bytes can be written untilChannel.isWritable()returnsfalse.longGet how many bytes must be drained from underlying buffers untilChannel.isWritable()returnstrue.close()Request to close theChanneland notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.close(ChannelPromise promise) Request to close theChanneland notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.Returns theChannelFuturewhich will be notified when this channel is closed.final intconnect(SocketAddress remoteAddress) Request to connect to the givenSocketAddressand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.connect(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.connect(SocketAddress remoteAddress, 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.connect(SocketAddress remoteAddress, 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.Request to deregister from the previous assignedEventExecutorand notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.deregister(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.Request to disconnect from the remote peer and notify theChannelFutureonce the operation completes, either because the operation was successful or because of an error.disconnect(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 abstract voidSchedule a read operation.protected abstract voiddoBind(SocketAddress localAddress) Bind theChannelto theSocketAddressprotected abstract voiddoClose()Close theChannelprotected voidprotected abstract voidDisconnect thisChannelfrom its remote peerprotected voidprotected voidCalled when conditions justify shutting down the output portion of the channel.protected abstract voidFlush the content of the given buffer to the remote peer.final booleanReturnstrueif and only if the specified object is identical with this channel (i.e:this == o).protected ObjectInvoked when a new message is added to aChannelOutboundBufferof thisAbstractChannel, so that theChannelimplementation converts the message to another.flush()Request to flush all pending messages via this ChannelOutboundInvoker.final inthashCode()Returns the ID of this channel.final ChannelIdid()Returns the globally unique identifier of thisChannel.protected voidDeprecated.no use-case for this.protected voidDeprecated.no use-case for this.protected abstract booleanisCompatible(EventLoop loop) Returntrueif the givenEventLoopis compatible with this instance.booleanbooleanReturnstrueif and only if the I/O thread will perform the requested write operation immediately.Returns the local address where this channel is bound to.protected abstract SocketAddressReturns theSocketAddresswhich is bound locally.protected final intprotected DefaultChannelPipelineReturns a newDefaultChannelPipelineinstance.newFailedFuture(Throwable cause) Create a newChannelFuturewhich is marked as failed already.protected ChannelIdnewId()Returns a newDefaultChannelIdinstance.Return an newChannelProgressivePromiseReturn a newChannelPromise.Create a newChannelFuturewhich is marked as succeeded already.protected abstract AbstractChannel.AbstractUnsafeCreate a newAbstractChannel.AbstractUnsafeinstance which will be used for the life-time of theChannelparent()Returns the parent of this channel.pipeline()Return the assignedChannelPipeline.read()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.Returns the remote address where this channel is connected to.protected abstract SocketAddressReturn theSocketAddresswhich theChannelis connected to.toString()Returns theStringrepresentation of this channel.unsafe()Returns an internal-use-only object that provides unsafe operations.protected voidvalidateFileRegion(DefaultFileRegion region, long position) final ChannelPromiseReturn a special ChannelPromise which can be reused for different operations.Request to write a message via thisChannelHandlerContextthrough theChannelPipeline.write(Object msg, ChannelPromise promise) Request to write a message via thisChannelHandlerContextthrough theChannelPipeline.writeAndFlush(Object msg) Shortcut for callChannelOutboundInvoker.write(Object)andChannelOutboundInvoker.flush().writeAndFlush(Object msg, ChannelPromise promise) Shortcut for callChannelOutboundInvoker.write(Object, ChannelPromise)andChannelOutboundInvoker.flush().Methods inherited from class DefaultAttributeMap
attr, hasAttrMethods inherited from interface AttributeMap
attr, hasAttr
-
Constructor Details
-
AbstractChannel
Creates a new instance.- Parameters:
parent- the parent of this channel.nullif there's no parent.
-
AbstractChannel
-
-
Method Details
-
maxMessagesPerWrite
protected final int maxMessagesPerWrite() -
id
-
newId
Returns a newDefaultChannelIdinstance. Subclasses may override this method to assign customChannelIds toChannels that use theAbstractChannel(Channel)constructor. -
newChannelPipeline
Returns a newDefaultChannelPipelineinstance. -
isWritable
public boolean isWritable()Description copied from interface:ChannelReturnstrueif and only if the I/O thread will perform the requested write operation immediately. Any write requests made when this method returnsfalseare queued until the I/O thread is ready to process the queued write requests.WriteBufferWaterMarkcan be used to configure on which condition the write buffer would cause this channel to change writability.- Specified by:
isWritablein interfaceChannel
-
bytesBeforeUnwritable
public long bytesBeforeUnwritable()Description copied from interface:ChannelGet how many bytes can be written untilChannel.isWritable()returnsfalse. This quantity will always be non-negative. IfChannel.isWritable()isfalsethen 0.WriteBufferWaterMarkcan be used to define writability settings.- Specified by:
bytesBeforeUnwritablein interfaceChannel
-
bytesBeforeWritable
public long bytesBeforeWritable()Description copied from interface:ChannelGet how many bytes must be drained from underlying buffers untilChannel.isWritable()returnstrue. This quantity will always be non-negative. IfChannel.isWritable()istruethen 0.WriteBufferWaterMarkcan be used to define writability settings.- Specified by:
bytesBeforeWritablein interfaceChannel
-
parent
-
pipeline
Description copied from interface:ChannelReturn the assignedChannelPipeline. -
alloc
Description copied from interface:ChannelReturn the assignedByteBufAllocatorwhich will be used to allocateByteBufs. -
eventLoop
-
localAddress
Description copied from interface:ChannelReturns the local address where this channel is bound to. The returnedSocketAddressis supposed to be down-cast into more concrete type such asInetSocketAddressto retrieve the detailed information.- Specified by:
localAddressin interfaceChannel- Returns:
- the local address of this channel.
nullif this channel is not bound.
-
invalidateLocalAddress
Deprecated.no use-case for this. -
remoteAddress
Description copied from interface:ChannelReturns the remote address where this channel is connected to. The returnedSocketAddressis supposed to be down-cast into more concrete type such asInetSocketAddressto retrieve the detailed information.- Specified by:
remoteAddressin interfaceChannel- Returns:
- the remote address of this channel.
nullif this channel is not connected. If this channel is not connected but it can receive messages from arbitrary remote addresses (e.g.DatagramChannel, useDefaultAddressedEnvelope.recipient()to determine the origination of the received message as this method will returnnull.
-
invalidateRemoteAddress
Deprecated.no use-case for this. -
isRegistered
public boolean isRegistered()Description copied from interface:Channel- Specified by:
isRegisteredin interfaceChannel
-
bind
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.- Specified by:
bindin interfaceChannelOutboundInvoker
-
connect
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.- Specified by:
connectin interfaceChannelOutboundInvoker
-
connect
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.- Specified by:
connectin interfaceChannelOutboundInvoker
-
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.- Specified by:
disconnectin interfaceChannelOutboundInvoker
-
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.- Specified by:
closein interfaceChannelOutboundInvoker
-
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.- Specified by:
deregisterin interfaceChannelOutboundInvoker
-
flush
Description copied from interface:ChannelOutboundInvokerRequest to flush all pending messages via this ChannelOutboundInvoker.- Specified by:
flushin interfaceChannel- Specified by:
flushin interfaceChannelOutboundInvoker
-
bind
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.- Specified by:
bindin interfaceChannelOutboundInvoker
-
connect
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.- Specified by:
connectin interfaceChannelOutboundInvoker
-
connect
public ChannelFuture connect(SocketAddress remoteAddress, 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.- Specified by:
connectin interfaceChannelOutboundInvoker
-
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. The givenChannelPromisewill be notified.This will result in having the
ChannelOutboundHandler.disconnect(ChannelHandlerContext, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel.- Specified by:
disconnectin interfaceChannelOutboundInvoker
-
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. The givenChannelPromisewill be notified.This will result in having the
ChannelOutboundHandler.close(ChannelHandlerContext, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel.- Specified by:
closein interfaceChannelOutboundInvoker
-
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. The givenChannelPromisewill be notified.This will result in having the
ChannelOutboundHandler.deregister(ChannelHandlerContext, ChannelPromise)method called of the nextChannelOutboundHandlercontained in theChannelPipelineof theChannel.- Specified by:
deregisterin interfaceChannelOutboundInvoker
-
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.- Specified by:
readin interfaceChannel- Specified by:
readin interfaceChannelOutboundInvoker
-
write
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.- Specified by:
writein interfaceChannelOutboundInvoker
-
write
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.- Specified by:
writein interfaceChannelOutboundInvoker
-
writeAndFlush
Description copied from interface:ChannelOutboundInvokerShortcut for callChannelOutboundInvoker.write(Object)andChannelOutboundInvoker.flush().- Specified by:
writeAndFlushin interfaceChannelOutboundInvoker
-
writeAndFlush
Description copied from interface:ChannelOutboundInvokerShortcut for callChannelOutboundInvoker.write(Object, ChannelPromise)andChannelOutboundInvoker.flush().- Specified by:
writeAndFlushin interfaceChannelOutboundInvoker
-
newPromise
Description copied from interface:ChannelOutboundInvokerReturn a newChannelPromise.- Specified by:
newPromisein interfaceChannelOutboundInvoker
-
newProgressivePromise
Description copied from interface:ChannelOutboundInvokerReturn an newChannelProgressivePromise- Specified by:
newProgressivePromisein interfaceChannelOutboundInvoker
-
newSucceededFuture
Description copied from interface:ChannelOutboundInvokerCreate a newChannelFuturewhich is marked as succeeded already. SoFuture.isSuccess()will returntrue. AllFutureListeneradded to it will be notified directly. Also every call of blocking methods will just return without blocking.- Specified by:
newSucceededFuturein interfaceChannelOutboundInvoker
-
newFailedFuture
Description copied from interface:ChannelOutboundInvokerCreate a newChannelFuturewhich is marked as failed already. SoFuture.isSuccess()will returnfalse. AllFutureListeneradded to it will be notified directly. Also every call of blocking methods will just return without blocking.- Specified by:
newFailedFuturein interfaceChannelOutboundInvoker
-
closeFuture
Description copied from interface:ChannelReturns theChannelFuturewhich will be notified when this channel is closed. This method always returns the same future instance.- Specified by:
closeFuturein interfaceChannel
-
unsafe
Description copied from interface:ChannelReturns an internal-use-only object that provides unsafe operations. -
newUnsafe
Create a newAbstractChannel.AbstractUnsafeinstance which will be used for the life-time of theChannel -
hashCode
-
equals
-
compareTo
- Specified by:
compareToin interfaceComparable<Channel>
-
toString
Returns theStringrepresentation of this channel. The returned string contains the ID, local address, and remote address of this channel for easier identification. -
voidPromise
Description copied from interface:ChannelOutboundInvokerReturn a special ChannelPromise which can be reused for different operations.It's only supported to use it for
ChannelOutboundInvoker.write(Object, ChannelPromise).Be aware that the returned
Be aware this is an expert feature and should be used with care!ChannelPromisewill 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 callChannelPipeline.fireExceptionCaught(Throwable)in this case.- Specified by:
voidPromisein interfaceChannelOutboundInvoker
-
isCompatible
-
localAddress0
Returns theSocketAddresswhich is bound locally. -
remoteAddress0
Return theSocketAddresswhich theChannelis connected to. -
doRegister
-
doBind
Bind theChannelto theSocketAddress- Throws:
Exception
-
doDisconnect
-
doClose
-
doShutdownOutput
-
doDeregister
-
doBeginRead
-
doWrite
Flush the content of the given buffer to the remote peer.- Throws:
Exception
-
filterOutboundMessage
Invoked when a new message is added to aChannelOutboundBufferof thisAbstractChannel, so that theChannelimplementation converts the message to another. (e.g. heap buffer -> direct buffer)- Throws:
Exception
-
validateFileRegion
- Throws:
IOException
-