Interface ChannelProvider

All Known Implementing Classes:
DatagramChannelProvider, SocketChannelProvider

public interface ChannelProvider
Used by ChannelConnections for I/O and wraps a java.nio channel.
  • Method Details

    • init

      void init(ChannelConnection connection, SelectionKey key)
      Initialized this ChannelProvider.
      Parameters:
      connection - The ChannelConnection this ChannelProvider is for
      key - The selection key of the connection
    • connect

      boolean connect(SocketAddress remote, int timeout) throws IOException
      Connects the underlying java.nio channel to the given remote address.
      Parameters:
      remote - The remote address
      timeout - If applicable, the connection attempt will cancel after this time in milliseconds
      Returns:
      true if the channel connected immediately
      Throws:
      IOException - If an IO error occurs
    • close

      void close() throws IOException
      Closes the underlying java.nio channel.
      Throws:
      IOException - If an IO error occurs
    • read

      int read(ByteBuffer buf) throws IOException
      Reads data from the underlying java.nio channel into the given buffer.
      Parameters:
      buf - The buffer to write data to
      Returns:
      The number of bytes read
      Throws:
      IOException - If an IO error occurs
    • write

      int write(ByteBuffer buf) throws IOException
      Writes data from the given buffer to the underlying java.nio channel.
      Parameters:
      buf - The buffer to read from
      Returns:
      The number of bytes written
      Throws:
      IOException - If an IO error occurs
    • writeBacklogStarted

      void writeBacklogStarted()
      Called by the ChannelConnection to indicate write backlog has started because the outgoing socket buffer is full.
    • writeBacklogEnded

      void writeBacklogEnded()
      Called by the ChannelConnection to indicate write backlog has ended.
    • setReadBlock

      void setReadBlock(boolean block)
      If given true, the underlying selection key should stop listening for read ops.
      Parameters:
      block - Whether to block read events
    • isAvailable

      boolean isAvailable()
      Returns true if the underlying java.nio channel is connected.
      Returns:
      true if the channel is connected
    • getSelectionKey

      SelectionKey getSelectionKey()
      Returns the SelectionKey of this ChannelProvider.
      Returns:
      The SelectionKey
      Since:
      1.6.1