void LibJoynrRuntime::init( std::unique_ptr<IMiddlewareMessagingStubFactory> middlewareMessagingStubFactory, std::shared_ptr<const joynr::system::RoutingTypes::Address> libjoynrMessagingAddress, std::shared_ptr<const joynr::system::RoutingTypes::Address> ccMessagingAddress) { // create messaging stub factory auto messagingStubFactory = std::make_unique<MessagingStubFactory>(); messagingStubFactory->registerStubFactory(std::move(middlewareMessagingStubFactory)); messagingStubFactory->registerStubFactory(std::make_unique<InProcessMessagingStubFactory>()); // create message router messageRouter = std::make_shared<MessageRouter>( std::move(messagingStubFactory), libjoynrMessagingAddress); startLibJoynrMessagingSkeleton(*messageRouter); joynrMessageSender = new JoynrMessageSender(messageRouter); joynrDispatcher = new Dispatcher(joynrMessageSender); joynrMessageSender->registerDispatcher(joynrDispatcher); // create the inprocess skeleton for the dispatcher dispatcherMessagingSkeleton = std::make_shared<InProcessLibJoynrMessagingSkeleton>(joynrDispatcher); dispatcherAddress = std::make_shared<InProcessMessagingAddress>(dispatcherMessagingSkeleton); publicationManager = new PublicationManager(); subscriptionManager = new SubscriptionManager(); inProcessDispatcher = new InProcessDispatcher(); inProcessPublicationSender = new InProcessPublicationSender(subscriptionManager); inProcessConnectorFactory = new InProcessConnectorFactory( subscriptionManager, publicationManager, inProcessPublicationSender, dynamic_cast<IRequestCallerDirectory*>(inProcessDispatcher)); joynrMessagingConnectorFactory = new JoynrMessagingConnectorFactory(joynrMessageSender, subscriptionManager); auto connectorFactory = std::make_unique<ConnectorFactory>( inProcessConnectorFactory, joynrMessagingConnectorFactory); proxyFactory = new ProxyFactory(libjoynrMessagingAddress, std::move(connectorFactory), nullptr); // Set up the persistence file for storing provider participant ids std::string persistenceFilename = libjoynrSettings->getParticipantIdsPersistenceFilename(); participantIdStorage = std::make_shared<ParticipantIdStorage>(persistenceFilename); // initialize the dispatchers std::vector<IDispatcher*> dispatcherList; dispatcherList.push_back(inProcessDispatcher); dispatcherList.push_back(joynrDispatcher); joynrDispatcher->registerPublicationManager(publicationManager); joynrDispatcher->registerSubscriptionManager(subscriptionManager); discoveryProxy = std::make_unique<LocalDiscoveryAggregator>(systemServicesSettings); requestCallerDirectory = dynamic_cast<IRequestCallerDirectory*>(inProcessDispatcher); std::string systemServicesDomain = systemServicesSettings.getDomain(); std::string routingProviderParticipantId = systemServicesSettings.getCcRoutingProviderParticipantId(); DiscoveryQos routingProviderDiscoveryQos; routingProviderDiscoveryQos.setCacheMaxAgeMs(1000); routingProviderDiscoveryQos.setArbitrationStrategy( DiscoveryQos::ArbitrationStrategy::FIXED_PARTICIPANT); routingProviderDiscoveryQos.addCustomParameter( "fixedParticipantId", routingProviderParticipantId); routingProviderDiscoveryQos.setDiscoveryTimeoutMs(50); auto routingProxyBuilder = createProxyBuilder<joynr::system::RoutingProxy>(systemServicesDomain); auto routingProxy = routingProxyBuilder->setMessagingQos(MessagingQos(10000)) ->setCached(false) ->setDiscoveryQos(routingProviderDiscoveryQos) ->build(); messageRouter->setParentRouter(std::unique_ptr<system::RoutingProxy>(routingProxy), ccMessagingAddress, routingProviderParticipantId); delete routingProxyBuilder; // setup discovery std::string discoveryProviderParticipantId = systemServicesSettings.getCcDiscoveryProviderParticipantId(); DiscoveryQos discoveryProviderDiscoveryQos; discoveryProviderDiscoveryQos.setCacheMaxAgeMs(1000); discoveryProviderDiscoveryQos.setArbitrationStrategy( DiscoveryQos::ArbitrationStrategy::FIXED_PARTICIPANT); discoveryProviderDiscoveryQos.addCustomParameter( "fixedParticipantId", discoveryProviderParticipantId); discoveryProviderDiscoveryQos.setDiscoveryTimeoutMs(1000); ProxyBuilder<joynr::system::DiscoveryProxy>* discoveryProxyBuilder = createProxyBuilder<joynr::system::DiscoveryProxy>(systemServicesDomain); joynr::system::IDiscoverySync* proxy = discoveryProxyBuilder->setMessagingQos(MessagingQos(10000)) ->setCached(false) ->setDiscoveryQos(discoveryProviderDiscoveryQos) ->build(); discoveryProxy->setDiscoveryProxy(std::unique_ptr<joynr::system::IDiscoverySync>(proxy)); capabilitiesRegistrar = std::make_unique<CapabilitiesRegistrar>( dispatcherList, *discoveryProxy, participantIdStorage, dispatcherAddress, messageRouter, messagingSettings.getDiscoveryEntryExpiryIntervalMs()); }
void LibJoynrRuntime::init( std::shared_ptr<IMiddlewareMessagingStubFactory> middlewareMessagingStubFactory, std::shared_ptr<const joynr::system::RoutingTypes::Address> libjoynrMessagingAddress, std::shared_ptr<const joynr::system::RoutingTypes::Address> ccMessagingAddress, std::unique_ptr<IMulticastAddressCalculator> addressCalculator, std::function<void()> onSuccess, std::function<void(const joynr::exceptions::JoynrRuntimeException&)> onError) { // create messaging stub factory auto messagingStubFactory = std::make_shared<MessagingStubFactory>(); middlewareMessagingStubFactory->registerOnMessagingStubClosedCallback([messagingStubFactory]( std::shared_ptr<const joynr::system::RoutingTypes::Address> destinationAddress) { messagingStubFactory->remove(std::move(destinationAddress)); }); messagingStubFactory->registerStubFactory(middlewareMessagingStubFactory); messagingStubFactory->registerStubFactory(std::make_shared<InProcessMessagingStubFactory>()); std::string routingProviderParticipantId = systemServicesSettings.getCcRoutingProviderParticipantId(); // create message router libJoynrMessageRouter = std::make_shared<LibJoynrMessageRouter>( messagingSettings, libjoynrMessagingAddress, std::move(messagingStubFactory), singleThreadIOService->getIOService(), std::move(addressCalculator), libjoynrSettings->isMessageRouterPersistencyEnabled(), std::vector<std::shared_ptr<ITransportStatus>>{}, std::make_unique<MessageQueue<std::string>>(), std::make_unique<MessageQueue<std::shared_ptr<ITransportStatus>>>()); libJoynrMessageRouter->init(); libJoynrMessageRouter->loadRoutingTable( libjoynrSettings->getMessageRouterPersistenceFilename()); libJoynrMessageRouter->setParentAddress(routingProviderParticipantId, ccMessagingAddress); startLibJoynrMessagingSkeleton(libJoynrMessageRouter); messageSender = std::make_shared<MessageSender>( libJoynrMessageRouter, keyChain, messagingSettings.getTtlUpliftMs()); joynrDispatcher = std::make_shared<Dispatcher>(messageSender, singleThreadIOService->getIOService()); messageSender->registerDispatcher(joynrDispatcher); // create the inprocess skeleton for the dispatcher dispatcherMessagingSkeleton = std::make_shared<InProcessMessagingSkeleton>(joynrDispatcher); dispatcherAddress = std::make_shared<InProcessMessagingAddress>(dispatcherMessagingSkeleton); publicationManager = std::make_shared<PublicationManager>( singleThreadIOService->getIOService(), messageSender, libjoynrSettings->isSubscriptionPersistencyEnabled(), messagingSettings.getTtlUpliftMs()); publicationManager->loadSavedAttributeSubscriptionRequestsMap( libjoynrSettings->getSubscriptionRequestPersistenceFilename()); publicationManager->loadSavedBroadcastSubscriptionRequestsMap( libjoynrSettings->getBroadcastSubscriptionRequestPersistenceFilename()); subscriptionManager = std::make_shared<SubscriptionManager>( singleThreadIOService->getIOService(), libJoynrMessageRouter); auto joynrMessagingConnectorFactory = std::make_shared<JoynrMessagingConnectorFactory>(messageSender, subscriptionManager); proxyFactory = std::make_unique<ProxyFactory>(joynrMessagingConnectorFactory); // Set up the persistence file for storing provider participant ids std::string persistenceFilename = libjoynrSettings->getParticipantIdsPersistenceFilename(); participantIdStorage = std::make_shared<ParticipantIdStorage>(persistenceFilename); // initialize the dispatchers joynrDispatcher->registerPublicationManager(publicationManager); joynrDispatcher->registerSubscriptionManager(subscriptionManager); discoveryProxy = std::make_shared<LocalDiscoveryAggregator>(getProvisionedEntries()); auto onSuccessBuildInternalProxies = [ thisSharedPtr = shared_from_this(), this, onSuccess, onError ]() { auto onSuccessGetGlobalAddress = [thisSharedPtr, this, onSuccess, onError](const std::string& globalAddress) { const std::string savedGlobalAddress(globalAddress); auto onSuccessGetReplyToAddress = [thisSharedPtr, this, onSuccess, savedGlobalAddress]( const std::string& replyAddress) { messageSender->setReplyToAddress(replyAddress); std::vector<std::shared_ptr<IDispatcher>> dispatcherList; dispatcherList.push_back(joynrDispatcher); capabilitiesRegistrar = std::make_unique<CapabilitiesRegistrar>( dispatcherList, discoveryProxy, participantIdStorage, dispatcherAddress, libJoynrMessageRouter, messagingSettings.getDiscoveryEntryExpiryIntervalMs(), publicationManager, savedGlobalAddress); if (onSuccess) { onSuccess(); } }; auto onErrorGetReplyToAddress = [onError](const joynr::exceptions::JoynrRuntimeException& error) { JOYNR_LOG_FATAL(logger(), "onErrorGetReplyToAddress: got exception: {}", error.getMessage()); if (onError) { onError(error); } }; ccRoutingProxy->getReplyToAddressAsync( std::move(onSuccessGetReplyToAddress), std::move(onErrorGetReplyToAddress)); }; auto onErrorGetGlobalAddress = [onError](const joynr::exceptions::JoynrRuntimeException& error) { JOYNR_LOG_FATAL( logger(), "onErrorGetGlobalAddress: got exception: {}", error.getMessage()); if (onError) { onError(error); } }; ccRoutingProxy->getGlobalAddressAsync( std::move(onSuccessGetGlobalAddress), std::move(onErrorGetGlobalAddress)); }; auto onErrorBuildInternalProxies = [onError](const joynr::exceptions::JoynrRuntimeException& error) { JOYNR_LOG_FATAL( logger(), "onErrorBuildInternalProxies: got exception: {}", error.getMessage()); if (onError) { onError(error); } }; buildInternalProxies(joynrMessagingConnectorFactory, onSuccessBuildInternalProxies, onErrorBuildInternalProxies); }