Search in sources :

Example 1 with JoynrRequestInterruptedException

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;
}
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 2 with JoynrRequestInterruptedException

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);
}
Also used : Reply(joynr.Reply) JoynrRequestInterruptedException(io.joynr.exceptions.JoynrRequestInterruptedException) Test(org.junit.Test)

Aggregations

JoynrRequestInterruptedException (io.joynr.exceptions.JoynrRequestInterruptedException)2 JoynrCommunicationException (io.joynr.exceptions.JoynrCommunicationException)1 JoynrMessageNotSentException (io.joynr.exceptions.JoynrMessageNotSentException)1 JoynrShutdownException (io.joynr.exceptions.JoynrShutdownException)1 ArrayList (java.util.ArrayList)1 Reply (joynr.Reply)1 Test (org.junit.Test)1