use of io.joynr.common.ExpiryDate 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 io.joynr.common.ExpiryDate in project joynr by bmwcarit.
the class RequestReplyManagerTest method requestReplyMessagesRemoveCallBackByTtl.
@Test
public void requestReplyMessagesRemoveCallBackByTtl() throws Exception {
TestProvider testResponder = new TestProvider(1);
ExpiryDate ttlReplyCaller = ExpiryDate.fromRelativeTtl(1000L);
final ReplyCaller replyCaller = mock(ReplyCaller.class);
replyCallerDirectory.addReplyCaller(request1.getRequestReplyId(), replyCaller, ttlReplyCaller);
Thread.sleep(ttlReplyCaller.getRelativeTtl() + 100);
requestReplyManager.handleReply(new Reply(request1.getRequestReplyId(), testResponder.getSentPayloadFor(request1)));
verify(replyCaller, never()).messageCallBack(any(Reply.class));
}
use of io.joynr.common.ExpiryDate in project joynr by bmwcarit.
the class MutableMessageFactory method createMessage.
private MutableMessage createMessage(String joynrMessageType, String fromParticipantId, String toParticipantId, Object payload, MessagingQos messagingQos, boolean upliftTtl) {
ExpiryDate expiryDate;
if (!upliftTtl) {
expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
} else if (messagingQos.getRoundTripTtl_ms() > (Long.MAX_VALUE - ttlUpliftMs)) {
expiryDate = DispatcherUtils.convertTtlToExpirationDate(Long.MAX_VALUE);
} else {
expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms() + ttlUpliftMs);
}
MutableMessage message = new MutableMessage();
message.setType(joynrMessageType);
if (messagingQos.getEffort() != null && !MessagingQosEffort.NORMAL.equals(messagingQos.getEffort())) {
message.setEffort(String.valueOf(messagingQos.getEffort()));
}
message.setSender(fromParticipantId);
message.setRecipient(toParticipantId);
message.setTtlAbsolute(true);
message.setTtlMs(expiryDate.getValue());
message.setPayload(serializePayload(payload));
message.setCustomHeaders(messagingQos.getCustomMessageHeaders());
message.setCompressed(messagingQos.getCompress());
for (JoynrMessageProcessor processor : messageProcessors) {
message = processor.processOutgoing(message);
}
logger.debug("Message {} has expiry date: {}", message.getId(), expiryDate);
return message;
}
use of io.joynr.common.ExpiryDate 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