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 | |
Timo Tietavainen | a0745d2 | 2019-11-28 09:55:22 +0200 | [diff] [blame] | 17 | /* |
| 18 | * This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 19 | * platform project (RICP). |
| 20 | */ |
| 21 | |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 22 | #include "private/redis/asynccommanddispatcher.hpp" |
| 23 | #include <cstdlib> |
| 24 | #include "config.h" |
| 25 | #include "private/redis/databaseinfo.hpp" |
| 26 | #if HAVE_HIREDIS_VIP |
| 27 | #include "private/redis/asynchiredisclustercommanddispatcher.hpp" |
| 28 | #include "private/redis/asynchirediscommanddispatcher.hpp" |
| 29 | #elif HAVE_HIREDIS |
| 30 | #include "private/redis/asynchirediscommanddispatcher.hpp" |
| 31 | #endif |
| 32 | #include "private/abort.hpp" |
| 33 | #include "private/engine.hpp" |
| 34 | |
| 35 | using namespace shareddatalayer::redis; |
| 36 | |
| 37 | std::shared_ptr<AsyncCommandDispatcher> AsyncCommandDispatcher::create(Engine& engine, |
| 38 | const DatabaseInfo& databaseInfo, |
| 39 | std::shared_ptr<ContentsBuilder> contentsBuilder, |
| 40 | bool usePermanentCommandCallbacks, |
Rolf Badorek | 8324d02 | 2019-09-17 16:47:20 +0300 | [diff] [blame] | 41 | std::shared_ptr<Logger> logger, |
| 42 | bool usedForSentinel) |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 43 | { |
| 44 | #if HAVE_HIREDIS_VIP |
Rolf Badorek | 8324d02 | 2019-09-17 16:47:20 +0300 | [diff] [blame] | 45 | static_cast<void>(usedForSentinel); |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 46 | if (databaseInfo.type == DatabaseInfo::Type::CLUSTER) |
| 47 | { |
| 48 | return std::make_shared<AsyncHiredisClusterCommandDispatcher>(engine, |
| 49 | databaseInfo.ns, |
| 50 | databaseInfo.hosts, |
| 51 | contentsBuilder, |
| 52 | usePermanentCommandCallbacks, |
| 53 | logger); |
| 54 | } |
| 55 | else |
| 56 | return std::make_shared<AsyncHiredisCommandDispatcher>(engine, |
| 57 | databaseInfo.hosts.at(0).getHost(), |
| 58 | databaseInfo.hosts.at(0).getPort(), |
| 59 | contentsBuilder, |
| 60 | usePermanentCommandCallbacks, |
| 61 | logger); |
| 62 | #elif HAVE_HIREDIS |
| 63 | if (databaseInfo.type == DatabaseInfo::Type::CLUSTER) |
| 64 | SHAREDDATALAYER_ABORT("Not implemented."); |
| 65 | return std::make_shared<AsyncHiredisCommandDispatcher>(engine, |
| 66 | databaseInfo.hosts.at(0).getHost(), |
| 67 | databaseInfo.hosts.at(0).getPort(), |
| 68 | contentsBuilder, |
| 69 | usePermanentCommandCallbacks, |
Rolf Badorek | 8324d02 | 2019-09-17 16:47:20 +0300 | [diff] [blame] | 70 | logger, |
| 71 | usedForSentinel); |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 72 | #else |
| 73 | SHAREDDATALAYER_ABORT("Not implemented."); |
| 74 | #endif |
| 75 | } |