Search in sources :

Example 1 with ClientErrorMessage

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");
        }
    }
}
Also used : ClientErrorMessage(org.openkilda.messaging.error.ClientErrorMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) InfoData(org.openkilda.messaging.info.InfoData) ClientErrorMessage(org.openkilda.messaging.error.ClientErrorMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage)

Aggregations

ClientErrorMessage (org.openkilda.messaging.error.ClientErrorMessage)1 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)1 ChunkedInfoMessage (org.openkilda.messaging.info.ChunkedInfoMessage)1 InfoData (org.openkilda.messaging.info.InfoData)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1