X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=include%2Fprivate%2Fredis%2Fasynchiredisclustercommanddispatcher.hpp;fp=include%2Fprivate%2Fredis%2Fasynchiredisclustercommanddispatcher.hpp;h=844829421c1544ab86fe3fdf7c567e59db092bb7;hb=ef2bf51d04aaf01fa0cabdcaf905b23423067662;hp=0000000000000000000000000000000000000000;hpb=edc9b96a441194b571e8d55ec1603b5be0ea52eb;p=ric-plt%2Fsdl.git diff --git a/include/private/redis/asynchiredisclustercommanddispatcher.hpp b/include/private/redis/asynchiredisclustercommanddispatcher.hpp new file mode 100644 index 0000000..8448294 --- /dev/null +++ b/include/private/redis/asynchiredisclustercommanddispatcher.hpp @@ -0,0 +1,138 @@ +/* + 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_ASYNCHIREDISCLUSTERCOMMANDDISPATCHER_HPP_ +#define SHAREDDATALAYER_REDIS_ASYNCHIREDISCLUSTERCOMMANDDISPATCHER_HPP_ + +#include "private/redis/asynccommanddispatcher.hpp" +#include "private/databaseconfiguration.hpp" +#include "private/logger.hpp" +#include "private/timer.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" +{ + struct redisReply; + struct redisClusterAsyncContext; + struct redisAsyncContext; +} + +namespace shareddatalayer +{ + class Engine; + + namespace redis + { + class HiredisClusterSystem; + class HiredisClusterEpollAdapter; + class Reply; + + class AsyncHiredisClusterCommandDispatcher: public AsyncCommandDispatcher + { + public: + AsyncHiredisClusterCommandDispatcher(const AsyncHiredisClusterCommandDispatcher&) = delete; + + AsyncHiredisClusterCommandDispatcher& operator = (const AsyncHiredisClusterCommandDispatcher&) = delete; + + AsyncHiredisClusterCommandDispatcher(Engine& engine, + const boost::optional& ns, + const DatabaseConfiguration::Addresses& addresses, + std::shared_ptr contentsBuilder, + bool usePermanentCommandCallbacks, + std::shared_ptr logger); + + AsyncHiredisClusterCommandDispatcher(Engine& engine, + const boost::optional& ns, + const DatabaseConfiguration::Addresses& addresses, + std::shared_ptr contentsBuilder, + bool usePermanentCommandCallbacks, + HiredisClusterSystem& hiredisClusterSystem, + std::shared_ptr adapter, + std::shared_ptr logger); + + ~AsyncHiredisClusterCommandDispatcher() override; + + void waitConnectedAsync(const ConnectAck& connectAck) override; + + void registerDisconnectCb(const DisconnectCb& disconnectCb) override; + + void dispatchAsync(const CommandCb& commandCb, const AsyncConnection::Namespace& ns, const Contents& contents) override; + + void disableCommandCallbacks() override; + + void handleReply(const CommandCb& commandCb, const std::error_code& error, const redisReply* rr); + + bool isClientCallbacksEnabled() const; + + void handleDisconnect(const redisAsyncContext* ac); + + private: + enum class ServiceState + { + DISCONNECTED, + CONNECTED + }; + + using Callback = std::function; + + Engine& engine; + const boost::optional initialNamespace; + const DatabaseConfiguration::Addresses addresses; + std::shared_ptr contentsBuilder; + bool usePermanentCommandCallbacks; + HiredisClusterSystem& hiredisClusterSystem; + std::shared_ptr adapter; + redisClusterAsyncContext* acc; + ConnectAck connectAck; + DisconnectCb disconnectCallback; + ServiceState serviceState; + std::list cbs; + bool clientCallbacksEnabled; + Timer connectionRetryTimer; + Timer::Duration connectionRetryTimerDuration; + std::shared_ptr logger; + + void connect(); + + bool isValidCb(const CommandCb& commandCb); + + void removeCb(const CommandCb& commandCb); + + void callCommandCbWithError(const CommandCb& commandCb, const std::error_code& error); + + void dispatchAsync(const CommandCb& commandCb, const AsyncConnection::Namespace& ns, const Contents& contents, bool checkConnectionState); + + void verifyConnection(); + + void verifyConnectionReply(const std::error_code& error, const redis::Reply& reply); + + void setConnected(); + + void armConnectionRetryTimer(); + + void disconnectHiredisCluster(); + }; + } +} + +#endif