child_policy_handler.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_CHILD_POLICY_HANDLER_H
18 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_CHILD_POLICY_HANDLER_H
19 
21 
22 #include <utility>
23 
25 
30 
31 namespace grpc_core {
32 
33 // A class that makes it easy to gracefully switch child policies.
34 //
35 // Callers should instantiate this instead of using
36 // LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(). Once
37 // instantiated, this object will automatically take care of
38 // constructing the child policy as needed upon receiving an update.
40  public:
42  : LoadBalancingPolicy(std::move(args)), tracer_(tracer) {}
43 
44  const char* name() const override { return "child_policy_handler"; }
45 
46  void UpdateLocked(UpdateArgs args) override;
47  void ExitIdleLocked() override;
48  void ResetBackoffLocked() override;
49 
50  // Returns true if transitioning from the old config to the new config
51  // requires instantiating a new policy object.
53  LoadBalancingPolicy::Config* old_config,
54  LoadBalancingPolicy::Config* new_config) const;
55 
56  // Instantiates a new policy of the specified name.
57  // May be overridden by subclasses to avoid recursion when an LB
58  // policy factory returns a ChildPolicyHandler.
60  const char* name, LoadBalancingPolicy::Args args) const;
61 
62  private:
63  class Helper;
64 
65  void ShutdownLocked() override;
66 
68  const char* child_policy_name, const grpc_channel_args& args);
69 
70  // Passed in from caller at construction time.
72 
73  bool shutting_down_ = false;
74 
75  // The most recent config passed to UpdateLocked().
76  // If pending_child_policy_ is non-null, this is the config passed to
77  // pending_child_policy_; otherwise, it's the config passed to child_policy_.
79 
80  // Child LB policy.
83 };
84 
85 } // namespace grpc_core
86 
87 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_CHILD_POLICY_HANDLER_H \
88  */
trace.h
grpc_core::ChildPolicyHandler::tracer_
TraceFlag * tracer_
Definition: child_policy_handler.h:71
orphanable.h
grpc_core::LoadBalancingPolicy
Definition: lb_policy.h:95
grpc_core
Definition: call_metric_recorder.h:31
lb_policy.h
grpc_core::LoadBalancingPolicy::Config
Definition: lb_policy.h:305
grpc_channel_args
Definition: grpc_types.h:132
grpc_core::ChildPolicyHandler::ExitIdleLocked
void ExitIdleLocked() override
Definition: child_policy_handler.cc:257
grpc_types.h
grpc_core::ChildPolicyHandler::ConfigChangeRequiresNewPolicyInstance
virtual bool ConfigChangeRequiresNewPolicyInstance(LoadBalancingPolicy::Config *old_config, LoadBalancingPolicy::Config *new_config) const
Definition: child_policy_handler.cc:303
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_core::ChildPolicyHandler::UpdateLocked
void UpdateLocked(UpdateArgs args) override
Definition: child_policy_handler.cc:163
grpc_core::ChildPolicyHandler::current_config_
RefCountedPtr< LoadBalancingPolicy::Config > current_config_
Definition: child_policy_handler.h:78
grpc_core::ChildPolicyHandler::shutting_down_
bool shutting_down_
Definition: child_policy_handler.h:73
grpc_core::ChildPolicyHandler::CreateChildPolicy
OrphanablePtr< LoadBalancingPolicy > CreateChildPolicy(const char *child_policy_name, const grpc_channel_args &args)
Definition: child_policy_handler.cc:275
grpc_core::LoadBalancingPolicy::Args
Args used to instantiate an LB policy.
Definition: lb_policy.h:343
grpc_core::TraceFlag
Definition: debug/trace.h:63
grpc_core::OrphanablePtr
std::unique_ptr< T, Deleter > OrphanablePtr
Definition: orphanable.h:64
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
grpc_core::ChildPolicyHandler::child_policy_
OrphanablePtr< LoadBalancingPolicy > child_policy_
Definition: child_policy_handler.h:81
grpc_core::ChildPolicyHandler
Definition: child_policy_handler.h:39
ref_counted_ptr.h
grpc_core::ChildPolicyHandler::ChildPolicyHandler
ChildPolicyHandler(Args args, TraceFlag *tracer)
Definition: child_policy_handler.h:41
grpc_core::ChildPolicyHandler::ResetBackoffLocked
void ResetBackoffLocked() override
Resets connection backoff.
Definition: child_policy_handler.cc:266
grpc_core::ChildPolicyHandler::ShutdownLocked
void ShutdownLocked() override
Shuts down the policy.
Definition: child_policy_handler.cc:137
grpc_core::ChildPolicyHandler::CreateLoadBalancingPolicy
virtual OrphanablePtr< LoadBalancingPolicy > CreateLoadBalancingPolicy(const char *name, LoadBalancingPolicy::Args args) const
Definition: child_policy_handler.cc:310
grpc_core::ChildPolicyHandler::pending_child_policy_
OrphanablePtr< LoadBalancingPolicy > pending_child_policy_
Definition: child_policy_handler.h:82
grpc_core::ChildPolicyHandler::name
const char * name() const override
Returns the name of the LB policy.
Definition: child_policy_handler.h:44
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:45