Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 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 | #ifndef SHAREDDATALAYER_REDIS_ASYNCSTORAGEIMPL_HPP_ |
| 18 | #define SHAREDDATALAYER_REDIS_ASYNCSTORAGEIMPL_HPP_ |
| 19 | |
Rolf Badorek | 8324d02 | 2019-09-17 16:47:20 +0300 | [diff] [blame] | 20 | #include <functional> |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 21 | #include <sdl/asyncstorage.hpp> |
| 22 | #include <sdl/publisherid.hpp> |
| 23 | #include "private/configurationreader.hpp" |
| 24 | #include "private/databaseconfigurationimpl.hpp" |
| 25 | #include "private/logger.hpp" |
| 26 | #include "private/namespaceconfigurationsimpl.hpp" |
Rolf Badorek | 8324d02 | 2019-09-17 16:47:20 +0300 | [diff] [blame] | 27 | #include "private/redis/asyncdatabasediscovery.hpp" |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 28 | |
| 29 | namespace shareddatalayer |
| 30 | { |
| 31 | class Engine; |
| 32 | |
| 33 | class AsyncStorageImpl: public AsyncStorage |
| 34 | { |
| 35 | public: |
Rolf Badorek | 8324d02 | 2019-09-17 16:47:20 +0300 | [diff] [blame] | 36 | using AsyncDatabaseDiscoveryCreator = std::function<std::shared_ptr<redis::AsyncDatabaseDiscovery>(std::shared_ptr<Engine> engine, |
| 37 | const DatabaseConfiguration& databaseConfiguration, |
| 38 | std::shared_ptr<Logger> logger)>; |
| 39 | |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 40 | AsyncStorageImpl(const AsyncStorageImpl&) = delete; |
| 41 | |
| 42 | AsyncStorageImpl& operator = (const AsyncStorageImpl&) = delete; |
| 43 | |
| 44 | AsyncStorageImpl(AsyncStorageImpl&&) = delete; |
| 45 | |
| 46 | AsyncStorageImpl& operator = (AsyncStorageImpl&&) = delete; |
| 47 | |
| 48 | AsyncStorageImpl(std::shared_ptr<Engine> engine, |
| 49 | const boost::optional<PublisherId>& pId, |
| 50 | std::shared_ptr<Logger> logger); |
| 51 | |
| 52 | // Meant for UT |
| 53 | AsyncStorageImpl(std::shared_ptr<Engine> engine, |
| 54 | const boost::optional<PublisherId>& pId, |
| 55 | std::shared_ptr<DatabaseConfiguration> databaseConfiguration, |
| 56 | std::shared_ptr<NamespaceConfigurations> namespaceConfigurations, |
Rolf Badorek | 8324d02 | 2019-09-17 16:47:20 +0300 | [diff] [blame] | 57 | std::shared_ptr<Logger> logger, |
| 58 | const AsyncDatabaseDiscoveryCreator& asyncDatabaseDiscoveryCreator); |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 59 | |
| 60 | int fd() const override; |
| 61 | |
| 62 | void handleEvents() override; |
| 63 | |
| 64 | void waitReadyAsync(const Namespace& ns, const ReadyAck& readyAck) override; |
| 65 | |
| 66 | void setAsync(const Namespace& ns, const DataMap& dataMap, const ModifyAck& modifyAck) override; |
| 67 | |
| 68 | void setIfAsync(const Namespace& ns, const Key& key, const Data& oldData, const Data& newData, const ModifyIfAck& modifyIfAck) override; |
| 69 | |
| 70 | void setIfNotExistsAsync(const Namespace& ns, const Key& key, const Data& data, const ModifyIfAck& modifyIfAck) override; |
| 71 | |
| 72 | void getAsync(const Namespace& ns, const Keys& keys, const GetAck& getAck) override; |
| 73 | |
| 74 | void removeAsync(const Namespace& ns, const Keys& keys, const ModifyAck& modifyAck) override; |
| 75 | |
| 76 | void removeIfAsync(const Namespace& ns, const Key& key, const Data& data, const ModifyIfAck& modifyIfAck) override; |
| 77 | |
| 78 | void findKeysAsync(const Namespace& ns, const std::string& keyPrefix, const FindKeysAck& findKeysAck) override; |
| 79 | |
| 80 | void removeAllAsync(const Namespace& ns, const ModifyAck& modifyAck) override; |
| 81 | |
| 82 | //public for UT |
| 83 | AsyncStorage& getOperationHandler(const std::string& ns); |
| 84 | private: |
| 85 | std::shared_ptr<Engine> engine; |
| 86 | std::shared_ptr<DatabaseConfiguration> databaseConfiguration; |
| 87 | std::shared_ptr<NamespaceConfigurations> namespaceConfigurations; |
| 88 | const boost::optional<PublisherId> publisherId; |
| 89 | std::shared_ptr<Logger> logger; |
Rolf Badorek | 8324d02 | 2019-09-17 16:47:20 +0300 | [diff] [blame] | 90 | AsyncDatabaseDiscoveryCreator asyncDatabaseDiscoveryCreator; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 91 | |
| 92 | AsyncStorage& getRedisHandler(); |
| 93 | AsyncStorage& getDummyHandler(); |
| 94 | }; |
| 95 | } |
| 96 | |
| 97 | #endif |