Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Define a RequestInfo interface:

Code Block
languagejava
titleRequestInfo Interface
linenumberstrue
public interface RequestInfo {
  
  /* @return the request header that contains information such as API key, API version, client ID and etc.
   */
  public RequestHeader getHeader();
  
  /* @return IP address of the client that made this request
   */
  public InetAddress getClientAddress();
  
  /* @return principal of the client that made this request
   */
  public KafkaPrincipal getPrincipal();
  
  /* @return size in bytes of the body of this request
   */
  public int getBodySize();
  
  /* This method should only be invoked if the request is of type ApiKeys.PRODUCE. Otherwise, an exception is thrown.
   * @return a map of topic name to the number of bytes that are supposed to be produced to this topic in this request
   */
  public Map<String, Long> getProduceToTopicSizeInBytes();

  /* This method should only be invoked if the request is of type ApiKeys.PRODUCE. Otherwise, an exception is thrown.
   * @return a map of topic name to the number of records that are supposed to be produced to this topic in this request
   */
  public Map<String, Long> getProduceToTopicRecordCount();
}

...

Define a ResponseInfo interface:

Code Block
languagejava
titleResponseInfo Interface
linenumberstrue
public interface ResponseInfo {
  /* @return a map of error to its count of occurrence.
   */
  public Map<Errors, Integer> getErrorCounts();

  /* This method should only be invoked if the response is of type ApiKeys.FETCH. Otherwise, an exception is thrown.
   * @return a map of topic partition to the number of bytes that are fetched from this topic partition.
   */
  public Map<TopicPartition, Long> getFetchFromTopicPartitionSizeInBytes();
}

...

Define RequestAdapter class:

Code Block
languagejava
titleRequestInfo implementation
linenumberstrue
public class RequestAdapter implements RequestInfo {


	public RequestAdapter(RequestChannel.Request request) {
		// ...
	}
	// ...
}

...

Define ResponseAdapter class:

Code Block
languagejava
titleResponseInfo implementation
linenumberstrue
public class ResponseAdapter implements ResponseInfo {


	public ResponseAdapter(AbstractResponse response) {
		// ...
	}
	// ...
}

...