+void AsyncSentinelDatabaseDiscovery::subscribeNotifications()
+{
+ subscriber->dispatchAsync(std::bind(&AsyncSentinelDatabaseDiscovery::subscribeAck,
+ this,
+ std::placeholders::_1,
+ std::placeholders::_2),
+ "dummyNamespace", // Not meaningful for Sentinel
+ contentsBuilder->build("SUBSCRIBE", "+switch-master"));
+}
+
+void AsyncSentinelDatabaseDiscovery::subscribeAck(const std::error_code& error,
+ const Reply& reply)
+{
+ if (!error)
+ {
+ auto subscribeReply = parseSubscribeReply(reply, *logger);
+ if (subscribeReply)
+ {
+ switch (subscribeReply->type)
+ {
+ case (SubscribeReply::Type::SUBSCRIBE_REPLY):
+ {
+ dispatcher->waitConnectedAsync(std::bind(&AsyncSentinelDatabaseDiscovery::sendMasterInquiry, this));
+ break;
+ }
+ case (SubscribeReply::Type::NOTIFICATION):
+ {
+ auto hostAndPort = parseNotificationMessage(subscribeReply->message, *logger);
+ if (hostAndPort)
+ {
+ auto databaseInfo(DatabaseInfo({DatabaseConfiguration::Addresses({*hostAndPort}),
+ DatabaseInfo::Type::SINGLE,
+ boost::none,
+ DatabaseInfo::Discovery::SENTINEL}));
+ if (stateChangedCb)
+ stateChangedCb(databaseInfo);
+ }
+ else
+ SHAREDDATALAYER_ABORT("Notification message parsing error.");
+ break;
+ }
+ case (SubscribeReply::Type::UNKNOWN):
+ {
+ logger->debug() << "Invalid SUBSCRIBE reply type." << std::endl;
+ SHAREDDATALAYER_ABORT("Invalid SUBSCRIBE command reply type.");
+ }
+ }
+ }
+ else
+ SHAREDDATALAYER_ABORT("SUBSCRIBE command reply parsing error.");
+ }
+ else
+ subscribeRetryTimer.arm(
+ subscribeRetryTimerDuration,
+ std::bind(&AsyncSentinelDatabaseDiscovery::subscribeNotifications, this));
+}
+