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,
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:
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:
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().
84  if (drain_grace_time_ms_ >= 0) {
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;
99  static_cast<XdsServerServingStatusNotifierInterface*>(user_data);
100  notifier->OnServingStatusUpdate(
101  uri, {grpc::Status(static_cast<StatusCode>(update.code),
102  update.error_message)});
103  }
104 
107 };
108 
109 namespace experimental {
110 // TODO(yashykt): Delete this after the 1.42 release.
112  "Use grpc::XdsServerServingStatusNotifierInterface instead. The "
113  "experimental version will be deleted after the 1.42 release.")
117  "Use grpc::XdsServerBuilder instead. The experimental version will be "
118  "deleted after the 1.42 release.")
120 } // namespace experimental
121 } // namespace grpc
122 
123 #endif /* GRPCPP_XDS_SERVER_BUILDER_H */
grpc::XdsServerServingStatusNotifierInterface
Definition: xds_server_builder.h:28
grpc::XdsServerServingStatusNotifierInterface::~XdsServerServingStatusNotifierInterface
virtual ~XdsServerServingStatusNotifierInterface()=default
grpc
Definition: grpcpp/alarm.h:33
grpc_server_config_fetcher
Definition: src/core/lib/surface/server.h:497
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::XdsServerBuilder::experimental_type
Definition: xds_server_builder.h:52
grpc::XdsServerBuilder::experimental_type::experimental_type
experimental_type(XdsServerBuilder *builder)
Definition: xds_server_builder.h:54
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::XdsServerBuilder::BuildChannelArgs
ChannelArguments BuildChannelArgs() override
Experimental API, subject to change.
Definition: xds_server_builder.h:82
grpc_channel_args
Definition: grpc_types.h:132
grpc::ServerBuilder::set_fetcher
void set_fetcher(grpc_server_config_fetcher *server_config_fetcher)
Experimental API, subject to change.
Definition: grpcpp/server_builder.h:347
grpc::XdsServerBuilder
Definition: xds_server_builder.h:47
GRPC_DEPRECATED
#define GRPC_DEPRECATED(reason)
Definition: impl/codegen/port_platform.h:36
profile_analyzer.builder
builder
Definition: profile_analyzer.py:159
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc::XdsServerServingStatusNotifierInterface::OnServingStatusUpdate
virtual void OnServingStatusUpdate(std::string uri, ServingStatusUpdate update)=0
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)
Definition: xds_server_config_fetcher.cc:1332
grpc.StatusCode
Definition: src/python/grpcio/grpc/__init__.py:232
grpc::ServerBuilder
A builder class for the creation and startup of grpc::Server instances.
Definition: grpcpp/server_builder.h:86
grpc::ServerBuilder::experimental_type
Definition: grpcpp/server_builder.h:257
grpc_serving_status_update
Definition: grpc.h:445
grpc::XdsServerBuilder::drain_grace_time_ms_
int drain_grace_time_ms_
Definition: xds_server_builder.h:106
grpc::ServerBuilder::BuildChannelArgs
virtual ChannelArguments BuildChannelArgs()
Experimental API, subject to change.
Definition: server_builder.cc:237
grpc::ChannelArguments
Definition: grpcpp/support/channel_arguments.h:39
grpc::XdsServerBuilder::notifier_
XdsServerServingStatusNotifierInterface * notifier_
Definition: xds_server_builder.h:105
port_platform.h
grpc::XdsServerBuilder::set_status_notifier
void set_status_notifier(XdsServerServingStatusNotifierInterface *notifier)
Definition: xds_server_builder.h:71
GRPC_ARG_SERVER_CONFIG_CHANGE_DRAIN_GRACE_TIME_MS
#define GRPC_ARG_SERVER_CONFIG_CHANGE_DRAIN_GRACE_TIME_MS
Definition: grpc_types.h:456
grpc::XdsServerServingStatusNotifierInterface::ServingStatusUpdate::status
grpc::Status status
Definition: xds_server_builder.h:31
grpc::protobuf::util::Status
GRPC_CUSTOM_UTIL_STATUS Status
Definition: include/grpcpp/impl/codegen/config_protobuf.h:93
grpc::Status
Definition: include/grpcpp/impl/codegen/status.h:35
grpc::XdsServerBuilder::OnServingStatusUpdate
static void OnServingStatusUpdate(void *user_data, const char *uri, grpc_serving_status_update update)
Definition: xds_server_builder.h:95
grpc::XdsServerServingStatusNotifierInterface::ServingStatusUpdate
Definition: xds_server_builder.h:30
update
absl::optional< XdsClusterResource > update
Definition: cds.cc:150
server_builder.h
grpc::XdsServerBuilder::experimental
experimental_type experimental()
Definition: xds_server_builder.h:78
grpc::XdsServerBuilder::experimental_type::builder_
XdsServerBuilder * builder_
Definition: xds_server_builder.h:64


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:57