org.apache.kafka.clients
Interface KafkaClient

All Known Implementing Classes:
NetworkClient

public interface KafkaClient

The interface for NetworkClient


Method Summary
 void close()
          Close the client and disconnect from all nodes
 int inFlightRequestCount()
          The number of currently in-flight requests for which we have not yet returned a response
 boolean isReady(Node node, long now)
          Check if we are currently ready to send another request to the given node but don't attempt to connect if we aren't.
 Node leastLoadedNode(long now)
          Choose the node with the fewest outstanding requests.
 RequestHeader nextRequestHeader(ApiKeys key)
          Generate a request header for the next request
 java.util.List<ClientResponse> poll(java.util.List<ClientRequest> requests, long timeout, long now)
          Initiate the sending of the given requests and return any completed responses.
 boolean ready(Node node, long now)
          Initiate a connection to the given node (if necessary), and return true if already connected.
 void wakeup()
          Wake up the client if it is currently blocked waiting for I/O
 

Method Detail

isReady

boolean isReady(Node node,
                long now)
Check if we are currently ready to send another request to the given node but don't attempt to connect if we aren't.

Parameters:
node - The node to check
now - The current timestamp

ready

boolean ready(Node node,
              long now)
Initiate a connection to the given node (if necessary), and return true if already connected. The readiness of a node will change only when poll is invoked.

Parameters:
node - The node to connect to.
now - The current time
Returns:
true iff we are ready to immediately initiate the sending of another request to the given node.

poll

java.util.List<ClientResponse> poll(java.util.List<ClientRequest> requests,
                                    long timeout,
                                    long now)
Initiate the sending of the given requests and return any completed responses. Requests can only be sent on ready connections.

Parameters:
requests - The requests to send
timeout - The maximum amount of time to wait for responses in ms
now - The current time in ms
Throws:
java.lang.IllegalStateException - If a request is sent to an unready node

leastLoadedNode

Node leastLoadedNode(long now)
Choose the node with the fewest outstanding requests. This method will prefer a node with an existing connection, but will potentially choose a node for which we don't yet have a connection if all existing connections are in use.

Parameters:
now - The current time in ms
Returns:
The node with the fewest in-flight requests.

inFlightRequestCount

int inFlightRequestCount()
The number of currently in-flight requests for which we have not yet returned a response


nextRequestHeader

RequestHeader nextRequestHeader(ApiKeys key)
Generate a request header for the next request

Parameters:
key - The API key of the request

wakeup

void wakeup()
Wake up the client if it is currently blocked waiting for I/O


close

void close()
Close the client and disconnect from all nodes