org.apache.thrift.transport
Class TNonblockingSocket

java.lang.Object
  extended by org.apache.thrift.transport.TTransport
      extended by org.apache.thrift.transport.TNonblockingTransport
          extended by org.apache.thrift.transport.TNonblockingSocket

public class TNonblockingSocket
extends TNonblockingTransport

Socket implementation of the TTransport interface. To be commented soon!


Constructor Summary
TNonblockingSocket(java.nio.channels.SocketChannel socketChannel)
          Constructor that takes an already created socket.
 
Method Summary
 void close()
          Closes the socket.
 void flush()
          Flushes the underlying output stream if not null.
 java.net.Socket getSocket()
          Returns a reference to the underlying socket.
 boolean isOpen()
          Checks whether the socket is connected.
 void open()
          Connects the socket, creating a new socket object if necessary.
 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 this socket with the specified selector for both read and write operations.
 void setTimeout(int timeout)
          Sets the socket timeout
 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 org.apache.thrift.transport.TTransport
consumeBuffer, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, readAll, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TNonblockingSocket

public TNonblockingSocket(java.nio.channels.SocketChannel socketChannel)
                   throws TTransportException
Constructor that takes an already created socket.

Parameters:
socketChannel - Already created SocketChannel object
Throws:
TTransportException - 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 this socket with the specified selector for both read and write operations.

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

Parameters:
timeout - Milliseconds timeout

getSocket

public java.net.Socket getSocket()
Returns a reference to the underlying socket.


isOpen

public boolean isOpen()
Checks whether the socket is connected.

Specified by:
isOpen in class TTransport
Returns:
True if the transport is open.

open

public void open()
          throws TTransportException
Connects the socket, creating a new socket object if necessary.

Specified by:
open in class TTransport
Throws:
TTransportException - if the transport could not be opened

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

flush

public void flush()
           throws TTransportException
Flushes the underlying output stream if not null.

Overrides:
flush in class TTransport
Throws:
TTransportException - if there was an error writing out data.

close

public void close()
Closes the socket.

Specified by:
close in class TTransport