Search in sources :

Example 1 with MethodMetaInformation

use of joynr.MethodMetaInformation in project joynr by bmwcarit.

the class JoynrMessagingConnectorInvocationHandler method executeSyncMethod.

@CheckForNull
@Override
public Object executeSyncMethod(Method method, Object[] args) throws ApplicationException {
    // TODO does a method with 0 args pass in an empty args array, or null for args?
    if (method == null) {
        throw new IllegalArgumentException("Method cannot be null");
    }
    if (toDiscoveryEntries.size() > 1) {
        throw new JoynrIllegalStateException("You can't execute sync methods for multiple participants.");
    }
    if (toDiscoveryEntries.isEmpty()) {
        throw new JoynrIllegalStateException("You must have exactly one participant to be able to execute a sync method.");
    }
    MethodMetaInformation methodMetaInformation = JoynrMessagingConnectorFactory.ensureMethodMetaInformationPresent(method);
    Request request = new Request(method.getName(), args, method.getParameterTypes());
    Reply reply;
    String requestReplyId = request.getRequestReplyId();
    SynchronizedReplyCaller synchronizedReplyCaller = new SynchronizedReplyCaller(fromParticipantId, requestReplyId, request);
    ExpiryDate expiryDate = DispatcherUtils.convertTtlToExpirationDate(qosSettings.getRoundTripTtl_ms());
    replyCallerDirectory.addReplyCaller(requestReplyId, synchronizedReplyCaller, expiryDate);
    reply = (Reply) requestReplyManager.sendSyncRequest(fromParticipantId, toDiscoveryEntries.iterator().next(), request, synchronizedReplyCaller, qosSettings);
    if (reply.getError() == null) {
        if (method.getReturnType().equals(void.class)) {
            return null;
        }
        Object response = RpcUtils.reconstructReturnedObject(method, methodMetaInformation, reply.getResponse());
        logger.debug("REQUEST returns successful: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), response);
        return response;
    } else if (reply.getError() instanceof ApplicationException) {
        logger.debug("REQUEST returns error: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), reply.getError());
        throw (ApplicationException) reply.getError();
    } else {
        logger.debug("REQUEST returns error: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), reply.getError());
        throw (JoynrRuntimeException) reply.getError();
    }
}
Also used : ExpiryDate(io.joynr.common.ExpiryDate) ApplicationException(joynr.exceptions.ApplicationException) MethodMetaInformation(joynr.MethodMetaInformation) OneWayRequest(joynr.OneWayRequest) Request(joynr.Request) Reply(joynr.Reply) SynchronizedReplyCaller(io.joynr.dispatching.rpc.SynchronizedReplyCaller) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) CheckForNull(javax.annotation.CheckForNull)

Example 2 with MethodMetaInformation

use of joynr.MethodMetaInformation in project joynr by bmwcarit.

the class ProxyInvocationHandlerImpl method abort.

@Override
public void abort(JoynrRuntimeException exception) {
    setThrowableForInvoke(exception);
    for (Iterator<MethodInvocation<?>> iterator = queuedRpcList.iterator(); iterator.hasNext(); ) {
        MethodInvocation<?> invocation = iterator.next();
        try {
            MethodMetaInformation metaInfo = new MethodMetaInformation(invocation.getMethod());
            int callbackIndex = metaInfo.getCallbackIndex();
            if (callbackIndex > -1) {
                ICallback callback = (ICallback) invocation.getArgs()[callbackIndex];
                callback.onFailure(exception);
            }
        } catch (Exception metaInfoException) {
            logger.error("aborting call to method: " + invocation.getMethod().getName() + " but unable to call onError callback because of: " + metaInfoException.getMessage(), metaInfoException);
        }
        invocation.getFuture().onFailure(exception);
    }
    for (Iterator<UnsubscribeInvocation> iterator = queuedUnsubscripeInvocationList.iterator(); iterator.hasNext(); ) {
        Invocation<String> invocation = iterator.next();
        invocation.getFuture().onFailure(exception);
    }
    for (SubscriptionAction subscriptionAction : queuedSubscriptionInvocationList) {
        subscriptionAction.fail(exception);
    }
}
Also used : UnsubscribeInvocation(io.joynr.proxy.invocation.UnsubscribeInvocation) MethodMetaInformation(joynr.MethodMetaInformation) MethodInvocation(io.joynr.proxy.invocation.MethodInvocation) DiscoveryException(io.joynr.exceptions.DiscoveryException) JoynrException(io.joynr.exceptions.JoynrException) ApplicationException(joynr.exceptions.ApplicationException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 3 with MethodMetaInformation

use of joynr.MethodMetaInformation 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)

Example 4 with MethodMetaInformation

use of joynr.MethodMetaInformation in project joynr by bmwcarit.

the class JoynrMessagingConnectorFactory method ensureMethodMetaInformationPresent.

public static MethodMetaInformation ensureMethodMetaInformationPresent(Method method) {
    if (metaInformationMap.containsKey(method)) {
        return metaInformationMap.get(method);
    }
    MethodMetaInformation metaInformation;
    try {
        metaInformation = new MethodMetaInformation(method);
    } catch (JsonMappingException e) {
        throw new JoynrRuntimeException(e);
    }
    MethodMetaInformation existingMetaInformation = metaInformationMap.putIfAbsent(method, metaInformation);
    if (existingMetaInformation != null) {
        // we only use putIfAbsent instead of .put, because putIfAbsent is threadsafe
        logger.debug("There was already a metaInformation object for that method in the map.");
    }
    return metaInformation;
}
Also used : MethodMetaInformation(joynr.MethodMetaInformation) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException)

Aggregations

MethodMetaInformation (joynr.MethodMetaInformation)4 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)3 ExpiryDate (io.joynr.common.ExpiryDate)2 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)2 OneWayRequest (joynr.OneWayRequest)2 Request (joynr.Request)2 ApplicationException (joynr.exceptions.ApplicationException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 RpcAsyncRequestReplyCaller (io.joynr.dispatching.rpc.RpcAsyncRequestReplyCaller)1 SynchronizedReplyCaller (io.joynr.dispatching.rpc.SynchronizedReplyCaller)1 DiscoveryException (io.joynr.exceptions.DiscoveryException)1 JoynrException (io.joynr.exceptions.JoynrException)1 MethodInvocation (io.joynr.proxy.invocation.MethodInvocation)1 UnsubscribeInvocation (io.joynr.proxy.invocation.UnsubscribeInvocation)1 CheckForNull (javax.annotation.CheckForNull)1 Reply (joynr.Reply)1