private void checkErrorResponse(AbstractRequest req, Throwable e) throws Exception { checkResponse(req.getErrorResponse(e), req.version()); }
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); }
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); }
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 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()); } }