GRPC C++  1.39.1
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 
25 
26 namespace grpc_core {
27 
28 // A class that makes it easy to gracefully switch child policies.
29 //
30 // Callers should instantiate this instead of using
31 // LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(). Once
32 // instantiated, this object will automatically take care of
33 // constructing the child policy as needed upon receiving an update.
35  public:
37  : LoadBalancingPolicy(std::move(args)), tracer_(tracer) {}
38 
39  const char* name() const override { return "child_policy_handler"; }
40 
41  void UpdateLocked(UpdateArgs args) override;
42  void ExitIdleLocked() override;
43  void ResetBackoffLocked() override;
44 
45  // Returns true if transitioning from the old config to the new config
46  // requires instantiating a new policy object.
48  LoadBalancingPolicy::Config* old_config,
49  LoadBalancingPolicy::Config* new_config) const;
50 
51  // Instantiates a new policy of the specified name.
52  // May be overridden by subclasses to avoid recursion when an LB
53  // policy factory returns a ChildPolicyHandler.
55  const char* name, LoadBalancingPolicy::Args args) const;
56 
57  private:
58  class Helper;
59 
60  void ShutdownLocked() override;
61 
62  OrphanablePtr<LoadBalancingPolicy> CreateChildPolicy(
63  const char* child_policy_name, const grpc_channel_args& args);
64 
65  // Passed in from caller at construction time.
66  TraceFlag* tracer_;
67 
68  bool shutting_down_ = false;
69 
70  // The most recent config passed to UpdateLocked().
71  // If pending_child_policy_ is non-null, this is the config passed to
72  // pending_child_policy_; otherwise, it's the config passed to child_policy_.
74 
75  // Child LB policy.
77  OrphanablePtr<LoadBalancingPolicy> pending_child_policy_;
78 };
79 
80 } // namespace grpc_core
81 
82 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_CHILD_POLICY_HANDLER_H \
83  */
Definition: child_policy_handler.h:34
virtual bool ConfigChangeRequiresNewPolicyInstance(LoadBalancingPolicy::Config *old_config, LoadBalancingPolicy::Config *new_config) const
Definition: child_policy_handler.cc:287
void ExitIdleLocked() override
Tries to enter a READY connectivity state.
Definition: child_policy_handler.cc:241
void ResetBackoffLocked() override
Resets connection backoff.
Definition: child_policy_handler.cc:250
void UpdateLocked(UpdateArgs args) override
Updates the policy with new data from the resolver.
Definition: child_policy_handler.cc:147
ChildPolicyHandler(Args args, TraceFlag *tracer)
Definition: child_policy_handler.h:36
const char * name() const override
Returns the name of the LB policy.
Definition: child_policy_handler.h:39
virtual OrphanablePtr< LoadBalancingPolicy > CreateLoadBalancingPolicy(const char *name, LoadBalancingPolicy::Args args) const
Definition: child_policy_handler.cc:294
Interface for configuration data used by an LB policy implementation.
Definition: lb_policy.h:301
Interface for load balancing policies.
Definition: lb_policy.h:82
Definition: ref_counted_ptr.h:35
Definition: trace.h:61
Round Robin Policy.
Definition: backend_metric.cc:26
std::unique_ptr< T, Deleter > OrphanablePtr
Definition: orphanable.h:67
Definition: async_unary_call.h:398
An array of arguments that can be passed around.
Definition: grpc_types.h:132
Args used to instantiate an LB policy.
Definition: lb_policy.h:327
TraceFlag * tracer
Definition: xds_api.cc:907