OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
parsec/runtime_locking_shard/client.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#include "client.hpp"
7
8#include "format.hpp"
10
12 client::client(std::vector<network::endpoint_t> endpoints)
13 : m_client(std::make_unique<decltype(m_client)::element_type>(
14 std::move(endpoints))) {}
15
16 auto client::init() -> bool {
17 return m_client->init();
18 }
19
21 broker_id_type broker_id,
22 key_type key,
23 lock_type locktype,
24 bool first_lock,
25 try_lock_callback_type result_callback) -> bool {
26 auto req = try_lock_request{ticket_number,
27 broker_id,
28 key,
29 locktype,
30 first_lock};
31 return m_client->call(
32 std::move(req),
33 [result_callback](std::optional<response> resp) {
34 assert(resp.has_value());
35 assert(std::holds_alternative<try_lock_return_type>(
36 resp.value()));
37 result_callback(std::get<try_lock_return_type>(resp.value()));
38 });
39 }
40
42 broker_id_type broker_id,
43 state_update_type state_update,
44 prepare_callback_type result_callback) -> bool {
45 auto req = prepare_request{ticket_number, state_update, broker_id};
46 return m_client->call(
47 std::move(req),
48 [result_callback](std::optional<response> resp) {
49 assert(resp.has_value());
50 assert(
51 std::holds_alternative<prepare_return_type>(resp.value()));
52 result_callback(std::get<prepare_return_type>(resp.value()));
53 });
54 }
55
57 commit_callback_type result_callback) -> bool {
58 auto req = commit_request{ticket_number};
59 return m_client->call(
60 req,
61 [result_callback](std::optional<response> resp) {
62 assert(resp.has_value());
63 assert(
64 std::holds_alternative<commit_return_type>(resp.value()));
65 result_callback(std::get<commit_return_type>(resp.value()));
66 });
67 }
68
70 rollback_callback_type result_callback) -> bool {
71 auto req = rollback_request{ticket_number};
72 return m_client->call(
73 req,
74 [result_callback](std::optional<response> resp) {
75 assert(resp.has_value());
76 assert(std::holds_alternative<rollback_return_type>(
77 resp.value()));
78 result_callback(std::get<rollback_return_type>(resp.value()));
79 });
80 }
81
83 finish_callback_type result_callback) -> bool {
84 auto req = finish_request{ticket_number};
85 return m_client->call(
86 req,
87 [result_callback](std::optional<response> resp) {
88 assert(resp.has_value());
89 assert(
90 std::holds_alternative<finish_return_type>(resp.value()));
91 result_callback(std::get<finish_return_type>(resp.value()));
92 });
93 }
94
96 get_tickets_callback_type result_callback)
97 -> bool {
98 auto req = get_tickets_request{broker_id};
99 return m_client->call(
100 req,
101 [result_callback](std::optional<response> resp) {
102 assert(resp.has_value());
103 assert(std::holds_alternative<get_tickets_return_type>(
104 resp.value()));
105 result_callback(
106 std::get<get_tickets_return_type>(resp.value()));
107 });
108 }
109}
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
std::function< void(prepare_return_type)> prepare_callback_type
Callback function type for the result of a prepare operation.
std::function< void(get_tickets_return_type)> get_tickets_callback_type
Callback function type for the result of a get tickets operation.
std::function< void(rollback_return_type)> rollback_callback_type
Callback function type for the result of a rollback operation.
std::function< void(finish_return_type)> finish_callback_type
Callback function type for the result of a finish operation.
std::function< void(try_lock_return_type)> try_lock_callback_type
Function type for try lock operation results.
std::function< void(commit_return_type)> commit_callback_type
Callback function type for the result of a commit operation.
auto init() -> bool
Initializes the underlying TCP client.
auto prepare(ticket_number_type ticket_number, broker_id_type broker_id, state_update_type state_update, prepare_callback_type result_callback) -> bool override
Requests a prepare operation from the remote shard.
auto commit(ticket_number_type ticket_number, commit_callback_type result_callback) -> bool override
Requests a commit operation from the remote shard.
auto get_tickets(broker_id_type broker_id, get_tickets_callback_type result_callback) -> bool override
Requests a get tickets operation from the remote shard.
auto try_lock(ticket_number_type ticket_number, broker_id_type broker_id, key_type key, lock_type locktype, bool first_lock, try_lock_callback_type result_callback) -> bool override
Requests a try lock operation from the remote shard.
auto finish(ticket_number_type ticket_number, finish_callback_type result_callback) -> bool override
Requests a finish operation from the remote shard.
auto rollback(ticket_number_type ticket_number, rollback_callback_type result_callback) -> bool override
Requests a rollback operation from the remote shard.
parsec::ticket_machine::ticket_number_type ticket_number_type
Type for a ticket number.
std:: unordered_map< key_type, value_type, hashing::const_sip_hash< key_type > > state_update_type
Type for state updates to a shard. A map of keys and their new values.