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()); }
ShortCircuitRuntime::ShortCircuitRuntime(std::unique_ptr<Settings> settings, std::shared_ptr<IKeychain> keyChain) : JoynrRuntimeImpl(*settings), keyChain(std::move(keyChain)), clusterControllerSettings(*settings), ownAddress(), enablePersistency(true) { auto messagingStubFactory = std::make_unique<MessagingStubFactory>(); requestCallerDirectory = std::make_shared<DummyRequestCallerDirectory>(); messagingStubFactory->registerStubFactory(std::make_unique<InProcessMessagingStubFactory>()); const std::string multicastTopicPrefix = ""; std::unique_ptr<IMulticastAddressCalculator> addressCalculator = std::make_unique<MqttMulticastAddressCalculator>(nullptr, multicastTopicPrefix); const std::string& globalClusterControllerAddress("globalAddress"); const std::string messageNotificationProviderParticipantId( "messageNotificationProviderParticipantId"); messageRouter = std::make_shared<CcMessageRouter>( messagingSettings, clusterControllerSettings, std::move(messagingStubFactory), nullptr, nullptr, singleThreadedIOService.getIOService(), std::move(addressCalculator), globalClusterControllerAddress, messageNotificationProviderParticipantId, enablePersistency, std::vector<std::shared_ptr<ITransportStatus>>{}, std::make_unique<MessageQueue<std::string>>(), std::make_unique<MessageQueue<std::shared_ptr<ITransportStatus>>>(), ownAddress); messageSender = std::make_shared<MessageSender>(messageRouter, keyChain); joynrDispatcher = std::make_shared<Dispatcher>(messageSender, singleThreadedIOService.getIOService()); messageSender->registerDispatcher(joynrDispatcher); dispatcherMessagingSkeleton = std::make_shared<InProcessMessagingSkeleton>(joynrDispatcher); dispatcherAddress = std::make_shared<InProcessMessagingAddress>(dispatcherMessagingSkeleton); publicationManager = std::make_shared<PublicationManager>( singleThreadedIOService.getIOService(), messageSender, enablePersistency); subscriptionManager = std::make_shared<SubscriptionManager>( singleThreadedIOService.getIOService(), messageRouter); auto joynrMessagingConnectorFactory = std::make_unique<JoynrMessagingConnectorFactory>(messageSender, subscriptionManager); proxyFactory = std::make_unique<ProxyFactory>(std::move(joynrMessagingConnectorFactory)); std::string persistenceFilename = "dummy.txt"; participantIdStorage = std::make_shared<ParticipantIdStorage>(persistenceFilename); std::vector<std::shared_ptr<IDispatcher>> dispatcherList; dispatcherList.push_back(joynrDispatcher); joynrDispatcher->registerPublicationManager(publicationManager); joynrDispatcher->registerSubscriptionManager(subscriptionManager); discoveryProxy = std::make_shared<DummyDiscovery>(); capabilitiesRegistrar = std::make_unique<CapabilitiesRegistrar>(dispatcherList, discoveryProxy, participantIdStorage, dispatcherAddress, messageRouter, std::numeric_limits<std::int64_t>::max(), publicationManager, globalClusterControllerAddress); maximumTtlMs = std::chrono::milliseconds(std::chrono::hours(24) * 30).count(); }
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); }
ShortCircuitRuntime::ShortCircuitRuntime() { std::string libjoynrMessagingId = "libjoynr.messaging.participantid_short-circuit-uuid"; auto libjoynrMessagingAddress = std::make_shared<joynr::system::RoutingTypes::WebSocketClientAddress>( libjoynrMessagingId); auto messagingStubFactory = std::make_unique<MessagingStubFactory>(); messagingStubFactory->registerStubFactory(std::make_unique<InProcessMessagingStubFactory>()); messageRouter = std::make_shared<MessageRouter>( std::move(messagingStubFactory), libjoynrMessagingAddress); joynrMessageSender = std::make_unique<JoynrMessageSender>(messageRouter); joynrDispatcher = new Dispatcher(joynrMessageSender.get()); joynrMessageSender->registerDispatcher(joynrDispatcher); dispatcherMessagingSkeleton = std::make_shared<InProcessLibJoynrMessagingSkeleton>(joynrDispatcher); dispatcherAddress = std::make_shared<InProcessMessagingAddress>(dispatcherMessagingSkeleton); publicationManager = new PublicationManager(); subscriptionManager = new SubscriptionManager(); inProcessDispatcher = new InProcessDispatcher(); inProcessPublicationSender = std::make_unique<InProcessPublicationSender>(subscriptionManager); inProcessConnectorFactory = new InProcessConnectorFactory( subscriptionManager, publicationManager, inProcessPublicationSender.get(), dynamic_cast<IRequestCallerDirectory*>(inProcessDispatcher)); joynrMessagingConnectorFactory = new JoynrMessagingConnectorFactory(joynrMessageSender.get(), subscriptionManager); auto connectorFactory = std::make_unique<ConnectorFactory>( inProcessConnectorFactory, joynrMessagingConnectorFactory); proxyFactory = std::make_unique<ProxyFactory>( libjoynrMessagingAddress, std::move(connectorFactory), nullptr); std::string persistenceFilename = "dummy.txt"; participantIdStorage = std::make_shared<ParticipantIdStorage>(persistenceFilename); std::vector<IDispatcher*> dispatcherList; dispatcherList.push_back(inProcessDispatcher); dispatcherList.push_back(joynrDispatcher); joynrDispatcher->registerPublicationManager(publicationManager); joynrDispatcher->registerSubscriptionManager(subscriptionManager); discoveryProxy = std::make_unique<DummyDiscovery>(); capabilitiesRegistrar = std::make_unique<CapabilitiesRegistrar>(dispatcherList, *discoveryProxy, participantIdStorage, dispatcherAddress, messageRouter, std::numeric_limits<std::int64_t>::max()); maximumTtlMs = std::chrono::milliseconds(std::chrono::hours(24) * 30).count(); }