Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Concepts.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2023, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "data/cassandra/Types.hpp"
23
24#include <boost/asio/io_context.hpp>
25#include <boost/asio/spawn.hpp>
26#include <boost/json.hpp>
27#include <boost/json/object.hpp>
28
29#include <chrono>
30#include <concepts>
31#include <cstdint>
32#include <optional>
33#include <string>
34#include <utility>
35#include <vector>
36
37namespace data::cassandra {
38
42template <typename T>
43concept SomeSettingsProvider = requires(T a) {
44 { a.getSettings() } -> std::same_as<Settings>;
45 { a.getKeyspace() } -> std::same_as<std::string>;
46 { a.getTablePrefix() } -> std::same_as<std::optional<std::string>>;
47 { a.getReplicationFactor() } -> std::same_as<uint16_t>;
48};
49
53template <typename T>
54concept SomeExecutionStrategy = requires(
55 T a,
56 Settings settings,
57 Handle handle,
58 Statement statement,
59 std::vector<Statement> statements,
60 PreparedStatement prepared,
61 boost::asio::yield_context token
62) {
63 { T(settings, handle) };
64 { a.sync() } -> std::same_as<void>;
65 { a.isTooBusy() } -> std::same_as<bool>;
66 { a.writeSync(statement) } -> std::same_as<ResultOrError>;
67 { a.writeSync(prepared) } -> std::same_as<ResultOrError>;
68 { a.write(prepared) } -> std::same_as<void>;
69 { a.write(std::move(statements)) } -> std::same_as<void>;
70 { a.read(token, prepared) } -> std::same_as<ResultOrError>;
71 { a.read(token, statement) } -> std::same_as<ResultOrError>;
72 { a.read(token, statements) } -> std::same_as<ResultOrError>;
73 { a.readEach(token, statements) } -> std::same_as<std::vector<Result>>;
74 { a.stats() } -> std::same_as<boost::json::object>;
75};
76
80template <typename T>
81concept SomeRetryPolicy = requires(T a, boost::asio::io_context ioc, CassandraError err, uint32_t attempt) {
82 { T(ioc) };
83 { a.shouldRetry(err) } -> std::same_as<bool>;
84 {
85 a.retry([]() {})
86 } -> std::same_as<void>;
87};
88
89} // namespace data::cassandra
The requirements of an execution strategy.
Definition Concepts.hpp:54
The requirements of a retry policy.
Definition Concepts.hpp:81
The requirements of a settings provider.
Definition Concepts.hpp:43
This namespace implements a wrapper for the Cassandra C++ driver.
Definition Concepts.hpp:37