Add extra line about src files are part of RIC platform project
[ric-plt/sdl.git] / include / private / redis / asyncsentineldatabasediscovery.hpp
1 /*
2    Copyright (c) 2018-2019 Nokia.
3
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
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
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.
15 */
16
17 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20 */
21
22 #ifndef SHAREDDATALAYER_REDIS_ASYNCSENTINELDATABASEDISCOVERY_HPP_
23 #define SHAREDDATALAYER_REDIS_ASYNCSENTINELDATABASEDISCOVERY_HPP_
24
25 #include <functional>
26 #include <system_error>
27 #include "private/redis/asyncdatabasediscovery.hpp"
28 #include "private/redis/databaseinfo.hpp"
29 #include "private/logger.hpp"
30 #include "private/timer.hpp"
31
32 namespace shareddatalayer
33 {
34     namespace redis
35     {
36         class AsyncCommandDispatcher;
37         struct Contents;
38         class ContentsBuilder;
39         class Reply;
40     }
41
42     class Engine;
43
44     namespace redis
45     {
46         class AsyncSentinelDatabaseDiscovery: public AsyncDatabaseDiscovery
47         {
48         public:
49             using AsyncCommandDispatcherCreator = std::function<std::shared_ptr<redis::AsyncCommandDispatcher>(Engine& engine,
50                                                                                                                const redis::DatabaseInfo& databaseInfo,
51                                                                                                                std::shared_ptr<redis::ContentsBuilder> contentsBuilder,
52                                                                                                                std::shared_ptr<Logger> logger,
53                                                                                                                bool usePermanentCommandCallbacks)>;
54
55             AsyncSentinelDatabaseDiscovery(const AsyncSentinelDatabaseDiscovery&) = delete;
56
57             AsyncSentinelDatabaseDiscovery& operator = (const AsyncSentinelDatabaseDiscovery&) = delete;
58
59             AsyncSentinelDatabaseDiscovery(std::shared_ptr<Engine> engine,
60                                            std::shared_ptr<Logger> logger,
61                                            const HostAndPort& sentinelAddress,
62                                            const std::string& sentinelMasterName);
63
64             AsyncSentinelDatabaseDiscovery(std::shared_ptr<Engine> engine,
65                                            std::shared_ptr<Logger> logger,
66                                            const HostAndPort& sentinelAddress,
67                                            const std::string& sentinelMasterName,
68                                            const AsyncCommandDispatcherCreator& asyncCommandDispatcherCreator,
69                                            std::shared_ptr<redis::ContentsBuilder> contentsBuilder);
70
71             ~AsyncSentinelDatabaseDiscovery() override;
72
73             void setStateChangedCb(const StateChangedCb& stateChangedCb) override;
74
75             void clearStateChangedCb() override;
76
77             void setConnected(bool state);
78         private:
79             std::shared_ptr<Engine> engine;
80             std::shared_ptr<Logger> logger;
81             StateChangedCb stateChangedCb;
82             DatabaseInfo databaseInfo;
83             std::string sentinelMasterName;
84             std::shared_ptr<redis::AsyncCommandDispatcher> subscriber;
85             std::shared_ptr<redis::AsyncCommandDispatcher> dispatcher;
86             std::shared_ptr<redis::ContentsBuilder> contentsBuilder;
87             Timer subscribeRetryTimer;
88             Timer::Duration subscribeRetryTimerDuration;
89             Timer masterInquiryRetryTimer;
90             Timer::Duration masterInquiryRetryTimerDuration;
91
92             void subscribeNotifications();
93
94             void subscribeAck(const std::error_code& error, const Reply& reply);
95
96             void sendMasterInquiry();
97
98             void masterInquiryAck(const std::error_code& error, const Reply& reply);
99         };
100     }
101 }
102
103 #endif