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");
}
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));
}
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;
}
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;
}
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);
}
Aggregations