use of org.openkilda.messaging.error.ClientErrorMessage in project open-kilda by telstra.
the class KafkaMessagingChannel method onResponse.
/**
* Processes messages that come back to NB topics, usually messages come as a response to some request.
* If this response is for pended request then such request will be marked as completed.
* Messages might be chunked and not chunked. If chunked we need to wait until we receive the last one
* and only then collect all responses and complete the request.
*
* @param message received message.
*/
void onResponse(Message message) {
if (!isValid(message)) {
logger.warn("Skipping invalid message: {}", message);
return;
}
if (message instanceof ErrorMessage) {
ErrorMessage error = (ErrorMessage) message;
String errorMessage = String.format("Response message is error: %s", error);
if (message instanceof ClientErrorMessage) {
logger.warn(errorMessage);
} else {
logger.error(errorMessage);
}
completeWithError(error);
} else if (message instanceof InfoMessage) {
if (isChunkedPendingResponse(message)) {
processChunkedMessage((ChunkedInfoMessage) message);
} else if (pendingRequests.containsKey(message.getCorrelationId())) {
InfoMessage infoMessage = (InfoMessage) message;
CompletableFuture<InfoData> request = pendingRequests.remove(message.getCorrelationId());
if (request != null) {
request.complete(infoMessage.getData());
}
} else {
logger.trace("Received non-pending message");
}
}
}
Aggregations