Search in sources :

Example 26 with MessagingQos

use of io.joynr.messaging.MessagingQos in project joynr by bmwcarit.

the class WebSocketTest method sendMessage.

private void sendMessage() throws Throwable {
    OneWayRequest request = new OneWayRequest("method", new Object[0], new Class<?>[0]);
    MessagingQos messagingQos = new MessagingQos(100000);
    ImmutableMessage msg = messageFactory.createOneWayRequest("fromID", "toID", request, messagingQos).getImmutableMessage();
    SuccessAction successAction = mock(SuccessAction.class);
    webSocketMessagingStub.transmit(msg, successAction, new FailureAction() {

        @Override
        public void execute(Throwable error) {
            Assert.fail(error.getMessage());
        }
    });
    Mockito.verify(messageRouterMock, Mockito.timeout(1000)).route(argThat(new SerializedDataOfImmutableMessageMatcher(msg)));
    Mockito.verify(successAction).execute();
}
Also used : OneWayRequest(joynr.OneWayRequest) MessagingQos(io.joynr.messaging.MessagingQos) SuccessAction(io.joynr.messaging.SuccessAction) FailureAction(io.joynr.messaging.FailureAction) ImmutableMessage(joynr.ImmutableMessage)

Example 27 with MessagingQos

use of io.joynr.messaging.MessagingQos in project joynr by bmwcarit.

the class ConsumerApplication method run.

@SuppressWarnings("checkstyle:methodlength")
@Override
public void run() {
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryTimeoutMs(10000);
    discoveryQos.setCacheMaxAgeMs(Long.MAX_VALUE);
    discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
    ProxyBuilder<SystemIntegrationTestProxy> proxyBuilder = runtime.getProxyBuilder(providerDomain, SystemIntegrationTestProxy.class);
    boolean success = false;
    try {
        systemIntegrationTestProxy = proxyBuilder.setMessagingQos(new MessagingQos(10000)).setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<SystemIntegrationTestProxy>() {

            @Override
            public void onProxyCreationFinished(SystemIntegrationTestProxy result) {
                LOG.info("proxy created");
                proxyCreated.release();
            }

            @Override
            public void onProxyCreationError(JoynrRuntimeException error) {
                LOG.error("error creating proxy");
            }
        });
        try {
            if (proxyCreated.tryAcquire(11000, TimeUnit.MILLISECONDS) == false) {
                throw new DiscoveryException("proxy not created in time");
            }
        } catch (InterruptedException e) {
            throw new DiscoveryException("proxy not created in time");
        }
        try {
            int addendA = 3333333;
            int addendB = 4444444;
            Integer sum = systemIntegrationTestProxy.add(addendA, addendB);
            if (sum != null && sum == (addendA + addendB)) {
                LOG.info("SIT RESULT success: Java consumer -> " + providerDomain + " (" + addendA + " + " + addendB + " =  " + sum + ")");
                success = true;
            }
        } catch (Exception e) {
        // fallthrough
        }
    } catch (DiscoveryException | JoynrCommunicationException e) {
    // fallthrough
    }
    if (!success) {
        LOG.info("SIT RESULT error: Java consumer -> " + providerDomain);
    }
    System.exit((success) ? 0 : 1);
}
Also used : SystemIntegrationTestProxy(joynr.test.SystemIntegrationTestProxy) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) DiscoveryException(io.joynr.exceptions.DiscoveryException) IOException(java.io.IOException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException) MessagingQos(io.joynr.messaging.MessagingQos) ProxyCreatedCallback(io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback) DiscoveryException(io.joynr.exceptions.DiscoveryException) SuppressWarnings(edu.umd.cs.findbugs.annotations.SuppressWarnings)

Example 28 with MessagingQos

use of io.joynr.messaging.MessagingQos in project joynr by bmwcarit.

the class PublicationManagerImpl method handleSubscriptionRequest.

private void handleSubscriptionRequest(PublicationInformation publicationInformation, SubscriptionRequest subscriptionRequest, ProviderContainer providerContainer) {
    final String subscriptionId = subscriptionRequest.getSubscriptionId();
    SubscriptionQos subscriptionQos = subscriptionRequest.getQos();
    MessagingQos messagingQos = createMessagingQos(subscriptionQos);
    try {
        Method method = findGetterForAttributeName(providerContainer.getProviderProxy().getClass(), subscriptionRequest.getSubscribedToName());
        triggerPublication(publicationInformation, providerContainer, method);
        boolean hasSubscriptionHeartBeat = subscriptionQos instanceof HeartbeatSubscriptionInformation;
        boolean isOnChangeSubscription = subscriptionQos instanceof OnChangeSubscriptionQos;
        if (hasSubscriptionHeartBeat || isOnChangeSubscription) {
            // TODO: send error subscription reply is periodMs < MIN_PERIOD_MS or periodMs > MAX_PERIOD_MS?
            final PublicationTimer timer = new PublicationTimer(publicationInformation, method, providerContainer, this, attributePollInterpreter);
            timer.startTimer();
            publicationTimers.put(subscriptionId, timer);
        }
        if (subscriptionQos instanceof OnChangeSubscriptionQos) {
            handleOnChangeSubscription(subscriptionRequest, providerContainer, subscriptionId);
        }
        dispatcher.sendSubscriptionReply(publicationInformation.providerParticipantId, publicationInformation.proxyParticipantId, new SubscriptionReply(subscriptionId), messagingQos);
    } catch (NoSuchMethodException e) {
        cancelPublicationCreation(subscriptionId);
        logger.error("Error subscribing: {}. The provider does not have the requested attribute", subscriptionRequest);
        sendSubscriptionReplyWithError(publicationInformation, subscriptionId, e, messagingQos);
    }
}
Also used : SubscriptionReply(joynr.SubscriptionReply) MessagingQos(io.joynr.messaging.MessagingQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) UnicastSubscriptionQos(joynr.UnicastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) Method(java.lang.reflect.Method) HeartbeatSubscriptionInformation(io.joynr.pubsub.HeartbeatSubscriptionInformation)

Example 29 with MessagingQos

use of io.joynr.messaging.MessagingQos in project joynr by bmwcarit.

the class PublicationManagerImpl method sendSubscriptionReplyWithError.

private void sendSubscriptionReplyWithError(SubscriptionException e, PublicationInformation publicationInformation, SubscriptionRequest subscriptionRequest) {
    SubscriptionQos subscriptionQos = subscriptionRequest.getQos();
    MessagingQos messagingQos = new MessagingQos();
    if (subscriptionQos.getExpiryDateMs() == SubscriptionQos.NO_EXPIRY_DATE) {
        messagingQos.setTtl_ms(SubscriptionQos.INFINITE_SUBSCRIPTION);
    } else {
        // TTL uplift will be done in JoynrMessageFactory
        messagingQos.setTtl_ms(subscriptionQos.getExpiryDateMs() - System.currentTimeMillis());
    }
    SubscriptionReply subscriptionReply = new SubscriptionReply(publicationInformation.getSubscriptionId(), e);
    dispatcher.sendSubscriptionReply(publicationInformation.providerParticipantId, publicationInformation.proxyParticipantId, subscriptionReply, messagingQos);
}
Also used : SubscriptionReply(joynr.SubscriptionReply) MessagingQos(io.joynr.messaging.MessagingQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) UnicastSubscriptionQos(joynr.UnicastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos)

Example 30 with MessagingQos

use of io.joynr.messaging.MessagingQos in project joynr by bmwcarit.

the class PublicationManagerImpl method sendSubscriptionPublication.

@Override
public void sendSubscriptionPublication(SubscriptionPublication publication, PublicationInformation publicationInformation) throws JoynrSendBufferFullException, JoynrMessageNotSentException, JsonGenerationException, JsonMappingException, IOException {
    MessagingQos messagingQos = new MessagingQos();
    // TTL uplift will be done in JoynrMessageFactory
    messagingQos.setTtl_ms(publicationInformation.getQos().getPublicationTtlMs());
    Set<String> toParticipantIds = new HashSet<>();
    toParticipantIds.add(publicationInformation.proxyParticipantId);
    dispatcher.sendSubscriptionPublication(publicationInformation.providerParticipantId, toParticipantIds, publication, messagingQos);
    publicationInformation.getState().updateTimeOfLastPublication();
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) HashSet(java.util.HashSet)

Aggregations

MessagingQos (io.joynr.messaging.MessagingQos)55 Test (org.junit.Test)23 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)19 MutableMessage (joynr.MutableMessage)15 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)11 Matchers.anyString (org.mockito.Matchers.anyString)11 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)9 SubscriptionRequest (joynr.SubscriptionRequest)9 Before (org.junit.Before)8 Properties (java.util.Properties)6 ImmutableMessage (joynr.ImmutableMessage)6 Request (joynr.Request)6 Injector (com.google.inject.Injector)5 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)5 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)5 joynr.tests.testProxy (joynr.tests.testProxy)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 AbstractModule (com.google.inject.AbstractModule)4 IOException (java.io.IOException)4 OneWayRequest (joynr.OneWayRequest)4