Search in sources :

Example 16 with JoynrRuntimeException

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

the class AttributePollInterpreter method execute.

@Nonnull
public Promise<?> execute(ProviderContainer providerContainer, Method method) {
    String interfaceName = providerContainer.getInterfaceName();
    Object returnValueFromProvider = null;
    try {
        returnValueFromProvider = method.invoke(providerContainer.getProviderProxy());
    } catch (IllegalAccessException e) {
        String message = String.format("Method \"%s\" is not accessible on \"%s\" provider (exception: \"%s\").", method.getName(), interfaceName, e.toString());
        logger.error(message, e);
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
        throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
    } catch (IllegalArgumentException e) {
        String message = String.format("Provider of interface \"%s\" does not declare method \"%s\" (exception: \"%s\")", interfaceName, method.getName(), e.toString());
        logger.error(message, e);
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
        throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        String message = String.format("Calling method \"%s\" on \"%s\" provider threw an exception: \"%s\"", method.getName(), interfaceName, cause == null ? e.toString() : cause.toString());
        logger.error(message, e);
        throw new ProviderRuntimeException(cause == null ? e.toString() : cause.toString());
    } catch (Exception e) {
        String message = String.format("Calling method \"%s\" on \"%s\" provider threw an unexpected exception: \"%s\"", method.getName(), interfaceName, e.toString());
        logger.error(message, e);
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
        throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
    }
    if (returnValueFromProvider == null) {
        String message = String.format("Calling method \"%s\" on \"%s\" provider returned \"null\".", method.getName(), interfaceName);
        logger.error(message);
        throw new JoynrRuntimeException(message);
    }
    Promise<?> returnedPromiseFromProvider = null;
    try {
        returnedPromiseFromProvider = (Promise<?>) returnValueFromProvider;
    } catch (ClassCastException e) {
        String message = String.format("Calling method \"%s\" on \"%s\" provider did not return a promise.", method.getName(), interfaceName);
        logger.error(message, e);
        throw new JoynrRuntimeException(message, e);
    }
    return returnedPromiseFromProvider;
}
Also used : JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MethodInvocationException(joynr.exceptions.MethodInvocationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) MethodInvocationException(joynr.exceptions.MethodInvocationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Nonnull(javax.annotation.Nonnull)

Example 17 with JoynrRuntimeException

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

the class PublicationManagerImpl method triggerPublication.

private void triggerPublication(final PublicationInformation publicationInformation, ProviderContainer providerContainer, Method method) {
    try {
        Promise<?> attributeGetterPromise = attributePollInterpreter.execute(providerContainer, method);
        attributeGetterPromise.then(new PromiseListener() {

            @Override
            public void onRejection(JoynrException error) {
                if (error instanceof JoynrRuntimeException) {
                    sendPublicationError((JoynrRuntimeException) error, publicationInformation);
                } else {
                    sendPublicationError(new ProviderRuntimeException("Unexpected exception while calling getter for attribute " + publicationInformation.getSubscribedToName()), publicationInformation);
                }
            }

            @Override
            public void onFulfillment(Object... values) {
                // attribute getters only return a single value
                sendPublication(prepareAttributePublication(values[0], publicationInformation.getSubscriptionId()), publicationInformation);
            }
        });
    } catch (JoynrRuntimeException error) {
        sendPublicationError(error, publicationInformation);
    }
}
Also used : PromiseListener(io.joynr.provider.PromiseListener) JoynrException(io.joynr.exceptions.JoynrException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 18 with JoynrRuntimeException

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

the class RpcAsyncRequestReplyCaller method error.

@Override
public void error(Throwable error) {
    JoynrException joynrException;
    // wrap non-joynr exceptions in a JoynrRuntimeException
    if (error instanceof JoynrException) {
        joynrException = (JoynrException) error;
    } else {
        joynrException = new JoynrRuntimeException(error);
    }
    errorCallback(joynrException);
    if (future != null) {
        future.onFailure(joynrException);
    }
}
Also used : JoynrException(io.joynr.exceptions.JoynrException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException)

Example 19 with JoynrRuntimeException

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

the class LocalDiscoveryAggregator method lookup.

@Override
public Future<DiscoveryEntryWithMetaInfo[]> lookup(final Callback<DiscoveryEntryWithMetaInfo[]> callback, String[] domains, String interfaceName, DiscoveryQos discoveryQos) {
    final Set<DiscoveryEntryWithMetaInfo> discoveryEntries = new HashSet<>();
    Set<String> missingDomains = new HashSet<>();
    for (String domain : domains) {
        if (provisionedDiscoveryEntries.containsKey(domain + interfaceName)) {
            DiscoveryEntryWithMetaInfo discoveryEntry = provisionedDiscoveryEntries.get(domain + interfaceName);
            discoveryEntries.add(discoveryEntry);
        } else {
            missingDomains.add(domain);
        }
    }
    logger.trace("Found locally provisioned discovery entries: {}", discoveryEntries);
    final Future<DiscoveryEntryWithMetaInfo[]> discoveryEntryFuture = new Future<>();
    if (!missingDomains.isEmpty()) {
        logger.trace("Did not find entries for the following domains: {}", missingDomains);
        Callback<DiscoveryEntryWithMetaInfo[]> newCallback = new Callback<DiscoveryEntryWithMetaInfo[]>() {

            @Override
            public void onFailure(JoynrRuntimeException error) {
                callback.onFailure(error);
                discoveryEntryFuture.onFailure(error);
            }

            @Override
            public void onSuccess(DiscoveryEntryWithMetaInfo[] entries) {
                assert entries != null : "Entries must not be null.";
                logger.trace("Globally found entries for missing domains: {}", Arrays.toString(entries));
                Collections.addAll(discoveryEntries, entries);
                resolveDiscoveryEntriesFutureWithEntries(discoveryEntryFuture, discoveryEntries, callback);
            }
        };
        String[] missingDomainsArray = new String[missingDomains.size()];
        missingDomains.toArray(missingDomainsArray);
        getDiscoveryProxy(discoveryQos.getDiscoveryTimeout()).lookup(newCallback, missingDomainsArray, interfaceName, discoveryQos);
    } else {
        resolveDiscoveryEntriesFutureWithEntries(discoveryEntryFuture, discoveryEntries, callback);
    }
    return discoveryEntryFuture;
}
Also used : Callback(io.joynr.proxy.Callback) Future(io.joynr.proxy.Future) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) HashSet(java.util.HashSet)

Example 20 with JoynrRuntimeException

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

the class ProxyBuilderDefaultImpl method createProxyInvocationHandler.

// Method called by both synchronous and asynchronous build() to create a ProxyInvocationHandler
private ProxyInvocationHandler createProxyInvocationHandler(final ProxyCreatedCallback<T> callback) {
    if (buildCalled) {
        throw new JoynrIllegalStateException("Proxy builder was already used to build a proxy. Please create a new proxy builder for each proxy.");
    }
    buildCalled = true;
    final ProxyInvocationHandler proxyInvocationHandler = proxyInvocationHandlerFactory.create(domains, interfaceName, proxyParticipantId, discoveryQos, messagingQos);
    // This order is necessary because the Arbitrator might return early
    // But if the listener is set after the ProxyInvocationHandler the
    // Arbitrator cannot return early
    arbitrator.setArbitrationListener(new ArbitrationCallback() {

        @Override
        public void onSuccess(ArbitrationResult arbitrationResult) {
            logger.debug("DISCOVERY proxy created for:{}", arbitrationResult.getDiscoveryEntries());
            proxyInvocationHandler.createConnector(arbitrationResult);
            callback.onProxyCreationFinished(proxy);
        }

        @Override
        public void onError(Throwable throwable) {
            JoynrRuntimeException reason;
            if (throwable instanceof JoynrRuntimeException) {
                reason = (JoynrRuntimeException) throwable;
            } else {
                reason = new JoynrRuntimeException(throwable);
            }
            proxyInvocationHandler.abort(reason);
            callback.onProxyCreationError(reason);
        }
    });
    return proxyInvocationHandler;
}
Also used : ArbitrationResult(io.joynr.arbitration.ArbitrationResult) ArbitrationCallback(io.joynr.arbitration.ArbitrationCallback) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

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