Search in sources :

Example 1 with Request

use of joynr.Request in project joynr by bmwcarit.

the class CcMessageRouterTest method setUp.

@Before
public void setUp() throws Exception {
    when(middlewareMessagingStubFactoryMock.create(any(ChannelAddress.class))).thenReturn(messagingStubMock);
    AbstractModule mockModule = new AbstractModule() {

        private Long msgRetryIntervalMs = 10L;

        // message runnables + cleanup thread
        private int numberOfThreads = maximumParallelSends + 1;

        private long routingTableGracePeriodMs = 30000;

        private long routingTableCleanupIntervalMs = 60000;

        @Override
        protected void configure() {
            bind(MessageRouter.class).to(CcMessageRouter.class);
            bind(RoutingTable.class).toInstance(routingTable);
            bind(AddressManager.class).toInstance(addressManager);
            bind(MulticastReceiverRegistry.class).toInstance(multicastReceiverRegistry);
            bind(ShutdownNotifier.class).toInstance(shutdownNotifier);
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_SEND_MSG_RETRY_INTERVAL_MS)).toInstance(msgRetryIntervalMs);
            bind(Integer.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_MESSAGING_MAXIMUM_PARALLEL_SENDS)).toInstance(maximumParallelSends);
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_ROUTING_TABLE_GRACE_PERIOD_MS)).toInstance(routingTableGracePeriodMs);
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_ROUTING_TABLE_CLEANUP_INTERVAL_MS)).toInstance(routingTableCleanupIntervalMs);
            bindConstant().annotatedWith(Names.named(ClusterControllerRuntimeModule.PROPERTY_ACCESSCONTROL_ENABLE)).to(false);
            bind(AccessController.class).toInstance(Mockito.mock(AccessController.class));
            bind(StatusReceiver.class).toInstance(statusReceiver);
            MapBinder<Class<? extends Address>, AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>> messagingStubFactory;
            messagingStubFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
            }, new TypeLiteral<AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>>() {
            }, Names.named(MessagingStubFactory.MIDDLEWARE_MESSAGING_STUB_FACTORIES));
            messagingStubFactory.addBinding(ChannelAddress.class).toInstance(middlewareMessagingStubFactoryMock);
            MapBinder<Class<? extends Address>, IMessagingSkeleton> messagingSkeletonFactory;
            messagingSkeletonFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
            }, new TypeLiteral<IMessagingSkeleton>() {
            }, Names.named(MessagingSkeletonFactory.MIDDLEWARE_MESSAGING_SKELETONS));
            messagingSkeletonFactory.addBinding(ChannelAddress.class).toInstance(messagingSkeletonMock);
            Multibinder.newSetBinder(binder(), new TypeLiteral<MulticastAddressCalculator>() {
            });
        }

        @Provides
        @Named(MessageRouter.SCHEDULEDTHREADPOOL)
        ScheduledExecutorService provideMessageSchedulerThreadPoolExecutor() {
            ThreadFactory schedulerNamedThreadFactory = new ThreadFactoryBuilder().setNameFormat("joynr.MessageScheduler-scheduler-%d").build();
            ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(numberOfThreads, schedulerNamedThreadFactory);
            scheduler.setKeepAliveTime(100, TimeUnit.SECONDS);
            scheduler.allowCoreThreadTimeOut(true);
            return scheduler;
        }
    };
    testModule = Modules.override(mockModule).with(new TestGlobalAddressModule());
    Injector injector = Guice.createInjector(testModule);
    messageRouter = injector.getInstance(MessageRouter.class);
    ObjectMapper objectMapper = new ObjectMapper();
    messageFactory = new MutableMessageFactory(objectMapper, new HashSet<JoynrMessageProcessor>());
    // toParticipantId is globally visible
    final boolean isGloballyVisible = true;
    final long expiryDateMs = Long.MAX_VALUE;
    final boolean isSticky = true;
    final boolean allowUpdate = false;
    routingTable.put(toParticipantId, channelAddress, isGloballyVisible, expiryDateMs, isSticky, allowUpdate);
    Request request = new Request("noMethod", new Object[] {}, new String[] {}, "requestReplyId");
    joynrMessage = messageFactory.createRequest(fromParticipantId, toParticipantId, request, new MessagingQos());
    joynrMessage.setLocalMessage(true);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) IMessagingSkeleton(io.joynr.messaging.IMessagingSkeleton) Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) CcMessageRouter(io.joynr.messaging.routing.CcMessageRouter) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) StatusReceiver(io.joynr.statusmetrics.StatusReceiver) MessagingQos(io.joynr.messaging.MessagingQos) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ShutdownNotifier(io.joynr.runtime.ShutdownNotifier) Request(joynr.Request) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) AbstractModule(com.google.inject.AbstractModule) AbstractMiddlewareMessagingStubFactory(io.joynr.messaging.AbstractMiddlewareMessagingStubFactory) AccessController(io.joynr.accesscontrol.AccessController) MutableMessageFactory(io.joynr.dispatching.MutableMessageFactory) IMessagingStub(io.joynr.messaging.IMessagingStub) Before(org.junit.Before)

Example 2 with Request

use of joynr.Request in project joynr by bmwcarit.

the class DefaultJoynrRuntimeFactoryTest method testJoynrMessageProcessorUsed.

@Test
public void testJoynrMessageProcessorUsed() throws Exception {
    createFixture();
    Injector injector = fixture.getInjector();
    MutableMessageFactory messageFactory = injector.getInstance(MutableMessageFactory.class);
    MutableMessage request = messageFactory.createRequest("from", "to", new Request("name", new Object[0], new Class[0]), new MessagingQos());
    assertEquals("test", request.getCustomHeaders().get("test"));
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MutableMessageFactory(io.joynr.dispatching.MutableMessageFactory) MutableMessage(joynr.MutableMessage) Injector(com.google.inject.Injector) Request(joynr.Request) Test(org.junit.Test)

Example 3 with Request

use of joynr.Request in project joynr by bmwcarit.

the class RequestReplyManagerImpl method entryAdded.

@Override
public void entryAdded(String participantId, ProviderContainer providerContainer) {
    ConcurrentLinkedQueue<ContentWithExpiryDate<Request>> requestList = requestQueue.remove(participantId);
    if (requestList != null) {
        for (ContentWithExpiryDate<Request> requestItem : requestList) {
            if (!requestItem.isExpired()) {
                Request request = requestItem.getContent();
                handleRequest(replyCallbacks.remove(request), providerContainer.getRequestCaller(), request);
            }
        }
    }
    ConcurrentLinkedQueue<OneWayCallable> oneWayCallables = oneWayRequestQueue.remove(participantId);
    if (oneWayCallables != null) {
        for (OneWayCallable oneWayCallable : oneWayCallables) {
            oneWayCallable.call();
        }
    }
}
Also used : OneWayRequest(joynr.OneWayRequest) Request(joynr.Request)

Example 4 with Request

use of joynr.Request in project joynr by bmwcarit.

the class RequestDeserializer method deserialize.

/* (non-Javadoc)
     * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser,
     * com.fasterxml.jackson.databind.DeserializationContext)
     */
@Override
public Request deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    JsonNode node = jp.getCodec().readTree(jp);
    String methodName = node.get("methodName").asText();
    String requestReplyId = node.get("requestReplyId").asText();
    ParamsAndParamDatatypesHolder paramsAndParamDatatypes = DeserializerUtils.deserializeParams(objectMapper, node, logger);
    return new Request(methodName, paramsAndParamDatatypes.params, paramsAndParamDatatypes.paramDatatypes, requestReplyId);
}
Also used : Request(joynr.Request) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 5 with Request

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

Aggregations

Request (joynr.Request)18 OneWayRequest (joynr.OneWayRequest)11 SubscriptionRequest (joynr.SubscriptionRequest)8 MessagingQos (io.joynr.messaging.MessagingQos)7 Reply (joynr.Reply)6 AbstractModule (com.google.inject.AbstractModule)5 Injector (com.google.inject.Injector)5 TypeLiteral (com.google.inject.TypeLiteral)5 Method (java.lang.reflect.Method)5 MutableMessage (joynr.MutableMessage)5 Before (org.junit.Before)5 Test (org.junit.Test)5 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)4 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)3 SynchronizedReplyCaller (io.joynr.dispatching.rpc.SynchronizedReplyCaller)3 JsonMessageSerializerModule (io.joynr.messaging.JsonMessageSerializerModule)3 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2