/** * Get an error response for a request with specified throttle time in the response if applicable */ public abstract AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e);
@Override public final String toString() { return toString(true); }
private AbstractResponse sendKafkaRequestReceiveResponse(String node, ApiKeys apiKey, AbstractRequest request) throws IOException { RequestHeader header = new RequestHeader(apiKey, request.version(), "someclient", nextCorrelationId++); Send send = request.toSend(node, header); selector.send(send); ByteBuffer responseBuffer = waitForResponse(); return NetworkClient.parseResponse(responseBuffer, header); }
private void checkErrorResponse(AbstractRequest req, Throwable e) throws Exception { checkResponse(req.getErrorResponse(e), req.version()); }
private void checkRequest(AbstractRequest req, boolean checkEqualityAndHashCode) throws Exception { // Check that we can serialize, deserialize and serialize again // Check for equality and hashCode only if indicated Struct struct = req.toStruct(); AbstractRequest deserialized = (AbstractRequest) deserialize(req, struct, req.version()); Struct struct2 = deserialized.toStruct(); if (checkEqualityAndHashCode) { assertEquals(struct, struct2); assertEquals(struct.hashCode(), struct2.hashCode()); } }
public String toString(boolean verbose) { return toStruct().toString(); }
private void handleApiVersionsResponse(List<ClientResponse> responses, InFlightRequest req, long now, ApiVersionsResponse apiVersionsResponse) { final String node = req.destination; if (apiVersionsResponse.error() != Errors.NONE) { if (req.request.version() == 0 || apiVersionsResponse.error() != Errors.UNSUPPORTED_VERSION) { log.warn("Received error {} from node {} when making an ApiVersionsRequest with correlation id {}. Disconnecting.", apiVersionsResponse.error(), node, req.header.correlationId()); this.selector.close(node); processDisconnection(responses, node, now, ChannelState.LOCAL_CLOSE); } else { nodesNeedingApiVersionsFetch.put(node, new ApiVersionsRequest.Builder((short) 0)); } return; } NodeApiVersions nodeVersionInfo = new NodeApiVersions(apiVersionsResponse.apiVersions()); apiVersions.update(node, nodeVersionInfo); this.connectionStates.ready(node); log.debug("Recorded API versions for node {}: {}", node, nodeVersionInfo); }
public Send toSend(String destination, RequestHeader header) { return new NetworkSend(destination, serialize(header)); }
public RequestAndSize parseRequest(ByteBuffer buffer) { if (isUnsupportedApiVersionsRequest()) { // Unsupported ApiVersion requests are treated as v0 requests and are not parsed ApiVersionsRequest apiVersionsRequest = new ApiVersionsRequest((short) 0, header.apiVersion()); return new RequestAndSize(apiVersionsRequest, 0); } else { ApiKeys apiKey = header.apiKey(); try { short apiVersion = header.apiVersion(); Struct struct = apiKey.parseRequest(apiVersion, buffer); AbstractRequest body = AbstractRequest.parseRequest(apiKey, apiVersion, struct); return new RequestAndSize(body, struct.sizeOf()); } catch (Throwable ex) { throw new InvalidRequestException("Error getting request for apiKey: " + apiKey + ", apiVersion: " + header.apiVersion() + ", connectionId: " + connectionId + ", listenerName: " + listenerName + ", principal: " + principal, ex); } } }
Request(ChannelHandlerContext ctx, ByteBuffer buffer) { this.requestId = buffer.getShort(); buffer.rewind(); header = RequestHeader.parse(buffer); if (header.apiKey() == ApiKeys.API_VERSIONS.id && !Protocol.apiVersionSupported(header.apiKey(), header.apiVersion())) { body = new ApiVersionsRequest(); } else { body = AbstractRequest.getRequest(header.apiKey(), header.apiVersion(), buffer); } this.clientAddress = ((InetSocketAddress) ctx.getChannel().getRemoteAddress()).getAddress(); }
private void doSend(ClientRequest clientRequest, boolean isInternalRequest, long now, AbstractRequest request) { String destination = clientRequest.destination(); RequestHeader header = clientRequest.makeHeader(request.version()); if (log.isDebugEnabled()) { int latestClientVersion = clientRequest.apiKey().latestVersion(); if (header.apiVersion() == latestClientVersion) { log.trace("Sending {} {} with correlation id {} to node {}", clientRequest.apiKey(), request, clientRequest.correlationId(), destination); } else { log.debug("Using older server API v{} to send {} {} with correlation id {} to node {}", header.apiVersion(), clientRequest.apiKey(), request, clientRequest.correlationId(), destination); } } Send send = request.toSend(destination, header); InFlightRequest inFlightRequest = new InFlightRequest( clientRequest, header, isInternalRequest, request, send, now); this.inFlightRequests.add(inFlightRequest); selector.send(send); }
/** * Get the error counts corresponding to an error response. This is overridden for requests * where response may be null (e.g produce with acks=0). */ public Map<Errors, Integer> errorCounts(Throwable e) { AbstractResponse response = getErrorResponse(0, e); if (response == null) throw new IllegalStateException("Error counts could not be obtained for request " + this); else return response.errorCounts(); }
if (apiKey != ApiKeys.SASL_AUTHENTICATE) { IllegalSaslStateException e = new IllegalSaslStateException("Unexpected Kafka request of type " + apiKey + " during SASL authentication."); buildResponseOnAuthenticateFailure(requestContext, requestAndSize.request.getErrorResponse(e)); throw e;