blob: 34548f011d3466292398927b9ea8a734802af384 [file] [log] [blame]
Rolf Badorekef2bf512019-08-20 11:17:15 +03001/*
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
Timo Tietavainena0745d22019-11-28 09:55:22 +020017/*
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
20*/
21
Rolf Badorekef2bf512019-08-20 11:17:15 +030022#ifndef SHAREDDATALAYER_REDIS_ASYNCSTORAGEIMPL_HPP_
23#define SHAREDDATALAYER_REDIS_ASYNCSTORAGEIMPL_HPP_
24
Rolf Badorek8324d022019-09-17 16:47:20 +030025#include <functional>
Rolf Badorekef2bf512019-08-20 11:17:15 +030026#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"
Rolf Badorek8324d022019-09-17 16:47:20 +030032#include "private/redis/asyncdatabasediscovery.hpp"
Rolf Badorekef2bf512019-08-20 11:17:15 +030033
34namespace shareddatalayer
35{
36 class Engine;
37
38 class AsyncStorageImpl: public AsyncStorage
39 {
40 public:
Rolf Badorek8324d022019-09-17 16:47:20 +030041 using AsyncDatabaseDiscoveryCreator = std::function<std::shared_ptr<redis::AsyncDatabaseDiscovery>(std::shared_ptr<Engine> engine,
42 const DatabaseConfiguration& databaseConfiguration,
43 std::shared_ptr<Logger> logger)>;
44
Rolf Badorekef2bf512019-08-20 11:17:15 +030045 AsyncStorageImpl(const AsyncStorageImpl&) = delete;
46
47 AsyncStorageImpl& operator = (const AsyncStorageImpl&) = delete;
48
49 AsyncStorageImpl(AsyncStorageImpl&&) = delete;
50
51 AsyncStorageImpl& operator = (AsyncStorageImpl&&) = delete;
52
53 AsyncStorageImpl(std::shared_ptr<Engine> engine,
54 const boost::optional<PublisherId>& pId,
55 std::shared_ptr<Logger> logger);
56
57 // Meant for UT
58 AsyncStorageImpl(std::shared_ptr<Engine> engine,
59 const boost::optional<PublisherId>& pId,
60 std::shared_ptr<DatabaseConfiguration> databaseConfiguration,
61 std::shared_ptr<NamespaceConfigurations> namespaceConfigurations,
Rolf Badorek8324d022019-09-17 16:47:20 +030062 std::shared_ptr<Logger> logger,
63 const AsyncDatabaseDiscoveryCreator& asyncDatabaseDiscoveryCreator);
Rolf Badorekef2bf512019-08-20 11:17:15 +030064
65 int fd() const override;
66
67 void handleEvents() override;
68
69 void waitReadyAsync(const Namespace& ns, const ReadyAck& readyAck) override;
70
71 void setAsync(const Namespace& ns, const DataMap& dataMap, const ModifyAck& modifyAck) override;
72
73 void setIfAsync(const Namespace& ns, const Key& key, const Data& oldData, const Data& newData, const ModifyIfAck& modifyIfAck) override;
74
75 void setIfNotExistsAsync(const Namespace& ns, const Key& key, const Data& data, const ModifyIfAck& modifyIfAck) override;
76
77 void getAsync(const Namespace& ns, const Keys& keys, const GetAck& getAck) override;
78
79 void removeAsync(const Namespace& ns, const Keys& keys, const ModifyAck& modifyAck) override;
80
81 void removeIfAsync(const Namespace& ns, const Key& key, const Data& data, const ModifyIfAck& modifyIfAck) override;
82
83 void findKeysAsync(const Namespace& ns, const std::string& keyPrefix, const FindKeysAck& findKeysAck) override;
84
85 void removeAllAsync(const Namespace& ns, const ModifyAck& modifyAck) override;
86
87 //public for UT
88 AsyncStorage& getOperationHandler(const std::string& ns);
89 private:
90 std::shared_ptr<Engine> engine;
91 std::shared_ptr<DatabaseConfiguration> databaseConfiguration;
92 std::shared_ptr<NamespaceConfigurations> namespaceConfigurations;
93 const boost::optional<PublisherId> publisherId;
94 std::shared_ptr<Logger> logger;
Rolf Badorek8324d022019-09-17 16:47:20 +030095 AsyncDatabaseDiscoveryCreator asyncDatabaseDiscoveryCreator;
Rolf Badorekef2bf512019-08-20 11:17:15 +030096
97 AsyncStorage& getRedisHandler();
98 AsyncStorage& getDummyHandler();
99 };
100}
101
102#endif