public class TNonblockingSocket extends TNonblockingTransport
| Constructor and Description |
|---|
TNonblockingSocket(java.nio.channels.SocketChannel socketChannel)
Constructor that takes an already created socket.
|
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.
|
| Modifier and Type | Method and 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;
|
consumeBuffer, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, readAll, writepublic TNonblockingSocket(java.lang.String host,
int port)
throws java.io.IOException
java.io.IOExceptionpublic TNonblockingSocket(java.lang.String host,
int port,
int timeout)
throws java.io.IOException
host - port - TTransportExceptionjava.io.IOExceptionpublic TNonblockingSocket(java.nio.channels.SocketChannel socketChannel)
throws java.io.IOException
socketChannel - Already created SocketChannel objectjava.io.IOException - if there is an error setting up the streamspublic java.nio.channels.SelectionKey registerSelector(java.nio.channels.Selector selector,
int interests)
throws java.io.IOException
registerSelector in class TNonblockingTransportselector - java.io.IOExceptionpublic void setTimeout(int timeout)
timeout - Milliseconds timeoutpublic java.nio.channels.SocketChannel getSocketChannel()
public boolean isOpen()
isOpen in class TTransportpublic void open()
throws TTransportException
open in class TTransportTTransportException - if the transport could not be openedpublic int read(java.nio.ByteBuffer buffer)
throws java.io.IOException
read in class TNonblockingTransportjava.io.IOExceptionpublic int read(byte[] buf,
int off,
int len)
throws TTransportException
read in class TTransportbuf - Array to read intooff - Index to start reading atlen - Maximum number of bytes to readTTransportException - if there was an error reading datapublic int write(java.nio.ByteBuffer buffer)
throws java.io.IOException
write in class TNonblockingTransportjava.io.IOExceptionpublic void write(byte[] buf,
int off,
int len)
throws TTransportException
write in class TTransportbuf - The output data bufferoff - The offset to start writing fromlen - The number of bytes to writeTTransportException - if there was an error writing datapublic void flush()
throws TTransportException
flush in class TTransportTTransportException - if there was an error writing out data.public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class TTransportpublic boolean startConnect()
throws java.io.IOException
startConnect in class TNonblockingTransportjava.io.IOExceptionSocketChannel.connect(SocketAddress remote)public boolean finishConnect()
throws java.io.IOException
finishConnect in class TNonblockingTransportjava.io.IOExceptionSocketChannel.finishConnect()