Search in sources :

Example 1 with RpcAsyncRequestReplyCaller

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;
}
Also used : RpcAsyncRequestReplyCaller(io.joynr.dispatching.rpc.RpcAsyncRequestReplyCaller) ExpiryDate(io.joynr.common.ExpiryDate) MethodMetaInformation(joynr.MethodMetaInformation) OneWayRequest(joynr.OneWayRequest) Request(joynr.Request) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Aggregations

ExpiryDate (io.joynr.common.ExpiryDate)1 RpcAsyncRequestReplyCaller (io.joynr.dispatching.rpc.RpcAsyncRequestReplyCaller)1 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)1 MethodMetaInformation (joynr.MethodMetaInformation)1 OneWayRequest (joynr.OneWayRequest)1 Request (joynr.Request)1