use of joynr.OneWayRequest in project joynr by bmwcarit.
the class ConnectorTest method oneWayMethodCallCallsRequestReplyManagerWithCorrectArguments.
@Test
public void oneWayMethodCallCallsRequestReplyManagerWithCorrectArguments() {
ConnectorInvocationHandler connector = createConnector();
assertNotNull(connector);
ArgumentCaptor<OneWayRequest> requestCaptor = ArgumentCaptor.forClass(OneWayRequest.class);
try {
Method method = TestFireAndForgetInterface.class.getDeclaredMethod("methodWithoutParameters");
connector.executeOneWayMethod(method, new Object[] {});
verify(requestReplyManager, times(1)).sendOneWayRequest(eq(fromParticipantId), eq(toDiscoveryEntries), requestCaptor.capture(), eq(qosSettings));
OneWayRequest actualRequest = requestCaptor.getValue();
OneWayRequest expectedRequest = new OneWayRequest(method.getName(), new Object[] {}, new String[] {});
assertEquals(expectedRequest, actualRequest);
} catch (Exception e) {
fail("Unexpected exception from one way method call: " + e);
}
}
use of joynr.OneWayRequest in project joynr by bmwcarit.
the class RequestReplyManagerTest method setUp.
@Before
public void setUp() throws NoSuchMethodException, SecurityException, JsonGenerationException, IOException {
requestCallerFactory = new RequestCallerFactory();
testOneWayRecipientParticipantId = "testOneWayRecipientParticipantId";
testOneWayRecipientDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
testOneWayRecipientDiscoveryEntry.setParticipantId(testOneWayRecipientParticipantId);
testOneWayRecipientDiscoveryEntries = Sets.newHashSet(testOneWayRecipientDiscoveryEntry);
testMessageResponderParticipantId = "testMessageResponderParticipantId";
testMessageResponderDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
testMessageResponderDiscoveryEntry.setParticipantId(testMessageResponderParticipantId);
testSenderParticipantId = "testSenderParticipantId";
testResponderUnregisteredParticipantId = "testResponderUnregisteredParticipantId";
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new JoynrMessageScopeModule());
bind(MessageSender.class).toInstance(messageSenderMock);
bind(MessageRouter.class).toInstance(messageRouterMock);
bind(RequestReplyManager.class).to(RequestReplyManagerImpl.class);
requestStaticInjection(RpcUtils.class, Request.class, JoynrMessagingConnectorFactory.class);
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("joynr.Cleanup-%d").build();
ScheduledExecutorService cleanupExecutor = Executors.newSingleThreadScheduledExecutor(namedThreadFactory);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(JOYNR_SCHEDULER_CLEANUP)).toInstance(cleanupExecutor);
Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
});
}
});
objectMapper = injector.getInstance(ObjectMapper.class);
objectMapper.registerSubtypes(Request.class, OneWayRequest.class);
requestReplyManager = injector.getInstance(RequestReplyManager.class);
providerDirectory = injector.getInstance(ProviderDirectory.class);
replyCallerDirectory = injector.getInstance(ReplyCallerDirectory.class);
requestReplyManager = injector.getInstance(RequestReplyManager.class);
// dispatcher.addListener(testOneWayRecipientParticipantId, testListener);
// jsonRequestString1 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
// + payload1 + "\"}}";
// jsonRequestString2 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
// + payload2 + "\"}}";
Object[] params1 = new Object[] { payload1 };
Object[] params2 = new Object[] { payload2 };
// MethodMetaInformation methodMetaInformation = new
// MethodMetaInformation(TestRequestCaller.class.getMethod("respond", new Class[]{ Object.class }));
Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
request1 = new Request(method.getName(), params1, method.getParameterTypes());
request2 = new Request(method.getName(), params2, method.getParameterTypes());
request3 = new Request("unknownMethodName", params2, method.getParameterTypes());
Method fireAndForgetMethod = TestOneWayRecipient.class.getMethod("fireAndForgetMethod", new Class[] { String.class });
oneWay1 = new OneWayRequest(fireAndForgetMethod.getName(), new Object[] { payload1 }, fireAndForgetMethod.getParameterTypes());
}
use of joynr.OneWayRequest in project joynr by bmwcarit.
the class WebSocketTest method sendMessage.
private void sendMessage() throws Throwable {
OneWayRequest request = new OneWayRequest("method", new Object[0], new Class<?>[0]);
MessagingQos messagingQos = new MessagingQos(100000);
ImmutableMessage msg = messageFactory.createOneWayRequest("fromID", "toID", request, messagingQos).getImmutableMessage();
SuccessAction successAction = mock(SuccessAction.class);
webSocketMessagingStub.transmit(msg, successAction, new FailureAction() {
@Override
public void execute(Throwable error) {
Assert.fail(error.getMessage());
}
});
Mockito.verify(messageRouterMock, Mockito.timeout(1000)).route(argThat(new SerializedDataOfImmutableMessageMatcher(msg)));
Mockito.verify(successAction).execute();
}
use of joynr.OneWayRequest in project joynr by bmwcarit.
the class DispatcherImpl method messageArrived.
@Override
public void messageArrived(final ImmutableMessage message) {
if (message == null) {
logger.error("received message was null");
return;
}
if (!message.isTtlAbsolute()) {
logger.error("received message with relative ttl (not supported)");
return;
}
final long expiryDate = message.getTtlMs();
final Map<String, String> customHeaders = message.getCustomHeaders();
if (DispatcherUtils.isExpired(expiryDate)) {
logger.debug("TTL expired, discarding message : {}", message);
return;
}
String payload;
try {
payload = new String(message.getUnencryptedBody(), Charsets.UTF_8);
} catch (EncodingException e) {
logger.error("Error reading SMRF message. msgId: {}. from: {} to: {}. Reason: {}. Discarding joynr message.", new Object[] { message.getSender(), message.getRecipient(), message.getId(), e.getMessage() });
return;
}
String type = message.getType();
try {
if (Message.VALUE_MESSAGE_TYPE_REPLY.equals(type)) {
Reply reply = objectMapper.readValue(payload, Reply.class);
logger.trace("Parsed reply from message payload :" + payload);
handle(reply);
} else if (Message.VALUE_MESSAGE_TYPE_SUBSCRIPTION_REPLY.equals(type)) {
SubscriptionReply subscriptionReply = objectMapper.readValue(payload, SubscriptionReply.class);
logger.trace("Parsed subscription reply from message payload :" + payload);
handle(subscriptionReply);
} else if (Message.VALUE_MESSAGE_TYPE_REQUEST.equals(type)) {
final Request request = objectMapper.readValue(payload, Request.class);
request.setCreatorUserId(message.getCreatorUserId());
request.setContext(message.getContext());
logger.trace("Parsed request from message payload :" + payload);
handle(request, message.getSender(), message.getRecipient(), expiryDate, customHeaders, message.isCompressed());
} else if (Message.VALUE_MESSAGE_TYPE_ONE_WAY.equals(type)) {
OneWayRequest oneWayRequest = objectMapper.readValue(payload, OneWayRequest.class);
oneWayRequest.setCreatorUserId(message.getCreatorUserId());
oneWayRequest.setContext(message.getContext());
logger.trace("Parsed one way request from message payload :" + payload);
handle(oneWayRequest, message.getRecipient(), expiryDate);
} else if (Message.VALUE_MESSAGE_TYPE_SUBSCRIPTION_REQUEST.equals(type) || Message.VALUE_MESSAGE_TYPE_BROADCAST_SUBSCRIPTION_REQUEST.equals(type) || Message.VALUE_MESSAGE_TYPE_MULTICAST_SUBSCRIPTION_REQUEST.equals(type)) {
SubscriptionRequest subscriptionRequest = objectMapper.readValue(payload, SubscriptionRequest.class);
logger.trace("Parsed subscription request from message payload :" + payload);
handle(subscriptionRequest, message.getSender(), message.getRecipient());
} else if (Message.VALUE_MESSAGE_TYPE_SUBSCRIPTION_STOP.equals(type)) {
SubscriptionStop subscriptionStop = objectMapper.readValue(payload, SubscriptionStop.class);
logger.trace("Parsed subscription stop from message payload :" + payload);
handle(subscriptionStop);
} else if (Message.VALUE_MESSAGE_TYPE_PUBLICATION.equals(type)) {
SubscriptionPublication publication = objectMapper.readValue(payload, SubscriptionPublication.class);
logger.trace("Parsed publication from message payload :" + payload);
handle(publication);
} else if (Message.VALUE_MESSAGE_TYPE_MULTICAST.equals(type)) {
MulticastPublication multicastPublication = objectMapper.readValue(payload, MulticastPublication.class);
logger.trace("Parsed multicast publication from message payload: {}", payload);
handle(multicastPublication);
}
} catch (IOException e) {
logger.error("Error parsing payload. msgId: {}. from: {} to: {}. Reason: {}. Discarding joynr message.", message.getId(), message.getSender(), message.getRecipient(), e.getMessage());
return;
}
}
use of joynr.OneWayRequest in project joynr by bmwcarit.
the class JoynrMessagingConnectorInvocationHandler method executeOneWayMethod.
@Override
public void executeOneWayMethod(Method method, Object[] args) {
// 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.isEmpty()) {
throw new JoynrIllegalStateException("You must have at least one participant to be able to execute an oneWayMethod.");
}
logger.debug("ONEWAYREQUEST call proxy: method: {}, params: {}, proxy participantId: {}," + " provider discovery entries: {}", method.getName(), args, fromParticipantId, toDiscoveryEntries);
OneWayRequest request = new OneWayRequest(method.getName(), args, method.getParameterTypes());
requestReplyManager.sendOneWayRequest(fromParticipantId, toDiscoveryEntries, request, qosSettings);
}
Aggregations