2 Copyright (c) 2018-2019 Nokia.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 #ifndef SHAREDDATALAYER_REDIS_ASYNCSENTINELDATABASEDISCOVERY_HPP_
18 #define SHAREDDATALAYER_REDIS_ASYNCSENTINELDATABASEDISCOVERY_HPP_
21 #include <system_error>
22 #include "private/redis/asyncdatabasediscovery.hpp"
23 #include "private/redis/databaseinfo.hpp"
24 #include "private/logger.hpp"
25 #include "private/timer.hpp"
27 namespace shareddatalayer
31 class AsyncCommandDispatcher;
33 class ContentsBuilder;
41 class AsyncSentinelDatabaseDiscovery: public AsyncDatabaseDiscovery
44 using AsyncCommandDispatcherCreator = std::function<std::shared_ptr<redis::AsyncCommandDispatcher>(Engine& engine,
45 const redis::DatabaseInfo& databaseInfo,
46 std::shared_ptr<redis::ContentsBuilder> contentsBuilder,
47 std::shared_ptr<Logger> logger)>;
49 AsyncSentinelDatabaseDiscovery(const AsyncSentinelDatabaseDiscovery&) = delete;
51 AsyncSentinelDatabaseDiscovery& operator = (const AsyncSentinelDatabaseDiscovery&) = delete;
53 AsyncSentinelDatabaseDiscovery(std::shared_ptr<Engine> engine,
54 std::shared_ptr<Logger> logger);
56 AsyncSentinelDatabaseDiscovery(std::shared_ptr<Engine> engine,
57 std::shared_ptr<Logger> logger,
58 const AsyncCommandDispatcherCreator& asyncCommandDispatcherCreator,
59 std::shared_ptr<redis::ContentsBuilder> contentsBuilder);
61 ~AsyncSentinelDatabaseDiscovery() override = default;
63 void setStateChangedCb(const StateChangedCb& stateChangedCb) override;
65 void clearStateChangedCb() override;
67 void setConnected(bool state);
69 std::shared_ptr<Engine> engine;
70 std::shared_ptr<Logger> logger;
71 StateChangedCb stateChangedCb;
72 DatabaseInfo databaseInfo;
73 std::shared_ptr<redis::AsyncCommandDispatcher> dispatcher;
74 std::shared_ptr<redis::ContentsBuilder> contentsBuilder;
75 Timer masterInquiryRetryTimer;
76 Timer::Duration masterInquiryRetryTimerDuration;
78 void sendMasterInquiry();
80 void masterInquiryAck(const std::error_code& error, const Reply& reply);