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_ASYNCCOMMANDDISPATCHER_HPP_
18 #define SHAREDDATALAYER_REDIS_ASYNCCOMMANDDISPATCHER_HPP_
21 #include <system_error>
25 #include "private/asyncconnection.hpp"
26 #include "private/logger.hpp"
28 namespace shareddatalayer
33 class ContentsBuilder;
38 class AsyncCommandDispatcher
41 AsyncCommandDispatcher(const AsyncCommandDispatcher&) = delete;
43 AsyncCommandDispatcher& operator = (const AsyncCommandDispatcher&) = delete;
45 virtual ~AsyncCommandDispatcher() = default;
47 using ConnectAck = std::function<void()>;
49 virtual void waitConnectedAsync(const ConnectAck& connectAck) = 0;
51 // NOTE: If there are connections open to several database instances, callback
52 // does not identify that which one was disconnected.
53 using DisconnectCb = std::function<void()>;
55 virtual void registerDisconnectCb(const DisconnectCb& disconnectCb) = 0;
57 using CommandCb = std::function<void(const std::error_code&, const Reply&)>;
59 virtual void dispatchAsync(const CommandCb& commandCb,
60 const AsyncConnection::Namespace& ns,
61 const Contents& contents) = 0;
63 virtual void disableCommandCallbacks() = 0;
65 static std::shared_ptr<AsyncCommandDispatcher> create(Engine& engine,
66 const DatabaseInfo& databaseInfo,
67 std::shared_ptr<ContentsBuilder> contentsBuilder,
68 bool usePermanentCommandCallbacks,
69 std::shared_ptr<Logger> logger,
70 bool usedForSentinel);
73 AsyncCommandDispatcher() = default;