use of org.apache.kafka.common.network.Send in project kafka by apache.
the class FetchResponse method toSend.
public Send toSend(Struct responseStruct, int throttleTimeMs, String dest, RequestHeader requestHeader) {
Struct responseHeader = new ResponseHeader(requestHeader.correlationId()).toStruct();
// write the total size and the response header
ByteBuffer buffer = ByteBuffer.allocate(responseHeader.sizeOf() + 4);
buffer.putInt(responseHeader.sizeOf() + responseStruct.sizeOf());
responseHeader.writeTo(buffer);
buffer.rewind();
List<Send> sends = new ArrayList<>();
sends.add(new ByteBufferSend(dest, buffer));
addResponseData(responseStruct, throttleTimeMs, dest, sends);
return new MultiSend(dest, sends);
}
use of org.apache.kafka.common.network.Send in project apache-kafka-on-k8s by banzaicloud.
the class SaslAuthenticatorTest method sendKafkaRequestReceiveResponse.
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);
}
use of org.apache.kafka.common.network.Send in project apache-kafka-on-k8s by banzaicloud.
the class MockSelector method completeDelayedReceives.
private void completeDelayedReceives() {
for (Send completedSend : completedSends) {
Iterator<DelayedReceive> delayedReceiveIterator = delayedReceives.iterator();
while (delayedReceiveIterator.hasNext()) {
DelayedReceive delayedReceive = delayedReceiveIterator.next();
if (delayedReceive.source().equals(completedSend.destination())) {
completedReceives.add(delayedReceive.receive());
delayedReceiveIterator.remove();
}
}
}
}
use of org.apache.kafka.common.network.Send in project apache-kafka-on-k8s by banzaicloud.
the class FetchResponse method toSend.
@Override
protected Send toSend(String dest, ResponseHeader responseHeader, short apiVersion) {
Struct responseHeaderStruct = responseHeader.toStruct();
Struct responseBodyStruct = toStruct(apiVersion);
// write the total size and the response header
ByteBuffer buffer = ByteBuffer.allocate(responseHeaderStruct.sizeOf() + 4);
buffer.putInt(responseHeaderStruct.sizeOf() + responseBodyStruct.sizeOf());
responseHeaderStruct.writeTo(buffer);
buffer.rewind();
Queue<Send> sends = new ArrayDeque<>();
sends.add(new ByteBufferSend(dest, buffer));
addResponseData(responseBodyStruct, throttleTimeMs, dest, sends);
return new MultiSend(dest, sends);
}
use of org.apache.kafka.common.network.Send in project apache-kafka-on-k8s by banzaicloud.
the class NetworkClient method doSend.
private void doSend(ClientRequest clientRequest, boolean isInternalRequest, long now, AbstractRequest request) {
String nodeId = 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(), nodeId);
} else {
log.debug("Using older server API v{} to send {} {} with correlation id {} to node {}", header.apiVersion(), clientRequest.apiKey(), request, clientRequest.correlationId(), nodeId);
}
}
Send send = request.toSend(nodeId, header);
InFlightRequest inFlightRequest = new InFlightRequest(header, clientRequest.createdTimeMs(), clientRequest.destination(), clientRequest.callback(), clientRequest.expectResponse(), isInternalRequest, request, send, now);
this.inFlightRequests.add(inFlightRequest);
selector.send(inFlightRequest.send);
}
Aggregations