GRPC C++  1.53.0
xds_server_builder.h
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2020 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #ifndef GRPCPP_XDS_SERVER_BUILDER_H
20 #define GRPCPP_XDS_SERVER_BUILDER_H
21 
23 
24 #include <grpcpp/server_builder.h>
25 
26 namespace grpc {
27 
29  public:
32  };
33 
34  virtual ~XdsServerServingStatusNotifierInterface() = default;
35 
36  // \a uri contains the listening target associated with the notification. Note
37  // that a single target provided to XdsServerBuilder can get resolved to
38  // multiple listening addresses.
39  // The callback is invoked each time there is an update to the serving status.
40  // The API does not provide any guarantees around duplicate updates.
41  // Status::OK signifies that the server is serving, while a non-OK status
42  // signifies that the server is not serving.
43  virtual void OnServingStatusUpdate(std::string uri,
44  ServingStatusUpdate update) = 0;
45 };
46 
48  public:
49  // NOTE: class experimental_type is not part of the public API of this class
50  // TODO(yashykt): Integrate into public API when this is no longer
51  // experimental.
53  public:
55  : ServerBuilder::experimental_type(builder), builder_(builder) {}
56 
57  // EXPERIMENTAL: Sets the drain grace period in ms for older connections
58  // when updates to a Listener is received.
59  void set_drain_grace_time(int drain_grace_time_ms) {
60  builder_->drain_grace_time_ms_ = drain_grace_time_ms;
61  }
62 
63  private:
64  XdsServerBuilder* builder_;
65  };
66 
67  // It is the responsibility of the application to make sure that \a notifier
68  // outlasts the life of the server. Notifications will start being made
69  // asynchronously once `BuildAndStart()` has been called. Note that it is
70  // possible for notifications to be made before `BuildAndStart()` returns.
72  notifier_ = notifier;
73  }
74 
79 
80  private:
81  // Called at the beginning of BuildAndStart().
82  ChannelArguments BuildChannelArgs() override {
84  if (drain_grace_time_ms_ >= 0) {
86  drain_grace_time_ms_);
87  }
88  grpc_channel_args c_channel_args = args.c_channel_args();
90  {OnServingStatusUpdate, notifier_}, &c_channel_args);
91  if (fetcher != nullptr) set_fetcher(fetcher);
92  return args;
93  }
94 
95  static void OnServingStatusUpdate(void* user_data, const char* uri,
97  if (user_data == nullptr) return;
98  XdsServerServingStatusNotifierInterface* notifier =
99  static_cast<XdsServerServingStatusNotifierInterface*>(user_data);
100  notifier->OnServingStatusUpdate(
101  uri, {grpc::Status(static_cast<StatusCode>(update.code),
102  update.error_message)});
103  }
104 
105  XdsServerServingStatusNotifierInterface* notifier_ = nullptr;
106  int drain_grace_time_ms_ = -1;
107 };
108 
109 } // namespace grpc
110 
111 #endif // GRPCPP_XDS_SERVER_BUILDER_H
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:32
grpc::XdsServerBuilder::experimental_type::set_drain_grace_time
void set_drain_grace_time(int drain_grace_time_ms)
Definition: xds_server_builder.h:59
grpc::ServerBuilder::set_fetcher
void set_fetcher(grpc_server_config_fetcher *server_config_fetcher)
Experimental API, subject to change.
Definition: server_builder.h:358
grpc::ChannelArguments::SetInt
void SetInt(const std::string &key, int value)
Set an integer argument value under key.
grpc::ServerBuilder::BuildChannelArgs
virtual ChannelArguments BuildChannelArgs()
Experimental API, subject to change.
grpc_server_config_fetcher
struct grpc_server_config_fetcher grpc_server_config_fetcher
Definition: grpc.h:448
grpc_channel_args
An array of arguments that can be passed around.
Definition: grpc_types.h:131
grpc_serving_status_update::error_message
const char * error_message
Definition: grpc.h:437
grpc::ChannelArguments
Options for channel creation.
Definition: channel_arguments.h:39
grpc::Status
Did it work? If it didn't, why?
Definition: status.h:35
grpc::XdsServerBuilder::experimental_type::experimental_type
experimental_type(XdsServerBuilder *builder)
Definition: xds_server_builder.h:54
grpc::XdsServerBuilder
Definition: xds_server_builder.h:47
grpc_server_config_fetcher_xds_create
GRPCAPI grpc_server_config_fetcher * grpc_server_config_fetcher_xds_create(grpc_server_xds_status_notifier notifier, const grpc_channel_args *args)
EXPERIMENTAL.
grpc::XdsServerServingStatusNotifierInterface::ServingStatusUpdate::status
grpc::Status status
Definition: xds_server_builder.h:31
grpc::XdsServerServingStatusNotifierInterface::ServingStatusUpdate
Definition: xds_server_builder.h:30
grpc_serving_status_update
Definition: grpc.h:435
grpc::XdsServerBuilder::experimental
experimental_type experimental()
NOTE: The function experimental() is not stable public API.
Definition: xds_server_builder.h:78
grpc::StatusCode
StatusCode
Definition: status_code_enum.h:26
grpc::ChannelArguments::c_channel_args
grpc_channel_args c_channel_args() const
Return (by value) a C grpc_channel_args structure which points to arguments owned by this ChannelArgu...
Definition: channel_arguments.h:115
grpc::ServerBuilder::experimental_type
NOTE: class experimental_type is not part of the public API of this class.
Definition: server_builder.h:256
grpc::XdsServerServingStatusNotifierInterface::OnServingStatusUpdate
virtual void OnServingStatusUpdate(std::string uri, ServingStatusUpdate update)=0
grpc::XdsServerBuilder::experimental_type
Definition: xds_server_builder.h:52
grpc::protobuf::util::Status
::google::protobuf::util::Status Status
Definition: config_protobuf.h:93
grpc::XdsServerBuilder::set_status_notifier
void set_status_notifier(XdsServerServingStatusNotifierInterface *notifier)
Definition: xds_server_builder.h:71
grpc_serving_status_update::code
grpc_status_code code
Definition: grpc.h:436
GRPC_ARG_SERVER_CONFIG_CHANGE_DRAIN_GRACE_TIME_MS
#define GRPC_ARG_SERVER_CONFIG_CHANGE_DRAIN_GRACE_TIME_MS
EXPERIMENTAL.
Definition: grpc_types.h:471
grpc::ServerBuilder
A builder class for the creation and startup of grpc::Server instances.
Definition: server_builder.h:85
grpc::XdsServerServingStatusNotifierInterface::~XdsServerServingStatusNotifierInterface
virtual ~XdsServerServingStatusNotifierInterface()=default
server_builder.h
port_platform.h
grpc::XdsServerServingStatusNotifierInterface
Definition: xds_server_builder.h:28