Class AbstractChannel

    • Constructor Detail

      • AbstractChannel

        protected AbstractChannel​(Channel parent,
                                  ChannelFactory factory,
                                  ChannelPipeline pipeline,
                                  ChannelSink sink)
        Creates a new instance.
        Parameters:
        parent - the parent of this channel. null if there's no parent.
        factory - the factory which created this channel
        pipeline - the pipeline which is going to be attached to this channel
        sink - the sink which will receive downstream events from the pipeline and send upstream events to the pipeline
      • AbstractChannel

        protected AbstractChannel​(Integer id,
                                  Channel parent,
                                  ChannelFactory factory,
                                  ChannelPipeline pipeline,
                                  ChannelSink sink)
        (Internal use only) Creates a new temporary instance with the specified ID.
        Parameters:
        parent - the parent of this channel. null if there's no parent.
        factory - the factory which created this channel
        pipeline - the pipeline which is going to be attached to this channel
        sink - the sink which will receive downstream events from the pipeline and send upstream events to the pipeline
    • Method Detail

      • getId

        public final Integer getId()
        Description copied from interface: Channel
        Returns the unique integer ID of this channel.
        Specified by:
        getId in interface Channel
      • getParent

        public Channel getParent()
        Description copied from interface: Channel
        Returns the parent of this channel.
        Specified by:
        getParent in interface Channel
        Returns:
        the parent channel. null if this channel does not have a parent channel.
      • 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
      • isOpen

        public boolean isOpen()
        Description copied from interface: Channel
        Returns true if and only if this channel is open.
        Specified by:
        isOpen in interface Channel
      • setClosed

        protected boolean setClosed()
        Marks this channel as closed. This method is intended to be called by an internal component - please do not call it unless you know what you are doing.
        Returns:
        true if and only if this channel was not marked as closed yet
      • bind

        public ChannelFuture bind​(SocketAddress localAddress)
        Description copied from interface: Channel
        Binds this channel to the specified local address asynchronously.
        Specified by:
        bind in interface Channel
        Parameters:
        localAddress - where to bind
        Returns:
        the ChannelFuture which will be notified when the bind request succeeds or fails
      • unbind

        public ChannelFuture unbind()
        Description copied from interface: Channel
        Unbinds this channel from the current local address asynchronously.
        Specified by:
        unbind in interface Channel
        Returns:
        the ChannelFuture which will be notified when the unbind request succeeds or fails
      • close

        public ChannelFuture close()
        Description copied from interface: Channel
        Closes this channel asynchronously. If this channel is bound or connected, it will be disconnected and unbound first. Once a channel is closed, it can not be open again. Calling this method on a closed channel has no effect. Please note that this method always returns the same future instance.
        Specified by:
        close in interface Channel
        Returns:
        the ChannelFuture which will be notified when the close request succeeds or fails
      • getCloseFuture

        public ChannelFuture getCloseFuture()
        Description copied from interface: Channel
        Returns the ChannelFuture which will be notified when this channel is closed. This method always returns the same future instance.
        Specified by:
        getCloseFuture in interface Channel
      • connect

        public ChannelFuture connect​(SocketAddress remoteAddress)
        Description copied from interface: Channel
        Connects this channel to the specified remote address asynchronously.
        Specified by:
        connect in interface Channel
        Parameters:
        remoteAddress - where to connect
        Returns:
        the ChannelFuture which will be notified when the connection request succeeds or fails
      • disconnect

        public ChannelFuture disconnect()
        Description copied from interface: Channel
        Disconnects this channel from the current remote address asynchronously.
        Specified by:
        disconnect in interface Channel
        Returns:
        the ChannelFuture which will be notified when the disconnection request succeeds or fails
      • setInterestOps

        public ChannelFuture setInterestOps​(int interestOps)
        Description copied from interface: Channel
        Changes the interestOps of this channel asynchronously.
        Specified by:
        setInterestOps in interface Channel
        Parameters:
        interestOps - the new interestOps
        Returns:
        the ChannelFuture which will be notified when the interestOps change request succeeds or fails
      • getInternalInterestOps

        protected int getInternalInterestOps()
      • setInternalInterestOps

        protected void setInternalInterestOps​(int interestOps)
        Sets the interestOps property of this channel immediately. This method is intended to be called by an internal component - please do not call it unless you know what you are doing.
      • isReadable

        public boolean isReadable()
        Description copied from interface: Channel
        Returns true if and only if the I/O thread will read a message from this channel. This method is a shortcut to the following code:
         return (getInterestOps() & OP_READ) != 0;
         
        Specified by:
        isReadable in interface Channel
      • isWritable

        public boolean isWritable()
        Description copied from interface: Channel
        Returns true if and only if the I/O thread will perform the requested write operation immediately. Any write requests made when this method returns false are queued until the I/O thread is ready to process the queued write requests. This method is a shortcut to the following code:
         return (getInterestOps() & OP_WRITE) == 0;
         
        Specified by:
        isWritable in interface Channel
      • getUserDefinedWritability

        public final boolean getUserDefinedWritability​(int index)
        Description copied from interface: Channel
        Returns true if and only if the user-defined writability flag at the specified index is set to true.
        Specified by:
        getUserDefinedWritability in interface Channel
      • setUserDefinedWritability

        public final void setUserDefinedWritability​(int index,
                                                    boolean writable)
        Description copied from interface: Channel
        Sets a user-defined writability flag at the specified index.
        Specified by:
        setUserDefinedWritability in interface Channel
      • setWritable

        protected boolean setWritable()
      • setUnwritable

        protected boolean setUnwritable()
      • setReadable

        public ChannelFuture setReadable​(boolean readable)
        Description copied from interface: Channel
        Suspends or resumes the read operation of the I/O thread asynchronously. This method is a shortcut to the following code:
         int interestOps = getInterestOps();
         if (readable) {
             setInterestOps(interestOps | OP_READ);
         } else {
             setInterestOps(interestOps & ~OP_READ);
         }
         
        Specified by:
        setReadable in interface Channel
        Parameters:
        readable - true to resume the read operation and false to suspend the read operation
        Returns:
        the ChannelFuture which will be notified when the interestOps change request succeeds or fails
      • write

        public ChannelFuture write​(Object message,
                                   SocketAddress remoteAddress)
        Description copied from interface: Channel
        Sends a message to this channel asynchronously. It has an additional parameter that allows a user to specify where to send the specified message instead of this channel's current remote address. If this channel was created by a connectionless transport (e.g. DatagramChannel) and is not connected yet, you must specify non-null address. Otherwise, the write request will fail with NotYetConnectedException and an 'exceptionCaught' event will be triggered.
        Specified by:
        write in interface Channel
        Parameters:
        message - the message to write
        remoteAddress - where to send the specified message. This method is identical to Channel.write(Object) if null is specified here.
        Returns:
        the ChannelFuture which will be notified when the write request succeeds or fails
      • getAttachment

        public Object getAttachment()
        Description copied from interface: Channel
        Retrieves an object which is attached to this Channel.
        Specified by:
        getAttachment in interface Channel
        Returns:
        null if no object was attached or null was attached
      • setAttachment

        public void setAttachment​(Object attachment)
        Description copied from interface: Channel
        Attaches an object to this Channel to store a stateful information
        Specified by:
        setAttachment in interface Channel