Class AbstractChannel<P extends Channel,​L extends SocketAddress,​R extends SocketAddress>

    • Method Detail

      • validateEventLoopGroup

        protected static <T extends EventLoopGroup> T validateEventLoopGroup​(T group,
                                                                             String name,
                                                                             Class<? extends Channel> channelType)
      • id

        public final ChannelId id()
        Description copied from interface: Channel
        Returns the globally unique identifier of this Channel.
        Specified by:
        id in interface Channel
      • parent

        public final P parent()
        Description copied from interface: Channel
        Returns the parent of this channel.
        Specified by:
        parent in interface Channel
        Returns:
        the parent channel. null if this channel does not have a parent channel.
      • localAddress

        public final L localAddress()
        Description copied from interface: Channel
        Returns the local address where this channel is bound to. The returned SocketAddress is supposed to be down-cast into more concrete type such as InetSocketAddress to retrieve the detailed information.
        Specified by:
        localAddress in interface Channel
        Returns:
        the local address of this channel. null if this channel is not bound.
      • remoteAddress

        public final R remoteAddress()
        Description copied from interface: Channel
        Returns the remote address where this channel is connected to. The returned SocketAddress is supposed to be down-cast into more concrete type such as InetSocketAddress to retrieve the detailed information.
        Specified by:
        remoteAddress in interface Channel
        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, use DefaultAddressedEnvelope.recipient() to determine the origination of the received message as this method will return null.
      • cacheAddresses

        protected final void cacheAddresses​(L localAddress,
                                            R remoteAddress)
      • isRegistered

        public final boolean isRegistered()
        Description copied from interface: IoHandle
        Return true if registered already.
        Specified by:
        isRegistered in interface IoHandle
        Returns:
        true if registered, false otherwise
      • closeFuture

        public final Future<Void> closeFuture()
        Description copied from interface: Channel
        Returns the Future which will be notified when this channel is closed. This method always returns the same future instance.
        Specified by:
        closeFuture in interface Channel
      • writableBytes

        public final long writableBytes()
        Description copied from interface: Channel
        Returns how many bytes can be written before the Channel becomes 'unwritable'. Once a Channel becomes unwritable, all messages will be queued until the I/O thread is ready to process the queued write requests.
        Specified by:
        writableBytes in interface Channel
        Returns:
        the number of bytes that can be written before the Channel becomes unwritable.
      • hashCode

        public final int hashCode()
        Returns the ID of this channel.
        Overrides:
        hashCode in class Object
      • equals

        public final boolean equals​(Object o)
        Returns true if and only if the specified object is identical with this channel (i.e: this == o).
        Overrides:
        equals in class Object
      • readIfIsAutoRead

        protected final void readIfIsAutoRead()
      • assertEventLoop

        protected final void assertEventLoop()
      • closeTransport

        protected void closeTransport​(Promise<Void> promise)
      • closeForciblyTransport

        protected final void closeForciblyTransport()
      • deregisterTransport

        protected void deregisterTransport​(Promise<Void> promise)
      • writeFlushed

        protected void writeFlushed()
        Write previous flushed messages.
      • handleWriteError

        protected final void handleWriteError​(Throwable t)
      • ensureOpen

        protected final boolean ensureOpen​(Promise<Void> promise)
      • safeSetSuccess

        protected final void safeSetSuccess​(Promise<Void> promise)
        Marks the specified promise as success. If the promise is done already, log a message.
      • safeSetFailure

        protected final void safeSetFailure​(Promise<Void> promise,
                                            Throwable cause)
        Marks the specified promise as failure. If the promise is done already, log a message.
      • closeIfClosed

        protected final void closeIfClosed()
      • annotateConnectException

        protected static Throwable annotateConnectException​(Throwable cause,
                                                            SocketAddress remoteAddress)
        Appends the remote address to the message of the exceptions caused by connection attempt failure.
      • localAddress0

        protected abstract L localAddress0()
        Returns the SocketAddress which is bound locally.
      • remoteAddress0

        protected abstract R remoteAddress0()
        Return the SocketAddress which the Channel is connected to.
      • doDisconnect

        protected abstract void doDisconnect()
                                      throws Exception
        Disconnect this Channel from its remote peer
        Throws:
        Exception
      • doBeginRead

        protected abstract void doBeginRead()
                                     throws Exception
        Schedule a read operation.
        Throws:
        Exception
      • doConnect

        protected abstract boolean doConnect​(SocketAddress remoteAddress,
                                             SocketAddress localAddress)
                                      throws Exception
        Connect to remote peer.
        Parameters:
        remoteAddress - the address of the remote peer.
        localAddress - the local address of this channel.
        Returns:
        true if the connect was completed, false if finishConnect() will be called later again to try finishing the connect.
        Throws:
        Exception - thrown on error.
      • doFinishConnect

        protected abstract boolean doFinishConnect​(R requestedRemoteAddress)
                                            throws Exception
        Finish a connect request.
        Parameters:
        requestedRemoteAddress - the remote address of the peer.
        Returns:
        true if the connect was completed, false if finishConnect() will be called later again to try finishing the connect.
        Throws:
        Exception - thrown on error.
      • isConnectPending

        protected final boolean isConnectPending()
        Returns if a connect request was issued before and we are waiting for finishConnect() to be called.
        Returns:
        true if there is an outstanding connect request.
      • finishConnect

        protected final void finishConnect()
        Should be called once the connect request is ready to be completed.
      • setOption

        public final <T> Channel setOption​(ChannelOption<T> option,
                                           T value)
        Description copied from interface: Channel
        Sets a configuration property with the specified name and value.
        Specified by:
        setOption in interface Channel
        Type Parameters:
        T - the type of the value.
        Parameters:
        option - the ChannelOption.
        value - the value for the ChannelOption
        Returns:
        itself.
      • isExtendedOptionSupported

        protected boolean isExtendedOptionSupported​(ChannelOption<?> option)
        Override to add support for more ChannelOptions. You need to also call {@link super} after handling the extra options.
        Parameters:
        option - the ChannelOption.
        Returns:
        true if supported, false otherwise.
      • validate

        protected <T> void validate​(ChannelOption<T> option,
                                    T value)
      • getMaxMessagesPerWrite

        protected final int getMaxMessagesPerWrite()
        Get the maximum number of message to write per eventloop run. Once this limit is reached we will continue to process other events before trying to write the remaining messages.
      • getWriteSpinCount

        protected final int getWriteSpinCount()
      • setBufferAllocator

        public void setBufferAllocator​(BufferAllocator bufferAllocator)
      • isAutoRead

        protected final boolean isAutoRead()
      • isAllowHalfClosure

        protected final boolean isAllowHalfClosure()
      • runAfterTransportAction

        protected void runAfterTransportAction()