use of io.joynr.exceptions.JoynrRequestInterruptedException 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.JoynrRequestInterruptedException in project joynr by bmwcarit.
the class SerializationTest method serializeReplyWithJoynrRequestInterruptedException.
@Test
public void serializeReplyWithJoynrRequestInterruptedException() throws IOException {
JoynrRequestInterruptedException error = new JoynrRequestInterruptedException("detail message: JoynrRequestInterruptedException");
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