Search in sources :

Example 1 with JoynrMessageNotSentException

use of io.joynr.exceptions.JoynrMessageNotSentException in project joynr by bmwcarit.

the class CcMessageRouterTest method testScheduleExpiredMessageFails.

@Test
public void testScheduleExpiredMessageFails() throws Exception {
    joynrMessage.setTtlMs(ExpiryDate.fromRelativeTtl(1).getValue());
    joynrMessage.setTtlAbsolute(true);
    ImmutableMessage immutableMessage = joynrMessage.getImmutableMessage();
    Thread.sleep(5);
    try {
        messageRouter.route(immutableMessage);
    } catch (JoynrMessageNotSentException e) {
        verify(middlewareMessagingStubFactoryMock, never()).create(any(ChannelAddress.class));
        return;
    }
    fail("scheduling an expired message should throw");
}
Also used : ImmutableMessage(joynr.ImmutableMessage) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) Test(org.junit.Test)

Example 2 with JoynrMessageNotSentException

use of io.joynr.exceptions.JoynrMessageNotSentException in project joynr by bmwcarit.

the class MqttPahoClient method publishMessage.

@Override
public void publishMessage(String topic, byte[] serializedMessage, int qosLevel) {
    if (messagingSkeleton == null) {
        throw new JoynrDelayMessageException("MQTT Publish failed: messagingSkeleton has not been set yet");
    }
    if (maxMsgSizeBytes != 0 && serializedMessage.length > maxMsgSizeBytes) {
        throw new JoynrMessageNotSentException("MQTT Publish failed: maximum allowed message size of " + maxMsgSizeBytes + " bytes exceeded, actual size is " + serializedMessage.length + " bytes");
    }
    try {
        MqttMessage message = new MqttMessage();
        message.setPayload(serializedMessage);
        message.setQos(qosLevel);
        message.setRetained(false);
        logger.debug("MQTT Publish to: {}", topic);
        mqttClient.publish(topic, message);
    } catch (MqttException e) {
        logger.debug("MQTT Publish failed: {}. Error code {}", e.getMessage(), e.getReasonCode(), e);
        switch(e.getReasonCode()) {
            case MqttException.REASON_CODE_CLIENT_EXCEPTION:
                Throwable cause = e.getCause();
                if (cause != null) {
                    throw new JoynrDelayMessageException("MqttException: " + cause.getMessage());
                } else {
                    throw new JoynrDelayMessageException("MqttException: " + e.getMessage());
                }
            case MqttException.REASON_CODE_BROKER_UNAVAILABLE:
            case MqttException.REASON_CODE_CLIENT_DISCONNECTING:
            case MqttException.REASON_CODE_CLIENT_NOT_CONNECTED:
            case MqttException.REASON_CODE_CLIENT_TIMEOUT:
            case MqttException.REASON_CODE_CONNECTION_LOST:
            case MqttException.REASON_CODE_MAX_INFLIGHT:
            case MqttException.REASON_CODE_NO_MESSAGE_IDS_AVAILABLE:
            case MqttException.REASON_CODE_SERVER_CONNECT_ERROR:
            case MqttException.REASON_CODE_UNEXPECTED_ERROR:
            case MqttException.REASON_CODE_WRITE_TIMEOUT:
            case MqttException.REASON_CODE_CONNECT_IN_PROGRESS:
                throw new JoynrDelayMessageException("MqttException: " + e.getMessage());
            default:
                throw new JoynrMessageNotSentException(e.getMessage());
        }
    } catch (Exception e) {
        throw new JoynrMessageNotSentException(e.getMessage(), e);
    }
    logger.debug("Published message: " + new String(serializedMessage, Charsets.UTF_8));
}
Also used : MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) MqttException(org.eclipse.paho.client.mqttv3.MqttException) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) URISyntaxException(java.net.URISyntaxException) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) MqttException(org.eclipse.paho.client.mqttv3.MqttException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) MqttSecurityException(org.eclipse.paho.client.mqttv3.MqttSecurityException)

Example 3 with JoynrMessageNotSentException

use of io.joynr.exceptions.JoynrMessageNotSentException in project joynr by bmwcarit.

the class AbstractMessageRouter method createFailureAction.

private FailureAction createFailureAction(final ImmutableMessage message, final int retriesCount) {
    final FailureAction failureAction = new FailureAction() {

        final String messageId = message.getId();

        private boolean failureActionExecutedOnce = false;

        @Override
        public void execute(Throwable error) {
            synchronized (this) {
                if (failureActionExecutedOnce) {
                    logger.trace("Failure action for message with id {} already executed once. Ignoring further call.", messageId);
                    return;
                }
                failureActionExecutedOnce = true;
            }
            if (error instanceof JoynrShutdownException) {
                logger.warn("{}", error.getMessage());
                return;
            } else if (error instanceof JoynrMessageNotSentException) {
                logger.error(" ERROR SENDING:  aborting send of messageId: {}. Error: {}", new Object[] { messageId, error.getMessage() });
                callMessageProcessedListeners(messageId);
                return;
            }
            logger.warn("PROBLEM SENDING, will retry. messageId: {}. Error: {} Message: {}", new Object[] { messageId, error.getClass().getName(), error.getMessage() });
            long delayMs;
            if (error instanceof JoynrDelayMessageException) {
                delayMs = ((JoynrDelayMessageException) error).getDelayMs();
            } else {
                delayMs = createDelayWithExponentialBackoff(sendMsgRetryIntervalMs, retriesCount);
            }
            logger.error("Rescheduling messageId: {} with delay {} ms, TTL is: {}", messageId, delayMs, dateFormatter.format(message.getTtlMs()));
            try {
                routeInternal(message, delayMs, retriesCount + 1);
            } catch (Exception e) {
                logger.warn("Rescheduling of message failed (messageId {})", messageId);
                callMessageProcessedListeners(messageId);
            }
            return;
        }
    };
    return failureAction;
}
Also used : FailureAction(io.joynr.messaging.FailureAction) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) JoynrShutdownException(io.joynr.exceptions.JoynrShutdownException) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) JoynrShutdownException(io.joynr.exceptions.JoynrShutdownException) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 4 with JoynrMessageNotSentException

use of io.joynr.exceptions.JoynrMessageNotSentException in project joynr by bmwcarit.

the class RequestReplyManagerImpl method sendSyncRequest.

@Override
public Object sendSyncRequest(String fromParticipantId, DiscoveryEntryWithMetaInfo toDiscoveryEntry, Request request, SynchronizedReplyCaller synchronizedReplyCaller, MessagingQos messagingQos) {
    if (!running) {
        throw new IllegalStateException("Request: " + request.getRequestReplyId() + " failed. SenderImpl ID: " + System.identityHashCode(this) + ": joynr is shutting down");
    }
    final ArrayList<Object> responsePayloadContainer = new ArrayList<Object>(1);
    // the synchronizedReplyCaller will call notify on the responsePayloadContainer when a message arrives
    synchronizedReplyCaller.setResponseContainer(responsePayloadContainer);
    sendRequest(fromParticipantId, toDiscoveryEntry, request, messagingQos);
    long entryTime = System.currentTimeMillis();
    // saving all calling threads so that they can be interrupted at shutdown
    outstandingRequestThreads.add(Thread.currentThread());
    synchronized (responsePayloadContainer) {
        while (running && responsePayloadContainer.isEmpty() && entryTime + messagingQos.getRoundTripTtl_ms() > System.currentTimeMillis()) {
            try {
                responsePayloadContainer.wait(messagingQos.getRoundTripTtl_ms());
            } catch (InterruptedException e) {
                if (running) {
                    throw new JoynrRequestInterruptedException("Request: " + request.getRequestReplyId() + " interrupted.");
                }
                throw new JoynrShutdownException("Request: " + request.getRequestReplyId() + " interrupted by shutdown");
            }
        }
    }
    outstandingRequestThreads.remove(Thread.currentThread());
    if (responsePayloadContainer.isEmpty()) {
        throw new JoynrCommunicationException("Request: " + request.getRequestReplyId() + " failed. The response didn't arrive in time");
    }
    Object response = responsePayloadContainer.get(0);
    if (response instanceof Throwable) {
        Throwable error = (Throwable) response;
        throw new JoynrMessageNotSentException("Request: " + request.getRequestReplyId() + " failed: " + error.getMessage(), error);
    }
    return response;
}
Also used : JoynrShutdownException(io.joynr.exceptions.JoynrShutdownException) ArrayList(java.util.ArrayList) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException) JoynrRequestInterruptedException(io.joynr.exceptions.JoynrRequestInterruptedException) JoynrRequestInterruptedException(io.joynr.exceptions.JoynrRequestInterruptedException) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException)

Example 5 with JoynrMessageNotSentException

use of io.joynr.exceptions.JoynrMessageNotSentException in project joynr by bmwcarit.

the class SerializationTest method serializeReplyWithJoynrMessageNotSentException.

@Test
public void serializeReplyWithJoynrMessageNotSentException() throws IOException {
    JoynrMessageNotSentException error = new JoynrMessageNotSentException("detail message: JoynrMessageNotSentException");
    Reply reply = new Reply(UUID.randomUUID().toString(), error);
    String writeValueAsString = objectMapper.writeValueAsString(reply);
    System.out.println(writeValueAsString);
    Reply receivedReply = objectMapper.readValue(writeValueAsString, Reply.class);
    Assert.assertEquals(reply, receivedReply);
}
Also used : Reply(joynr.Reply) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) Test(org.junit.Test)

Aggregations

JoynrMessageNotSentException (io.joynr.exceptions.JoynrMessageNotSentException)8 JoynrDelayMessageException (io.joynr.exceptions.JoynrDelayMessageException)4 Test (org.junit.Test)4 JoynrShutdownException (io.joynr.exceptions.JoynrShutdownException)3 FailureAction (io.joynr.messaging.FailureAction)3 ImmutableMessage (joynr.ImmutableMessage)3 JoynrCommunicationException (io.joynr.exceptions.JoynrCommunicationException)2 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)2 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)2 SuccessAction (io.joynr.messaging.SuccessAction)2 JoynrChannelMissingException (io.joynr.exceptions.JoynrChannelMissingException)1 JoynrRequestInterruptedException (io.joynr.exceptions.JoynrRequestInterruptedException)1 JoynrMessagingError (io.joynr.messaging.datatypes.JoynrMessagingError)1 JoynrMessagingErrorCode (io.joynr.messaging.datatypes.JoynrMessagingErrorCode)1 HttpPost (io.joynr.messaging.http.operation.HttpPost)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 Reply (joynr.Reply)1