Action Engine
Loading...
Searching...
No Matches
peers.h
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ACTIONENGINE_DISTRIBUTED_PEERS_H_
16#define ACTIONENGINE_DISTRIBUTED_PEERS_H_
17
18#include <string>
19#include <string_view>
20#include <utility>
21
22#include <absl/base/nullability.h>
23
24#include "actionengine/distributed/sinks.h"
25
26namespace act::distributed {
27
28struct GetRequest {
29 std::string group;
30 std::string key;
31};
32
33struct GetResponse {
34 std::optional<std::string> value;
35 std::optional<double> minute_qps;
36};
37
38using ServiceGetter = absl::AnyInvocable<absl::Status(
39 GetRequest* absl_nonnull request, GetResponse* absl_nonnull response)>;
40
41class PeerPicker {
42 public:
43 virtual ~PeerPicker() = default;
44 [[nodiscard]] virtual std::optional<ServiceGetter> PickPeer(
45 std::string_view key) const = 0;
46};
47
48class NoPeers final : public PeerPicker {
49 public:
50 [[nodiscard]] std::optional<ServiceGetter> PickPeer(
51 std::string_view /*key*/) const override {
52 return std::nullopt;
53 }
54};
55
56} // namespace act::distributed
57
58#endif // ACTIONENGINE_DISTRIBUTED_PEERS_H_