Class TNonblockingMultiFetchClient

java.lang.Object
org.apache.thrift.TNonblockingMultiFetchClient

public class TNonblockingMultiFetchClient extends Object
This class uses a single thread to set up non-blocking sockets to a set of remote servers (hostname and port pairs), and sends a same request to all these servers. It then fetches responses from servers.

Parameters: int maxRecvBufBytesPerServer - an upper limit for receive buffer size per server (in byte). If a response from a server exceeds this limit, the client will not allocate memory or read response data for it.

int fetchTimeoutSeconds - time limit for fetching responses from all servers (in second). After the timeout, the fetch job is stopped and available responses are returned.

ByteBuffer requestBuf - request message that is sent to all servers.

Output: Responses are stored in an array of ByteBuffers. Index of elements in this array corresponds to index of servers in the server list. Content in a ByteBuffer may be in one of the following forms: 1. First 4 bytes form an integer indicating length of following data, then followed by the data. 2. First 4 bytes form an integer indicating length of following data, then followed by nothing - this happens when the response data size exceeds maxRecvBufBytesPerServer, and the client will not read any response data. 3. No data in the ByteBuffer - this happens when the server does not return any response within fetchTimeoutSeconds.

In some special cases (no servers are given, fetchTimeoutSeconds less than or equal to 0, requestBuf is null), the return is null.

Note: It assumes all remote servers are TNonblockingServers and use TFramedTransport.

  • Constructor Details

    • TNonblockingMultiFetchClient

      public TNonblockingMultiFetchClient(int maxRecvBufBytesPerServer, int fetchTimeoutSeconds, ByteBuffer requestBuf, List<InetSocketAddress> servers)
  • Method Details

    • getMaxRecvBufBytesPerServer

      public int getMaxRecvBufBytesPerServer()
    • getFetchTimeoutSeconds

      public int getFetchTimeoutSeconds()
    • getRequestBuf

      public ByteBuffer getRequestBuf()
      Returns a copy of requestBuf, so that requestBuf will not be modified by others.
      Returns:
      a copy of requestBuf.
    • getServerList

      public List<InetSocketAddress> getServerList()
    • getFetchStats

      public TNonblockingMultiFetchStats getFetchStats()
    • fetch

      public ByteBuffer[] fetch()
      Main entry function for fetching from servers.
      Returns:
      The fetched data.