Class TNonblockingSocket

    • Constructor Summary

      Constructors 
      Constructor Description
      TNonblockingSocket​(java.lang.String host, int port)  
      TNonblockingSocket​(java.lang.String host, int port, int timeout)
      Create a new nonblocking socket transport that will be connected to host:port.
      TNonblockingSocket​(java.nio.channels.SocketChannel socketChannel)
      Constructor that takes an already created socket.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the socket.
      boolean finishConnect()
      Non-blocking connection completion.
      void flush()
      Noop.
      java.nio.channels.SocketChannel getSocketChannel()
      Returns a reference to the underlying SocketChannel.
      boolean isOpen()
      Checks whether the socket is connected.
      void open()
      Do not call, the implementation provides its own lazy non-blocking connect.
      int read​(byte[] buf, int off, int len)
      Reads from the underlying input stream if not null.
      int read​(java.nio.ByteBuffer buffer)
      Perform a nonblocking read into buffer.
      java.nio.channels.SelectionKey registerSelector​(java.nio.channels.Selector selector, int interests)
      Register the new SocketChannel with our Selector, indicating we'd like to be notified when it's ready for I/O.
      void setTimeout​(int timeout)
      Sets the socket timeout, although this implementation never uses blocking operations so it is unused.
      boolean startConnect()
      Non-blocking connection initialization.
      void write​(byte[] buf, int off, int len)
      Writes to the underlying output stream if not null.
      int write​(java.nio.ByteBuffer buffer)
      Perform a nonblocking write of the data in buffer;
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TNonblockingSocket

        public TNonblockingSocket​(java.lang.String host,
                                  int port)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • TNonblockingSocket

        public TNonblockingSocket​(java.lang.String host,
                                  int port,
                                  int timeout)
                           throws java.io.IOException
        Create a new nonblocking socket transport that will be connected to host:port.
        Parameters:
        host -
        port -
        Throws:
        TTransportException
        java.io.IOException
      • TNonblockingSocket

        public TNonblockingSocket​(java.nio.channels.SocketChannel socketChannel)
                           throws java.io.IOException
        Constructor that takes an already created socket.
        Parameters:
        socketChannel - Already created SocketChannel object
        Throws:
        java.io.IOException - if there is an error setting up the streams
    • Method Detail

      • registerSelector

        public java.nio.channels.SelectionKey registerSelector​(java.nio.channels.Selector selector,
                                                               int interests)
                                                        throws java.io.IOException
        Register the new SocketChannel with our Selector, indicating we'd like to be notified when it's ready for I/O.
        Specified by:
        registerSelector in class TNonblockingTransport
        Parameters:
        selector -
        Returns:
        the selection key for this socket.
        Throws:
        java.io.IOException
      • setTimeout

        public void setTimeout​(int timeout)
        Sets the socket timeout, although this implementation never uses blocking operations so it is unused.
        Parameters:
        timeout - Milliseconds timeout
      • getSocketChannel

        public java.nio.channels.SocketChannel getSocketChannel()
        Returns a reference to the underlying SocketChannel.
      • isOpen

        public boolean isOpen()
        Checks whether the socket is connected.
        Specified by:
        isOpen in class TTransport
        Returns:
        True if the transport is open.
      • read

        public int read​(java.nio.ByteBuffer buffer)
                 throws java.io.IOException
        Perform a nonblocking read into buffer.
        Specified by:
        read in class TNonblockingTransport
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] buf,
                        int off,
                        int len)
                 throws TTransportException
        Reads from the underlying input stream if not null.
        Specified by:
        read in class TTransport
        Parameters:
        buf - Array to read into
        off - Index to start reading at
        len - Maximum number of bytes to read
        Returns:
        The number of bytes actually read
        Throws:
        TTransportException - if there was an error reading data
      • write

        public int write​(java.nio.ByteBuffer buffer)
                  throws java.io.IOException
        Perform a nonblocking write of the data in buffer;
        Specified by:
        write in class TNonblockingTransport
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] buf,
                          int off,
                          int len)
                   throws TTransportException
        Writes to the underlying output stream if not null.
        Specified by:
        write in class TTransport
        Parameters:
        buf - The output data buffer
        off - The offset to start writing from
        len - The number of bytes to write
        Throws:
        TTransportException - if there was an error writing data
      • close

        public void close()
        Closes the socket.
        Specified by:
        close in class TTransport
      • startConnect

        public boolean startConnect()
                             throws java.io.IOException
        Non-blocking connection initialization.
        Specified by:
        startConnect in class TNonblockingTransport
        Throws:
        java.io.IOException
        See Also:
        SocketChannel.connect(SocketAddress remote)
      • finishConnect

        public boolean finishConnect()
                              throws java.io.IOException
        Non-blocking connection completion.
        Specified by:
        finishConnect in class TNonblockingTransport
        Throws:
        java.io.IOException
        See Also:
        SocketChannel.finishConnect()