X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=include%2Fprivate%2Fredis%2Fasyncsentineldatabasediscovery.hpp;fp=include%2Fprivate%2Fredis%2Fasyncsentineldatabasediscovery.hpp;h=527fa4ed41dd18b4690eeb7df5e3f98cc910020f;hb=8324d029ce006509ddbc605446d05987c17e0368;hp=0000000000000000000000000000000000000000;hpb=ef2bf51d04aaf01fa0cabdcaf905b23423067662;p=ric-plt%2Fsdl.git diff --git a/include/private/redis/asyncsentineldatabasediscovery.hpp b/include/private/redis/asyncsentineldatabasediscovery.hpp new file mode 100644 index 0000000..527fa4e --- /dev/null +++ b/include/private/redis/asyncsentineldatabasediscovery.hpp @@ -0,0 +1,85 @@ +/* + Copyright (c) 2018-2019 Nokia. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef SHAREDDATALAYER_REDIS_ASYNCSENTINELDATABASEDISCOVERY_HPP_ +#define SHAREDDATALAYER_REDIS_ASYNCSENTINELDATABASEDISCOVERY_HPP_ + +#include +#include +#include "private/redis/asyncdatabasediscovery.hpp" +#include "private/redis/databaseinfo.hpp" +#include "private/logger.hpp" +#include "private/timer.hpp" + +namespace shareddatalayer +{ + namespace redis + { + class AsyncCommandDispatcher; + struct Contents; + class ContentsBuilder; + class Reply; + } + + class Engine; + + namespace redis + { + class AsyncSentinelDatabaseDiscovery: public AsyncDatabaseDiscovery + { + public: + using AsyncCommandDispatcherCreator = std::function(Engine& engine, + const redis::DatabaseInfo& databaseInfo, + std::shared_ptr contentsBuilder, + std::shared_ptr logger)>; + + AsyncSentinelDatabaseDiscovery(const AsyncSentinelDatabaseDiscovery&) = delete; + + AsyncSentinelDatabaseDiscovery& operator = (const AsyncSentinelDatabaseDiscovery&) = delete; + + AsyncSentinelDatabaseDiscovery(std::shared_ptr engine, + std::shared_ptr logger); + + AsyncSentinelDatabaseDiscovery(std::shared_ptr engine, + std::shared_ptr logger, + const AsyncCommandDispatcherCreator& asyncCommandDispatcherCreator, + std::shared_ptr contentsBuilder); + + ~AsyncSentinelDatabaseDiscovery() override = default; + + void setStateChangedCb(const StateChangedCb& stateChangedCb) override; + + void clearStateChangedCb() override; + + void setConnected(bool state); + private: + std::shared_ptr engine; + std::shared_ptr logger; + StateChangedCb stateChangedCb; + DatabaseInfo databaseInfo; + std::shared_ptr dispatcher; + std::shared_ptr contentsBuilder; + Timer masterInquiryRetryTimer; + Timer::Duration masterInquiryRetryTimerDuration; + + void sendMasterInquiry(); + + void masterInquiryAck(const std::error_code& error, const Reply& reply); + }; + } +} + +#endif