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