Package org.apache.thrift.transport
Class TNonblockingSocket
java.lang.Object
org.apache.thrift.transport.TTransport
org.apache.thrift.transport.TEndpointTransport
org.apache.thrift.transport.TNonblockingTransport
org.apache.thrift.transport.TNonblockingSocket
- All Implemented Interfaces:
Closeable,AutoCloseable
Transport for use with async client.
-
Field Summary
Fields inherited from class org.apache.thrift.transport.TEndpointTransport
knownMessageSize, remainingMessageSize -
Constructor Summary
ConstructorsConstructorDescriptionTNonblockingSocket(String host, int port) TNonblockingSocket(String host, int port, int timeout) Create a new nonblocking socket transport that will be connected to host:port.TNonblockingSocket(SocketChannel socketChannel) Constructor that takes an already created socket. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the socket.booleanNon-blocking connection completion.voidflush()Noop.Returns a reference to the underlying SocketChannel.booleanisOpen()Checks whether the socket is connected.voidopen()Do not call, the implementation provides its own lazy non-blocking connect.intread(byte[] buf, int off, int len) Reads from the underlying input stream if not null.intread(ByteBuffer buffer) Perform a nonblocking read into buffer.registerSelector(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.voidsetTimeout(int timeout) Sets the socket timeout, although this implementation never uses blocking operations so it is unused.booleanNon-blocking connection initialization.toString()voidwrite(byte[] buf, int off, int len) Writes to the underlying output stream if not null.intwrite(ByteBuffer buffer) Perform a nonblocking write of the data in buffer;Methods inherited from class org.apache.thrift.transport.TEndpointTransport
checkReadBytesAvailable, countConsumedMessageBytes, getConfiguration, getMaxFrameSize, getMaxMessageSize, resetConsumedMessageSize, setMaxFrameSize, updateKnownMessageSizeMethods inherited from class org.apache.thrift.transport.TTransport
consumeBuffer, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, readAll, write
-
Constructor Details
-
TNonblockingSocket
- Throws:
IOExceptionTTransportException
-
TNonblockingSocket
public TNonblockingSocket(String host, int port, int timeout) throws IOException, TTransportException Create a new nonblocking socket transport that will be connected to host:port.- Parameters:
host-port-- Throws:
IOExceptionTTransportException
-
TNonblockingSocket
Constructor that takes an already created socket.- Parameters:
socketChannel- Already created SocketChannel object- Throws:
IOException- if there is an error setting up the streamsTTransportException
-
-
Method Details
-
registerSelector
Register the new SocketChannel with our Selector, indicating we'd like to be notified when it's ready for I/O.- Specified by:
registerSelectorin classTNonblockingTransport- Parameters:
selector-- Returns:
- the selection key for this socket.
- Throws:
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
Returns a reference to the underlying SocketChannel. -
isOpen
public boolean isOpen()Checks whether the socket is connected.- Specified by:
isOpenin classTTransport- Returns:
- True if the transport is open.
-
open
Do not call, the implementation provides its own lazy non-blocking connect.- Specified by:
openin classTTransport- Throws:
TTransportException- if the transport could not be opened
-
read
Perform a nonblocking read into buffer.- Overrides:
readin classTTransport- Parameters:
buffer- The buffer into which bytes are to be transferred- Returns:
- The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream
- Throws:
TTransportException- if there was an error reading data
-
read
Reads from the underlying input stream if not null.- Specified by:
readin classTTransport- Parameters:
buf- Array to read intooff- Index to start reading atlen- Maximum number of bytes to read- Returns:
- The number of bytes actually read
- Throws:
TTransportException- if there was an error reading data
-
write
Perform a nonblocking write of the data in buffer;- Overrides:
writein classTTransport- Parameters:
buffer- The buffer from which bytes are to be retrieved- Returns:
- The number of bytes written, possibly zero
- Throws:
TTransportException- if there was an error writing data
-
write
Writes to the underlying output stream if not null.- Specified by:
writein classTTransport- Parameters:
buf- The output data bufferoff- The offset to start writing fromlen- The number of bytes to write- Throws:
TTransportException- if there was an error writing data
-
flush
Noop.- Overrides:
flushin classTTransport- Throws:
TTransportException- if there was an error writing out data.
-
close
public void close()Closes the socket.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classTTransport
-
startConnect
Non-blocking connection initialization.- Specified by:
startConnectin classTNonblockingTransport- Throws:
IOException- See Also:
-
finishConnect
Non-blocking connection completion.- Specified by:
finishConnectin classTNonblockingTransport- Throws:
IOException- See Also:
-
toString
-