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
,IoUringServerSocketChannel
,IoUringSocketChannel
,KQueueDatagramChannel
,KQueueDomainDatagramChannel
,LocalChannel
public abstract class AbstractChannel extends DefaultAttributeMap implements Channel
A skeletalChannel
implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractChannel.AbstractUnsafe
Channel.Unsafe
implementation 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 protected
AbstractChannel(Channel parent)
Creates a new instance.protected
AbstractChannel(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 ChannelFuture
closeFuture()
Returns theChannelFuture
which will be notified when this channel is closed.int
compareTo(Channel o)
protected abstract void
doBeginRead()
Schedule a read operation.protected abstract void
doBind(java.net.SocketAddress localAddress)
Bind theChannel
to theSocketAddress
protected abstract void
doClose()
Close theChannel
protected void
doDeregister()
protected abstract void
doDisconnect()
Disconnect thisChannel
from its remote peerprotected void
doRegister()
Deprecated.protected void
doRegister(ChannelPromise promise)
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)
Returnstrue
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 aChannelOutboundBuffer
of thisAbstractChannel
, so that theChannel
implementation converts the message to another.int
hashCode()
Returns the ID of this channel.ChannelId
id()
Returns the globally unique identifier of thisChannel
.protected void
invalidateLocalAddress()
Deprecated.no use-case for this.protected void
invalidateRemoteAddress()
Deprecated.no use-case for this.protected abstract boolean
isCompatible(EventLoop loop)
Returntrue
if the givenEventLoop
is compatible with this instance.boolean
isRegistered()
java.net.SocketAddress
localAddress()
Returns the local address where this channel is bound to.protected abstract java.net.SocketAddress
localAddress0()
Returns theSocketAddress
which is bound locally.protected int
maxMessagesPerWrite()
protected DefaultChannelPipeline
newChannelPipeline()
Returns a newDefaultChannelPipeline
instance.protected ChannelId
newId()
Returns a newDefaultChannelId
instance.protected abstract AbstractChannel.AbstractUnsafe
newUnsafe()
Create a newAbstractChannel.AbstractUnsafe
instance which will be used for the life-time of theChannel
Channel
parent()
Returns the parent of this channel.ChannelPipeline
pipeline()
Return the assignedChannelPipeline
.java.net.SocketAddress
remoteAddress()
Returns the remote address where this channel is connected to.protected abstract java.net.SocketAddress
remoteAddress0()
Return theSocketAddress
which theChannel
is connected to.java.lang.String
toString()
Returns theString
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.-
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.null
if there's no parent.
-
-
Method Detail
-
maxMessagesPerWrite
protected final int maxMessagesPerWrite()
-
id
public final ChannelId id()
Description copied from interface:Channel
Returns the globally unique identifier of thisChannel
.
-
newId
protected ChannelId newId()
Returns a newDefaultChannelId
instance. Subclasses may override this method to assign customChannelId
s toChannel
s that use theAbstractChannel(Channel)
constructor.
-
newChannelPipeline
protected DefaultChannelPipeline newChannelPipeline()
Returns a newDefaultChannelPipeline
instance.
-
parent
public Channel parent()
Description copied from interface:Channel
Returns the parent of this channel.
-
pipeline
public ChannelPipeline pipeline()
Description copied from interface:Channel
Return the assignedChannelPipeline
.
-
localAddress
public java.net.SocketAddress localAddress()
Description copied from interface:Channel
Returns the local address where this channel is bound to. The returnedSocketAddress
is supposed to be down-cast into more concrete type such asInetSocketAddress
to retrieve the detailed information.- Specified by:
localAddress
in interfaceChannel
- Returns:
- the local address of this channel.
null
if 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:Channel
Returns the remote address where this channel is connected to. The returnedSocketAddress
is supposed to be down-cast into more concrete type such asInetSocketAddress
to retrieve the detailed information.- Specified by:
remoteAddress
in interfaceChannel
- Returns:
- the remote address of this 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
, 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:
isRegistered
in interfaceChannel
-
closeFuture
public ChannelFuture closeFuture()
Description copied from interface:Channel
Returns theChannelFuture
which will be notified when this channel is closed. This method always returns the same future instance.- Specified by:
closeFuture
in interfaceChannel
-
unsafe
public Channel.Unsafe unsafe()
Description copied from interface:Channel
Returns an internal-use-only object that provides unsafe operations.
-
newUnsafe
protected abstract AbstractChannel.AbstractUnsafe newUnsafe()
Create a newAbstractChannel.AbstractUnsafe
instance which will be used for the life-time of theChannel
-
hashCode
public final int hashCode()
Returns the ID of this channel.- Overrides:
hashCode
in classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object o)
Returnstrue
if and only if the specified object is identical with this channel (i.e:this == o
).- Overrides:
equals
in classjava.lang.Object
-
compareTo
public final int compareTo(Channel o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<Channel>
-
toString
public java.lang.String toString()
Returns theString
representation of this channel. The returned string contains the ID, local address, and remote address of this channel for easier identification.- Overrides:
toString
in classjava.lang.Object
-
voidPromise
public final ChannelPromise voidPromise()
Description copied from interface:ChannelOutboundInvoker
Return 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!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 callChannelPipeline.fireExceptionCaught(Throwable)
in this case.- Specified by:
voidPromise
in interfaceChannel
- Specified by:
voidPromise
in interfaceChannelOutboundInvoker
-
isCompatible
protected abstract boolean isCompatible(EventLoop loop)
Returntrue
if the givenEventLoop
is compatible with this instance.
-
localAddress0
protected abstract java.net.SocketAddress localAddress0()
Returns theSocketAddress
which is bound locally.
-
remoteAddress0
protected abstract java.net.SocketAddress remoteAddress0()
Return theSocketAddress
which theChannel
is connected to.
-
doRegister
@Deprecated protected void doRegister() throws java.lang.Exception
Deprecated.Is called after theChannel
is registered with itsEventLoop
as part of the register process. Subclasses may override this method- Throws:
java.lang.Exception
-
doRegister
protected void doRegister(ChannelPromise promise)
Is called after theChannel
is registered with itsEventLoop
as part of the register process. Subclasses may override this method- Parameters:
promise
-ChannelPromise
that must be notified once done to continue the registration.
-
doBind
protected abstract void doBind(java.net.SocketAddress localAddress) throws java.lang.Exception
Bind theChannel
to theSocketAddress
- Throws:
java.lang.Exception
-
doDisconnect
protected abstract void doDisconnect() throws java.lang.Exception
Disconnect thisChannel
from its remote peer- Throws:
java.lang.Exception
-
doClose
protected abstract void doClose() throws java.lang.Exception
Close theChannel
- Throws:
java.lang.Exception
-
doShutdownOutput
protected void doShutdownOutput() throws java.lang.Exception
Called 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.Exception
Schedule 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.Exception
Invoked when a new message is added to aChannelOutboundBuffer
of thisAbstractChannel
, so that theChannel
implementation 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
-
-