Search in sources :

Example 41 with JoynrRuntimeException

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

the class DispatcherImpl method handle.

private void handle(final SubscriptionPublication publication) {
    try {
        String subscriptionId = publication.getSubscriptionId();
        if (subscriptionManager.isBroadcast(subscriptionId)) {
            Class<?>[] broadcastOutParameterTypes = subscriptionManager.getUnicastPublicationOutParameterTypes(subscriptionId);
            List<?> broadcastOutParamterValues = (List<?>) publication.getResponse();
            Object[] broadcastValues = getPublicationValues(broadcastOutParameterTypes, broadcastOutParamterValues);
            subscriptionManager.handleBroadcastPublication(subscriptionId, broadcastValues);
        } else {
            JoynrRuntimeException error = publication.getError();
            if (error != null) {
                subscriptionManager.handleAttributePublicationError(subscriptionId, error);
            } else {
                Class<?> receivedType = subscriptionManager.getAttributeType(subscriptionId);
                Object attributeValue;
                if (TypeReference.class.isAssignableFrom(receivedType)) {
                    TypeReference<?> typeRef = (TypeReference<?>) receivedType.newInstance();
                    attributeValue = objectMapper.convertValue(((List<?>) publication.getResponse()).get(0), typeRef);
                } else {
                    attributeValue = objectMapper.convertValue(((List<?>) publication.getResponse()).get(0), receivedType);
                }
                subscriptionManager.handleAttributePublication(subscriptionId, attributeValue);
            }
        }
    } catch (Exception e) {
        logger.error("Error delivering publication: {} : {}", e.getClass(), e.getMessage());
    }
}
Also used : List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrException(io.joynr.exceptions.JoynrException) EncodingException(io.joynr.smrf.EncodingException) IOException(java.io.IOException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException)

Example 42 with JoynrRuntimeException

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

the class ReplyCallerDirectory method addReplyCaller.

public void addReplyCaller(final String requestReplyId, final ReplyCaller replyCaller, final ExpiryDate roundTripTtlExpirationDate) {
    logger.trace("putReplyCaller: " + requestReplyId + " expiryDate: " + roundTripTtlExpirationDate);
    super.add(requestReplyId, replyCaller);
    try {
        cleanupScheduler.schedule(new Runnable() {

            @Override
            public void run() {
                removeExpiredReplyCaller(requestReplyId);
            }
        }, roundTripTtlExpirationDate.getRelativeTtl(), TimeUnit.MILLISECONDS);
    } catch (RejectedExecutionException e) {
        if (shutdown) {
            throw new JoynrShutdownException("shutdown in ReplyCallerDirectory");
        }
        throw new JoynrRuntimeException(e);
    }
}
Also used : JoynrShutdownException(io.joynr.exceptions.JoynrShutdownException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 43 with JoynrRuntimeException

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

the class JoynrMessagingConnectorFactory method ensureMethodMetaInformationPresent.

public static MethodMetaInformation ensureMethodMetaInformationPresent(Method method) {
    if (metaInformationMap.containsKey(method)) {
        return metaInformationMap.get(method);
    }
    MethodMetaInformation metaInformation;
    try {
        metaInformation = new MethodMetaInformation(method);
    } catch (JsonMappingException e) {
        throw new JoynrRuntimeException(e);
    }
    MethodMetaInformation existingMetaInformation = metaInformationMap.putIfAbsent(method, metaInformation);
    if (existingMetaInformation != null) {
        // we only use putIfAbsent instead of .put, because putIfAbsent is threadsafe
        logger.debug("There was already a metaInformation object for that method in the map.");
    }
    return metaInformation;
}
Also used : MethodMetaInformation(joynr.MethodMetaInformation) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException)

Example 44 with JoynrRuntimeException

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

the class CapabilitiesRegistrarImpl method registerProvider.

/*
     * (non-Javadoc)
     *
     * @see io.joynr.capabilities.CapabilitiesRegistrar# registerProvider(java.lang.String,
     * io.joynr.provider.JoynrProvider, java.lang.Class)
     */
@Override
public Future<Void> registerProvider(final String domain, Object provider, ProviderQos providerQos) {
    if (providerQos == null) {
        throw new JoynrRuntimeException("providerQos == null. It must not be null");
    }
    ProviderContainer providerContainer = providerContainerFactory.create(provider);
    String participantId = participantIdStorage.getProviderParticipantId(domain, providerContainer.getInterfaceName());
    String defaultPublicKeyId = "";
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(getVersionFromAnnotation(provider.getClass()), domain, providerContainer.getInterfaceName(), participantId, providerQos, System.currentTimeMillis(), System.currentTimeMillis() + defaultExpiryTimeMs, defaultPublicKeyId);
    final boolean isGloballyVisible = (discoveryEntry.getQos().getScope() == ProviderScope.GLOBAL);
    messageRouter.addNextHop(participantId, libjoynrMessagingAddress, isGloballyVisible);
    providerDirectory.add(participantId, providerContainer);
    Callback<Void> callback = new Callback<Void>() {

        @Override
        public void onSuccess(@CheckForNull Void result) {
        }

        @Override
        public void onFailure(JoynrRuntimeException runtimeException) {
            logger.error("Unexpected Error while registering Provider:", runtimeException);
        }
    };
    return localDiscoveryAggregator.add(callback, discoveryEntry);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Callback(io.joynr.proxy.Callback) CheckForNull(javax.annotation.CheckForNull) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProviderContainer(io.joynr.provider.ProviderContainer)

Example 45 with JoynrRuntimeException

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

the class IltConsumerAsyncMethodTest method callMethodWithSingleByteBufferParameterAsync.

@Test
public void callMethodWithSingleByteBufferParameterAsync() {
    LOG.info(name.getMethodName());
    final Semaphore resultAvailable = new Semaphore(0);
    try {
        // setup input parameter
        final Byte[] byteBufferArg = { -128, 0, 127 };
        Callback<Byte[]> callback = new Callback<Byte[]>() {

            @Override
            public void onSuccess(Byte[] byteBufferOut) {
                // check result
                if (!java.util.Objects.deepEquals(byteBufferOut, byteBufferArg)) {
                    LOG.info(name.getMethodName() + " - invalid byteBufferOut from callback");
                    LOG.info(name.getMethodName() + " - FAILED");
                    methodWithSingleByteBufferParameterAsyncCallbackResult = false;
                    resultAvailable.release();
                    return;
                }
                methodWithSingleByteBufferParameterAsyncCallbackResult = true;
                resultAvailable.release();
            }

            @Override
            public void onFailure(JoynrRuntimeException error) {
                methodWithSingleByteBufferParameterAsyncCallbackResult = false;
                if (error instanceof JoynrRuntimeException) {
                    LOG.info(name.getMethodName() + " - callback - caught exception " + ((JoynrRuntimeException) error).getMessage());
                } else {
                    LOG.info(name.getMethodName() + " - callback - caught exception");
                }
                LOG.info(name.getMethodName() + " - FAILED");
                resultAvailable.release();
            }
        };
        testInterfaceProxy.methodWithSingleByteBufferParameter(callback, byteBufferArg);
        try {
            // wait for callback
            LOG.info(name.getMethodName() + " - about to wait for callback");
            Assert.assertTrue(name.getMethodName() + " - FAILED - callback not received in time", resultAvailable.tryAcquire(10, TimeUnit.SECONDS));
            // check result from callback
            LOG.info(name.getMethodName() + " - wait for callback is over");
            Assert.assertTrue(name.getMethodName() + " - FAILED - callback reported error", methodWithSingleByteBufferParameterAsyncCallbackResult);
        } catch (InterruptedException | JoynrRuntimeException e) {
            fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
    }
    LOG.info(name.getMethodName() + " - OK");
}
Also used : MethodWithMultipleStructParametersCallback(joynr.interlanguagetest.TestInterfaceAsync.MethodWithMultipleStructParametersCallback) Callback(io.joynr.proxy.Callback) Semaphore(java.util.concurrent.Semaphore) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Aggregations

JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)76 Test (org.junit.Test)41 ApplicationException (joynr.exceptions.ApplicationException)18 joynr.tests.testProxy (joynr.tests.testProxy)16 MessagingQos (io.joynr.messaging.MessagingQos)14 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)13 Callback (io.joynr.proxy.Callback)9 Future (io.joynr.proxy.Future)9 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)9 IOException (java.io.IOException)8 Semaphore (java.util.concurrent.Semaphore)8 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 DiscoveryException (io.joynr.exceptions.DiscoveryException)7 JoynrException (io.joynr.exceptions.JoynrException)7 DeferredVoid (io.joynr.provider.DeferredVoid)7 HashSet (java.util.HashSet)7 ProviderQos (joynr.types.ProviderQos)7 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)5 ProxyCreatedCallback (io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback)5