Class SocketChannelEndPoint

All Implemented Interfaces:
Closeable, AutoCloseable, EndPoint, ManagedSelector.Selectable
Direct Known Subclasses:
NetworkTrafficSocketChannelEndPoint

public class SocketChannelEndPoint extends AbstractEndPoint implements ManagedSelector.Selectable
Channel End Point.

Holds the channel and socket for an NIO endpoint.

  • Constructor Details

  • Method Details

    • getLocalSocketAddress

      public SocketAddress getLocalSocketAddress()
      Specified by:
      getLocalSocketAddress in interface EndPoint
      Overrides:
      getLocalSocketAddress in class AbstractEndPoint
      Returns:
      the local SocketAddress to which this EndPoint is bound or null if this EndPoint is not bound to a Socket address.
    • getRemoteSocketAddress

      public SocketAddress getRemoteSocketAddress()
      Specified by:
      getRemoteSocketAddress in interface EndPoint
      Overrides:
      getRemoteSocketAddress in class AbstractEndPoint
      Returns:
      The remote SocketAddress to which this EndPoint is connected, or null if this EndPoint is not connected to a Socket address.
    • isOpen

      public boolean isOpen()
      Description copied from class: IdleTimeout
      This abstract method should be called to check if idle timeouts should still be checked.
      Specified by:
      isOpen in interface EndPoint
      Overrides:
      isOpen in class AbstractEndPoint
      Returns:
      True if the entity monitored should still be checked for idle timeouts
    • doShutdownOutput

      protected void doShutdownOutput()
      Overrides:
      doShutdownOutput in class AbstractEndPoint
    • doClose

      public void doClose()
      Overrides:
      doClose in class AbstractEndPoint
    • onClose

      public void onClose(Throwable cause)
      Description copied from interface: EndPoint

      Callback method invoked when this EndPoint is closed.

      Specified by:
      onClose in interface EndPoint
      Overrides:
      onClose in class AbstractEndPoint
      Parameters:
      cause - The reason for the close, or null if a normal close.
      See Also:
    • fill

      public int fill(ByteBuffer buffer) throws IOException
      Description copied from interface: EndPoint
      Fill the passed buffer with data from this endpoint. The bytes are appended to any data already in the buffer by writing from the buffers limit up to it's capacity. The limit is updated to include the filled bytes.
      Specified by:
      fill in interface EndPoint
      Parameters:
      buffer - The buffer to fill. The position and limit are modified during the fill. After the operation, the position is unchanged and the limit is increased to reflect the new data filled.
      Returns:
      an int value indicating the number of bytes filled or -1 if EOF is read or the input is shutdown.
      Throws:
      IOException - if the endpoint is closed.
    • flush

      public boolean flush(ByteBuffer... buffers) throws IOException
      Description copied from interface: EndPoint
      Flush data from the passed header/buffer to this endpoint. As many bytes as can be consumed are taken from the header/buffer position up until the buffer limit. The header/buffers position is updated to indicate how many bytes have been consumed.
      Specified by:
      flush in interface EndPoint
      Parameters:
      buffers - the buffers to flush
      Returns:
      True IFF all the buffers have been consumed and the endpoint has flushed the data to its destination (ie is not buffering any data).
      Throws:
      IOException - If the endpoint is closed or output is shutdown.
    • getChannel

      public SocketChannel getChannel()
    • getTransport

      public Object getTransport()
      Specified by:
      getTransport in interface EndPoint
      Returns:
      The underlying transport object (socket, channel, etc.)
    • needsFillInterest

      protected void needsFillInterest()
      Specified by:
      needsFillInterest in class AbstractEndPoint
    • onIncompleteFlush

      protected void onIncompleteFlush()
      Specified by:
      onIncompleteFlush in class AbstractEndPoint
    • onSelected

      public Runnable onSelected()
      Description copied from interface: ManagedSelector.Selectable
      Callback method invoked when a read or write events has been detected by the ManagedSelector for this endpoint.
      Specified by:
      onSelected in interface ManagedSelector.Selectable
      Returns:
      a job that may block or null
    • updateKey

      public void updateKey()
      Description copied from interface: ManagedSelector.Selectable
      Callback method invoked when all the keys selected by the ManagedSelector for this endpoint have been processed.
      Specified by:
      updateKey in interface ManagedSelector.Selectable
    • replaceKey

      public void replaceKey(SelectionKey newKey)
      Description copied from interface: ManagedSelector.Selectable
      Callback method invoked when the SelectionKey is replaced because the channel has been moved to a new selector.
      Specified by:
      replaceKey in interface ManagedSelector.Selectable
      Parameters:
      newKey - the new SelectionKey
    • toEndPointString

      public String toEndPointString()
      Overrides:
      toEndPointString in class AbstractEndPoint