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.
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
22 #ifndef SHAREDDATALAYER_REDIS_ASYNCSTORAGEIMPL_HPP_
23 #define SHAREDDATALAYER_REDIS_ASYNCSTORAGEIMPL_HPP_
26 #include <sdl/asyncstorage.hpp>
27 #include <sdl/publisherid.hpp>
28 #include "private/configurationreader.hpp"
29 #include "private/databaseconfigurationimpl.hpp"
30 #include "private/logger.hpp"
31 #include "private/namespaceconfigurationsimpl.hpp"
32 #include "private/redis/asyncdatabasediscovery.hpp"
33 #include "private/redis/asyncredisstorage.hpp"
35 namespace shareddatalayer
39 class AsyncStorageImpl: public AsyncStorage
42 using AsyncDatabaseDiscoveryCreator = std::function<std::shared_ptr<redis::AsyncDatabaseDiscovery>(std::shared_ptr<Engine> engine,
43 const std::string& ns,
44 const DatabaseConfiguration& databaseConfiguration,
45 const boost::optional<std::size_t>& addressIndex,
46 std::shared_ptr<Logger> logger)>;
48 AsyncStorageImpl(const AsyncStorageImpl&) = delete;
50 AsyncStorageImpl& operator = (const AsyncStorageImpl&) = delete;
52 AsyncStorageImpl(AsyncStorageImpl&&) = delete;
54 AsyncStorageImpl& operator = (AsyncStorageImpl&&) = delete;
56 AsyncStorageImpl(std::shared_ptr<Engine> engine,
57 const boost::optional<PublisherId>& pId,
58 std::shared_ptr<Logger> logger);
61 AsyncStorageImpl(std::shared_ptr<Engine> engine,
62 const boost::optional<PublisherId>& pId,
63 std::shared_ptr<DatabaseConfiguration> databaseConfiguration,
64 std::shared_ptr<NamespaceConfigurations> namespaceConfigurations,
65 std::shared_ptr<Logger> logger,
66 const AsyncDatabaseDiscoveryCreator& asyncDatabaseDiscoveryCreator);
68 int fd() const override;
70 void handleEvents() override;
72 void waitReadyAsync(const Namespace& ns, const ReadyAck& readyAck) override;
74 void setAsync(const Namespace& ns, const DataMap& dataMap, const ModifyAck& modifyAck) override;
76 void setIfAsync(const Namespace& ns, const Key& key, const Data& oldData, const Data& newData, const ModifyIfAck& modifyIfAck) override;
78 void setIfNotExistsAsync(const Namespace& ns, const Key& key, const Data& data, const ModifyIfAck& modifyIfAck) override;
80 void getAsync(const Namespace& ns, const Keys& keys, const GetAck& getAck) override;
82 void removeAsync(const Namespace& ns, const Keys& keys, const ModifyAck& modifyAck) override;
84 void removeIfAsync(const Namespace& ns, const Key& key, const Data& data, const ModifyIfAck& modifyIfAck) override;
86 void findKeysAsync(const Namespace& ns, const std::string& keyPrefix, const FindKeysAck& findKeysAck) override;
88 void removeAllAsync(const Namespace& ns, const ModifyAck& modifyAck) override;
91 AsyncStorage& getOperationHandler(const std::string& ns);
93 std::shared_ptr<Engine> engine;
94 std::shared_ptr<DatabaseConfiguration> databaseConfiguration;
95 std::shared_ptr<NamespaceConfigurations> namespaceConfigurations;
96 const boost::optional<PublisherId> publisherId;
97 std::shared_ptr<Logger> logger;
98 AsyncDatabaseDiscoveryCreator asyncDatabaseDiscoveryCreator;
100 std::vector<std::shared_ptr<AsyncRedisStorage>> asyncStorages;
102 AsyncStorage& getRedisHandler(const std::string& ns);
103 AsyncStorage& getDummyHandler();
105 void setAsyncRedisStorageHandlers(const std::string& ns);
106 AsyncStorage& getAsyncRedisStorageHandler(const std::string& ns);