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

    • Constructor Detail

      • AbstractChannel

        protected AbstractChannel​(P parent,
                                  EventLoop eventLoop,
                                  boolean supportingDisconnect)
        Creates a new instance.
        Parameters:
        parent - the parent of this channel. null if there's no parent.
        eventLoop - the EventLoop which will be used.
        supportingDisconnect - true if and only if the channel has the disconnect() operation that allows a user to disconnect and then call {
      • AbstractChannel

        protected AbstractChannel​(P parent,
                                  EventLoop eventLoop,
                                  boolean supportingDisconnect,
                                  ReadHandleFactory defaultReadHandleFactory,
                                  WriteHandleFactory defaultWriteHandleFactory)
        Creates a new instance.
        Parameters:
        parent - the parent of this channel. null if there's no parent.
        eventLoop - the EventLoop which will be used.
        supportingDisconnect - true if and only if the channel has the disconnect() operation that allows a user to disconnect and then call {
      • AbstractChannel

        protected AbstractChannel​(P parent,
                                  EventLoop eventLoop,
                                  boolean supportingDisconnect,
                                  ReadHandleFactory defaultReadHandleFactory,
                                  WriteHandleFactory defaultWriteHandleFactory,
                                  ChannelId id)
        Creates a new instance.
        Parameters:
        parent - the parent of this channel. null if there's no parent.
        eventLoop - the EventLoop which will be used.
        supportingDisconnect - true if and only if the channel has the disconnect() operation that allows a user to disconnect and then call {
    • Method Detail

      • validateEventLoopGroup

        protected static <T extends EventLoopGroup> T validateEventLoopGroup​(T group,
                                                                             String name,
                                                                             Class<? extends Channel> channelType)
        Validate that the EventLoopGroup supports the given channel type. If validation fails this will throw a runtime exception.
        Type Parameters:
        T - the concreate type of the EventLoopGroup.
        Parameters:
        group - the group to check against
        name - the name of the param that is used when throwing an exception.
        channelType - the Channel type.
        Returns:
        the group itself
      • id

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

        public final io.netty5.buffer.BufferAllocator bufferAllocator()
        Description copied from interface: Channel
        Return the assigned BufferAllocator which will be used to allocate Buffers.
        Specified by:
        bufferAllocator 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 io.netty5.util.concurrent.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()
      • closeTransport

        protected void closeTransport​(io.netty5.util.concurrent.Promise<Void> promise)
      • readNow

        protected final void readNow()
        Reading from the underlying transport now until there is nothing more to read or the ReadHandleFactory.ReadHandle is telling us to stop.
      • shutdownReadSide

        protected final void shutdownReadSide()
        Shutdown the read side of this channel. Depending on if half-closure is supported or not this will either just shutdown the inbound or close the channel completely.
      • doClearScheduledRead

        protected void doClearScheduledRead()
        Clear any previous scheduled read. By default, this method does nothing but implementations might override it to add extra logic.
      • isReadPending

        protected final boolean isReadPending()
        Returns true if a read is currently scheduled and pending for later execution.
        Returns:
        if a read is pending.
      • isWriteFlushedScheduled

        protected boolean isWriteFlushedScheduled()
        Returns true if flushed messages should not be tried to write when calling Channel.flush(). Instead these will be written once writeFlushedNow() is called, which is typically done once the underlying transport becomes writable again.
        Returns:
        true if write will be done later on by calling writeFlushedNow(), false otherwise.
      • writeFlushed

        protected final void writeFlushed()
        Writing previous flushed messages if isWriteFlushedScheduled() returns false, otherwise do nothing.
      • writeFlushedNow

        protected final void writeFlushedNow()
        Writing previous flushed messages now.
      • writeLoopComplete

        protected void writeLoopComplete​(boolean allWritten)
        Called once the write loop completed. Subclasses might override this method for custom logic but should also call super.
        Parameters:
        allWritten - true if all messages were written during the write loop, false otherwise.
      • localAddress0

        protected abstract L localAddress0()
        Returns the SocketAddress which is bound locally.
        Returns:
        the local address if any, null otherwise.
      • remoteAddress0

        protected abstract R remoteAddress0()
        Return the SocketAddress which the Channel is connected to.
        Returns:
        the remote address if any, null otherwise.
      • doDisconnect

        protected abstract void doDisconnect()
                                      throws Exception
        Disconnect this Channel from its remote peer
        Throws:
        Exception - thrown on error.
      • doRead

        protected abstract void doRead​(boolean wasReadPendingAlready)
                                throws Exception
        Schedule a read operation.
        Parameters:
        wasReadPendingAlready - true if a read was already pending when Channel.read() was called.
        Throws:
        Exception - thrown on error.
      • doConnect

        protected abstract boolean doConnect​(SocketAddress remoteAddress,
                                             SocketAddress localAddress,
                                             io.netty5.buffer.Buffer initialData)
                                      throws Exception
        Connect to remote peer. This method should never be directly called.
        Parameters:
        remoteAddress - the address of the remote peer.
        localAddress - the local address of this channel.
        initialData - the initial data that is written during connect (if ChannelOption.TCP_FASTOPEN_CONNECT is supported and configured). If data is written care must be taken to update the reader offset.
        Returns:
        true if the connect operation was completed, false if finishConnect() will be called later again to try finish connecting.
        Throws:
        Exception - thrown on error.
      • doFinishConnect

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

        protected final boolean isConnectPending()
        Returns if a connect operation was issued before, and finishConnect() must be called once the connect operation can be finished.
        Returns:
        true if there is an outstanding connect request.
      • finishConnect

        protected final boolean finishConnect()
        Should be called once the connect request is ready to be completed and isConnectPending() is true. Calling this method if no connect is pending will result in an AlreadyConnectedException.
        Returns:
        true if the connect operation completed, false otherwise.
      • filterOutboundMessage

        protected Object filterOutboundMessage​(Object msg)
                                        throws Exception
        Invoked when a new message is added to to the outbound queue of this AbstractChannel, so that the Channel implementation converts the message to another. (e.g. heap buffer -> direct buffer)
        Parameters:
        msg - the message to filter / convert.
        Throws:
        Exception - thrown on error.
      • validateFileRegion

        protected static void validateFileRegion​(DefaultFileRegion region,
                                                 long position)
                                          throws IOException
        Parameters:
        region - the region to validate.
        position - the requested position
        Throws:
        IOException - thrown if requested position is invalid.
      • isSupportingDisconnect

        protected final boolean isSupportingDisconnect()
        Returns true if the implementation supports disconnecting and re-connecting, false otherwise.
        Returns:
        true if supported.
      • 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 super after handling the extra options.
        Parameters:
        option - the ChannelOption.
        Returns:
        true if supported, false otherwise.
      • newSupportedIdentityOptionsSet

        protected static Set<ChannelOption<?>> newSupportedIdentityOptionsSet​(ChannelOption<?>... options)
        Creates a new Set that holds the given ChannelOptions. Sub-classes might use this method for supporting their own ChannelOptions.
        Parameters:
        options - the options.
        Returns:
        the Set that holds all the options.
      • readBufferAllocator

        protected io.netty5.buffer.BufferAllocator readBufferAllocator()
        Return the BufferAllocator that is used to allocate Buffer that are used for reading. By default, this will just return bufferAllocator(). Sub-classes might override this if some special allocator is needed.
        Returns:
        the BufferAllocator that is used to allocate Buffers that are used for reading.
      • readLoopComplete

        protected void readLoopComplete()
        Called once the read loop completed for this Channel. Sub-classes might override this method but should also call super.