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, write
public TNonblockingSocket(java.lang.String host, int port) throws java.io.IOException
java.io.IOException
public TNonblockingSocket(java.lang.String host, int port, int timeout) throws java.io.IOException
host
- port
- TTransportException
java.io.IOException
public 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 TNonblockingTransport
selector
- java.io.IOException
public void setTimeout(int timeout)
timeout
- Milliseconds timeoutpublic java.nio.channels.SocketChannel getSocketChannel()
public boolean isOpen()
isOpen
in class TTransport
public void open() throws TTransportException
open
in class TTransport
TTransportException
- if the transport could not be openedpublic int read(java.nio.ByteBuffer buffer) throws java.io.IOException
read
in class TNonblockingTransport
java.io.IOException
public int read(byte[] buf, int off, int len) throws TTransportException
read
in class TTransport
buf
- 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 TNonblockingTransport
java.io.IOException
public void write(byte[] buf, int off, int len) throws TTransportException
write
in class TTransport
buf
- 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 TTransport
TTransportException
- if there was an error writing out data.public void close()
close
in class TTransport
public boolean startConnect() throws java.io.IOException
startConnect
in class TNonblockingTransport
java.io.IOException
SocketChannel.connect(SocketAddress remote)
public boolean finishConnect() throws java.io.IOException
finishConnect
in class TNonblockingTransport
java.io.IOException
SocketChannel.finishConnect()