Class AbstractChannel

java.lang.Object
org.jboss.netty.channel.AbstractChannel
All Implemented Interfaces:
Comparable<Channel>, Channel
Direct Known Subclasses:
AbstractNioChannel, AbstractOioChannel, AbstractServerChannel, DefaultLocalChannel, EmbeddedChannel, HttpTunnelingClientSocketChannel

public abstract class AbstractChannel extends Object implements Channel
A skeletal Channel implementation.
  • Field Details

  • Constructor Details

    • 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 Details

    • allocateId

      private static Integer allocateId(Channel channel)
    • 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.
    • getFactory

      public ChannelFactory getFactory()
      Description copied from interface: Channel
      Returns the ChannelFactory which created this channel.
      Specified by:
      getFactory in interface Channel
    • getPipeline

      public ChannelPipeline getPipeline()
      Description copied from interface: Channel
      Returns the ChannelPipeline which handles ChannelEvents associated with this channel.
      Specified by:
      getPipeline in interface Channel
    • getSucceededFuture

      protected ChannelFuture getSucceededFuture()
      Returns the cached SucceededChannelFuture instance.
    • getUnsupportedOperationFuture

      protected ChannelFuture getUnsupportedOperationFuture()
      Returns the FailedChannelFuture whose cause is an UnsupportedOperationException.
    • 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
    • compareTo

      public final int compareTo(Channel o)
      Compares the ID of the two channels.
      Specified by:
      compareTo in interface Comparable<Channel>
    • 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
    • getInterestOps

      public int getInterestOps()
      Description copied from interface: Channel
      Returns the current interestOps of this channel.
      Specified by:
      getInterestOps in interface Channel
      Returns:
      Channel.OP_NONE, Channel.OP_READ, Channel.OP_WRITE, or Channel.OP_READ_WRITE
    • 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() invalid input: '&' 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() invalid input: '&' 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
    • setUserDefinedWritability

      private void setUserDefinedWritability(int index)
    • clearUserDefinedWritability

      private void clearUserDefinedWritability(int index)
    • writabilityMask

      private static int writabilityMask(int index)
    • 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 invalid input: '&' ~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)
      Description copied from interface: Channel
      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 Channel.write(Object, SocketAddress) instead. 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
      Returns:
      the ChannelFuture which will be notified when the write 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
    • toString

      public String toString()
      Returns the String representation of this channel. The returned string contains the ID, local address, and remote address of this channel for easier identification.
      Overrides:
      toString in class Object
    • getIdString

      private String getIdString()