Interface Channel

    • Method Detail

      • getId

        java.lang.Integer getId()
        Returns the unique integer ID of this channel.
      • getParent

        Channel getParent()
        Returns the parent of this channel.
        Returns:
        the parent channel. null if this channel does not have a parent channel.
      • getConfig

        ChannelConfig getConfig()
        Returns the configuration of this channel.
      • isOpen

        boolean isOpen()
        Returns true if and only if this channel is open.
      • isBound

        boolean isBound()
        Returns true if and only if this channel is bound to a local address.
      • isConnected

        boolean isConnected()
        Returns true if and only if this channel is connected to a remote address.
      • getLocalAddress

        java.net.SocketAddress getLocalAddress()
        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.
        Returns:
        the local address of this channel. null if this channel is not bound.
      • getRemoteAddress

        java.net.SocketAddress getRemoteAddress()
        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.
        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 MessageEvent.getRemoteAddress() to determine the origination of the received message as this method will return null.
      • write

        ChannelFuture write​(java.lang.Object message)
        Sends a message to this channel asynchronously. If this channel was created by a connectionless transport (e.g. DatagramChannel) and is not connected yet, you have to call write(Object, SocketAddress) instead. Otherwise, the write request will fail with NotYetConnectedException and an 'exceptionCaught' event will be triggered.
        Parameters:
        message - the message to write
        Returns:
        the ChannelFuture which will be notified when the write request succeeds or fails
        Throws:
        java.lang.NullPointerException - if the specified message is null
      • write

        ChannelFuture write​(java.lang.Object message,
                            java.net.SocketAddress remoteAddress)
        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.
        Parameters:
        message - the message to write
        remoteAddress - where to send the specified message. This method is identical to write(Object) if null is specified here.
        Returns:
        the ChannelFuture which will be notified when the write request succeeds or fails
        Throws:
        java.lang.NullPointerException - if the specified message is null
      • bind

        ChannelFuture bind​(java.net.SocketAddress localAddress)
        Binds this channel to the specified local address asynchronously.
        Parameters:
        localAddress - where to bind
        Returns:
        the ChannelFuture which will be notified when the bind request succeeds or fails
        Throws:
        java.lang.NullPointerException - if the specified address is null
      • connect

        ChannelFuture connect​(java.net.SocketAddress remoteAddress)
        Connects this channel to the specified remote address asynchronously.
        Parameters:
        remoteAddress - where to connect
        Returns:
        the ChannelFuture which will be notified when the connection request succeeds or fails
        Throws:
        java.lang.NullPointerException - if the specified address is null
      • disconnect

        ChannelFuture disconnect()
        Disconnects this channel from the current remote address asynchronously.
        Returns:
        the ChannelFuture which will be notified when the disconnection request succeeds or fails
      • unbind

        ChannelFuture unbind()
        Unbinds this channel from the current local address asynchronously.
        Returns:
        the ChannelFuture which will be notified when the unbind request succeeds or fails
      • close

        ChannelFuture close()
        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.
        Returns:
        the ChannelFuture which will be notified when the close request succeeds or fails
      • getCloseFuture

        ChannelFuture getCloseFuture()
        Returns the ChannelFuture which will be notified when this channel is closed. This method always returns the same future instance.
      • isReadable

        boolean isReadable()
        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;
         
      • isWritable

        boolean isWritable()
        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;
         
      • setInterestOps

        ChannelFuture setInterestOps​(int interestOps)
        Changes the interestOps of this channel asynchronously.
        Parameters:
        interestOps - the new interestOps
        Returns:
        the ChannelFuture which will be notified when the interestOps change request succeeds or fails
      • setReadable

        ChannelFuture setReadable​(boolean readable)
        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);
         }
         
        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
      • getUserDefinedWritability

        boolean getUserDefinedWritability​(int index)
        Returns true if and only if the user-defined writability flag at the specified index is set to true.
      • setUserDefinedWritability

        void setUserDefinedWritability​(int index,
                                       boolean isWritable)
        Sets a user-defined writability flag at the specified index.
      • getAttachment

        java.lang.Object getAttachment()
        Retrieves an object which is attached to this Channel.
        Returns:
        null if no object was attached or null was attached
      • setAttachment

        void setAttachment​(java.lang.Object attachment)
        Attaches an object to this Channel to store a stateful information