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;
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations