use of io.joynr.dispatching.rpc.RpcAsyncRequestReplyCaller in project joynr by bmwcarit.
the class JoynrMessagingConnectorInvocationHandler method executeAsyncMethod.
@SuppressWarnings("unchecked")
@Override
public Future<?> executeAsyncMethod(Method method, Object[] params, Future<?> future) {
if (method == null) {
throw new IllegalArgumentException("Method cannot be null");
}
if (toDiscoveryEntries.size() > 1) {
throw new JoynrIllegalStateException("You can't execute async methods for multiple participants.");
}
if (toDiscoveryEntries.isEmpty()) {
throw new JoynrIllegalStateException("You must have exactly one participant to be able to execute an async method.");
}
MethodMetaInformation methodMetaInformation = JoynrMessagingConnectorFactory.ensureMethodMetaInformationPresent(method);
if (methodMetaInformation.getCallbackAnnotation() == null) {
throw new JoynrIllegalStateException("All async methods need to have a annotated callback parameter.");
}
int callbackIndex = methodMetaInformation.getCallbackIndex();
ICallback callback = (ICallback) params[callbackIndex];
Object[] paramsWithoutCallback = new Object[params.length - 1];
copyArrayWithoutElement(params, paramsWithoutCallback, callbackIndex);
Class<?>[] paramDatatypes = method.getParameterTypes();
Class<?>[] paramDatatypesWithoutCallback = new Class<?>[paramDatatypes.length - 1];
copyArrayWithoutElement(paramDatatypes, paramDatatypesWithoutCallback, callbackIndex);
Request request = new Request(method.getName(), paramsWithoutCallback, paramDatatypesWithoutCallback);
String requestReplyId = request.getRequestReplyId();
@SuppressWarnings("rawtypes") RpcAsyncRequestReplyCaller<?> callbackWrappingReplyCaller = new RpcAsyncRequestReplyCaller(requestReplyId, callback, future, method, methodMetaInformation);
ExpiryDate expiryDate = DispatcherUtils.convertTtlToExpirationDate(qosSettings.getRoundTripTtl_ms());
replyCallerDirectory.addReplyCaller(requestReplyId, callbackWrappingReplyCaller, expiryDate);
requestReplyManager.sendRequest(fromParticipantId, toDiscoveryEntries.iterator().next(), request, qosSettings);
return future;
}
Aggregations