userver: userver/ugrpc/client/call_options.hpp Source File
Loading...
Searching...
No Matches
call_options.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ugrpc/client/call_options.hpp
4/// @brief @copybrief ugrpc::client::CallOptions
5
6#include <chrono>
7#include <string_view>
8#include <utility>
9#include <vector>
10
11#include <grpcpp/client_context.h>
12#include <grpcpp/support/config.h>
13
14#include <userver/engine/deadline.hpp>
15#include <userver/utils/move_only_function.hpp>
16
17USERVER_NAMESPACE_BEGIN
18
19namespace ugrpc::client {
20
21namespace impl {
22class CallOptionsAccessor;
23} // namespace impl
24
25/// @brief Options passed to interface calls
27public:
28 /// @{
29 /// Set and get retry attempts. Maximum number of retry attempts, including the original attempt.
30 void SetAttempts(int attempts);
31 int GetAttempts() const;
32 /// @}
33
34 /// @{
35 /// Set and get operation timeout.
36 ///
37 /// In case of retries `timeout` applies to each attempt.
38 /// Maximum time on call may actually be `timeout * attempts + sum(backoff_i)`
39 void SetTimeout(std::chrono::milliseconds timeout);
40 std::chrono::milliseconds GetTimeout() const;
41 /// @}
42
43 /// @{
44 /// Set and get operation deadline.
45 void SetDeadline(engine::Deadline deadline);
46 engine::Deadline GetDeadline() const;
47 /// @}
48
49 /// Add the (\a meta_key, \a meta_value) pair to the metadata associated with a client call.
50 void AddMetadata(std::string_view meta_key, std::string_view meta_value);
51
52 /// @{
53 /// Set custom grpc::ClientContext factory.
54 ///
55 /// 'client_context_factory' may be called zero, once or more time, because of retries.
56 using ClientContextFactory = utils::move_only_function<std::unique_ptr<grpc::ClientContext>() const>;
57 void SetClientContextFactory(ClientContextFactory&& client_context_factory);
58 /// @}
59
60private:
61 friend class impl::CallOptionsAccessor;
62
63 int attempts_{0};
64
65 std::chrono::milliseconds timeout_{std::chrono::milliseconds::max()};
66 engine::Deadline deadline_;
67
68 std::vector<std::pair<grpc::string, grpc::string>> metadata_;
69
70 ClientContextFactory client_context_factory_;
71};
72
73} // namespace ugrpc::client
74
75USERVER_NAMESPACE_END