Package io.netty.channel
Class AbstractChannel
- java.lang.Object
 - 
- io.netty.util.DefaultAttributeMap
 - 
- io.netty.channel.AbstractChannel
 
 
 
- 
- All Implemented Interfaces:
 Channel,ChannelOutboundInvoker,AttributeMap,java.lang.Comparable<Channel>
- Direct Known Subclasses:
 AbstractEpollServerChannel,AbstractEpollStreamChannel,AbstractKQueueServerChannel,AbstractKQueueStreamChannel,AbstractNioChannel,AbstractOioChannel,AbstractServerChannel,EmbeddedChannel,EpollDatagramChannel,EpollDomainDatagramChannel,IoUringDatagramChannel,IoUringDomainSocketChannel,IoUringServerDomainSocketChannel,IoUringServerSocketChannel,IoUringSocketChannel,KQueueDatagramChannel,KQueueDomainDatagramChannel,LocalChannel
public abstract class AbstractChannel extends DefaultAttributeMap implements Channel
A skeletalChannelimplementation. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractChannel.AbstractUnsafeChannel.Unsafeimplementation which sub-classes must extend and use.- 
Nested classes/interfaces inherited from interface io.netty.channel.Channel
Channel.Unsafe 
 - 
 
- 
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractChannel(Channel parent)Creates a new instance.protectedAbstractChannel(Channel parent, ChannelId id)Creates a new instance. 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ChannelFuturecloseFuture()Returns theChannelFuturewhich will be notified when this channel is closed.intcompareTo(Channel o)protected abstract voiddoBeginRead()Schedule a read operation.protected abstract voiddoBind(java.net.SocketAddress localAddress)Bind theChannelto theSocketAddressprotected abstract voiddoClose()Close theChannelprotected voiddoDeregister()protected abstract voiddoDisconnect()Disconnect thisChannelfrom its remote peerprotected voiddoRegister()Deprecated.protected voiddoRegister(ChannelPromise promise)protected voiddoShutdownOutput()Called when conditions justify shutting down the output portion of the channel.protected abstract voiddoWrite(ChannelOutboundBuffer in)Flush the content of the given buffer to the remote peer.booleanequals(java.lang.Object o)Returnstrueif and only if the specified object is identical with this channel (i.e:this == o).EventLoopeventLoop()protected java.lang.ObjectfilterOutboundMessage(java.lang.Object msg)Invoked when a new message is added to aChannelOutboundBufferof thisAbstractChannel, so that theChannelimplementation converts the message to another.inthashCode()Returns the ID of this channel.ChannelIdid()Returns the globally unique identifier of thisChannel.protected voidinvalidateLocalAddress()Deprecated.no use-case for this.protected voidinvalidateRemoteAddress()Deprecated.no use-case for this.protected abstract booleanisCompatible(EventLoop loop)Returntrueif the givenEventLoopis compatible with this instance.booleanisRegistered()java.net.SocketAddresslocalAddress()Returns the local address where this channel is bound to.protected abstract java.net.SocketAddresslocalAddress0()Returns theSocketAddresswhich is bound locally.protected intmaxMessagesPerWrite()protected DefaultChannelPipelinenewChannelPipeline()Returns a newDefaultChannelPipelineinstance.protected ChannelIdnewId()Returns a newDefaultChannelIdinstance.protected abstract AbstractChannel.AbstractUnsafenewUnsafe()Create a newAbstractChannel.AbstractUnsafeinstance which will be used for the life-time of theChannelChannelparent()Returns the parent of this channel.ChannelPipelinepipeline()Return the assignedChannelPipeline.java.net.SocketAddressremoteAddress()Returns the remote address where this channel is connected to.protected abstract java.net.SocketAddressremoteAddress0()Return theSocketAddresswhich theChannelis connected to.java.lang.StringtoString()Returns theStringrepresentation of this channel.Channel.Unsafeunsafe()Returns an internal-use-only object that provides unsafe operations.protected voidvalidateFileRegion(DefaultFileRegion region, long position)ChannelPromisevoidPromise()Return a special ChannelPromise which can be reused for different operations.- 
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, bind, bind, bytesBeforeUnwritable, bytesBeforeWritable, close, close, config, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, flush, getOption, isActive, isOpen, isWritable, metadata, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, read, setOption, write, write, writeAndFlush, writeAndFlush 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
AbstractChannel
protected AbstractChannel(Channel parent)
Creates a new instance.- Parameters:
 parent- the parent of this channel.nullif there's no parent.
 
 - 
 
- 
Method Detail
- 
maxMessagesPerWrite
protected final int maxMessagesPerWrite()
 
- 
id
public final ChannelId id()
Description copied from interface:ChannelReturns the globally unique identifier of thisChannel. 
- 
newId
protected ChannelId newId()
Returns a newDefaultChannelIdinstance. Subclasses may override this method to assign customChannelIds toChannels that use theAbstractChannel(Channel)constructor. 
- 
newChannelPipeline
protected DefaultChannelPipeline newChannelPipeline()
Returns a newDefaultChannelPipelineinstance. 
- 
parent
public Channel parent()
Description copied from interface:ChannelReturns the parent of this channel. 
- 
pipeline
public ChannelPipeline pipeline()
Description copied from interface:ChannelReturn the assignedChannelPipeline. 
- 
localAddress
public java.net.SocketAddress 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 protected void invalidateLocalAddress()
Deprecated.no use-case for this. 
- 
remoteAddress
public java.net.SocketAddress 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 protected void invalidateRemoteAddress()
Deprecated.no use-case for this. 
- 
isRegistered
public boolean isRegistered()
Description copied from interface:Channel- Specified by:
 isRegisteredin interfaceChannel
 
- 
closeFuture
public ChannelFuture 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
public Channel.Unsafe unsafe()
Description copied from interface:ChannelReturns an internal-use-only object that provides unsafe operations. 
- 
newUnsafe
protected abstract AbstractChannel.AbstractUnsafe newUnsafe()
Create a newAbstractChannel.AbstractUnsafeinstance which will be used for the life-time of theChannel 
- 
hashCode
public final int hashCode()
Returns the ID of this channel.- Overrides:
 hashCodein classjava.lang.Object
 
- 
equals
public final boolean equals(java.lang.Object o)
Returnstrueif and only if the specified object is identical with this channel (i.e:this == o).- Overrides:
 equalsin classjava.lang.Object
 
- 
compareTo
public final int compareTo(Channel o)
- Specified by:
 compareToin interfacejava.lang.Comparable<Channel>
 
- 
toString
public java.lang.String toString()
Returns theStringrepresentation of this channel. The returned string contains the ID, local address, and remote address of this channel for easier identification.- Overrides:
 toStringin classjava.lang.Object
 
- 
voidPromise
public final ChannelPromise 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 interfaceChannel- Specified by:
 voidPromisein interfaceChannelOutboundInvoker
 
- 
isCompatible
protected abstract boolean isCompatible(EventLoop loop)
Returntrueif the givenEventLoopis compatible with this instance. 
- 
localAddress0
protected abstract java.net.SocketAddress localAddress0()
Returns theSocketAddresswhich is bound locally. 
- 
remoteAddress0
protected abstract java.net.SocketAddress remoteAddress0()
Return theSocketAddresswhich theChannelis connected to. 
- 
doRegister
@Deprecated protected void doRegister() throws java.lang.ExceptionDeprecated.Is called after theChannelis registered with itsEventLoopas part of the register process. Subclasses may override this method- Throws:
 java.lang.Exception
 
- 
doRegister
protected void doRegister(ChannelPromise promise)
Is called after theChannelis registered with itsEventLoopas part of the register process. Subclasses may override this method- Parameters:
 promise-ChannelPromisethat must be notified once done to continue the registration.
 
- 
doBind
protected abstract void doBind(java.net.SocketAddress localAddress) throws java.lang.ExceptionBind theChannelto theSocketAddress- Throws:
 java.lang.Exception
 
- 
doDisconnect
protected abstract void doDisconnect() throws java.lang.ExceptionDisconnect thisChannelfrom its remote peer- Throws:
 java.lang.Exception
 
- 
doClose
protected abstract void doClose() throws java.lang.ExceptionClose theChannel- Throws:
 java.lang.Exception
 
- 
doShutdownOutput
protected void doShutdownOutput() throws java.lang.ExceptionCalled when conditions justify shutting down the output portion of the channel. This may happen if a write operation throws an exception.- Throws:
 java.lang.Exception
 
- 
doDeregister
protected void doDeregister() throws java.lang.Exception- Throws:
 java.lang.Exception
 
- 
doBeginRead
protected abstract void doBeginRead() throws java.lang.ExceptionSchedule a read operation.- Throws:
 java.lang.Exception
 
- 
doWrite
protected abstract void doWrite(ChannelOutboundBuffer in) throws java.lang.Exception
Flush the content of the given buffer to the remote peer.- Throws:
 java.lang.Exception
 
- 
filterOutboundMessage
protected java.lang.Object filterOutboundMessage(java.lang.Object msg) throws java.lang.ExceptionInvoked when a new message is added to aChannelOutboundBufferof thisAbstractChannel, so that theChannelimplementation converts the message to another. (e.g. heap buffer -> direct buffer)- Throws:
 java.lang.Exception
 
- 
validateFileRegion
protected void validateFileRegion(DefaultFileRegion region, long position) throws java.io.IOException
- Throws:
 java.io.IOException
 
 - 
 
 -