use of io.joynr.dispatcher.rpc.MultiReturnValuesContainer in project joynr by bmwcarit.
the class ProviderWrapper method createAndResolveOrRejectDeferred.
@SuppressWarnings("unchecked")
private AbstractDeferred createAndResolveOrRejectDeferred(Method method, Object result, JoynrException joynrException) {
AbstractDeferred deferred;
if (result == null && method.getReturnType().equals(Void.class)) {
deferred = new DeferredVoid();
if (joynrException == null) {
((DeferredVoid) deferred).resolve();
}
} else {
if (result instanceof MultiReturnValuesContainer) {
deferred = new MultiValueDeferred();
if (joynrException == null) {
((MultiValueDeferred) deferred).resolve(((MultiReturnValuesContainer) result).getValues());
}
} else {
deferred = new Deferred<Object>();
if (joynrException == null) {
((Deferred<Object>) deferred).resolve(result);
}
}
}
if (joynrException != null) {
LOG.debug("Provider method invocation resulted in provider runtime exception - rejecting the deferred {} with {}", deferred, joynrException);
if (joynrException instanceof ApplicationException) {
try {
Method rejectMethod = AbstractDeferred.class.getDeclaredMethod("reject", new Class[] { JoynrException.class });
rejectMethod.setAccessible(true);
rejectMethod.invoke(deferred, new Object[] { joynrException });
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
LOG.warn("Unable to set {} as rejection reason on {}. Wrapping in ProviderRuntimeException instead.", joynrException, deferred);
deferred.reject(new ProviderRuntimeException(((ApplicationException) joynrException).getMessage()));
}
} else if (joynrException instanceof ProviderRuntimeException) {
deferred.reject((ProviderRuntimeException) joynrException);
}
}
return deferred;
}
Aggregations