1 /* 2 * 3 * Copyright 2015 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 #include <grpc/support/port_platform.h> 20 21 #include "src/core/ext/filters/client_channel/lb_policy.h" 22 #include "src/core/lib/iomgr/combiner.h" 23 24 grpc_core::DebugOnlyTraceFlag grpc_trace_lb_policy_refcount( 25 false, "lb_policy_refcount"); 26 27 namespace grpc_core { 28 29 LoadBalancingPolicy::LoadBalancingPolicy(const Args& args) 30 : InternallyRefCountedWithTracing(&grpc_trace_lb_policy_refcount), 31 combiner_(GRPC_COMBINER_REF(args.combiner, "lb_policy")), 32 client_channel_factory_(args.client_channel_factory), 33 interested_parties_(grpc_pollset_set_create()), 34 request_reresolution_(nullptr) {} 35 36 LoadBalancingPolicy::~LoadBalancingPolicy() { 37 grpc_pollset_set_destroy(interested_parties_); 38 GRPC_COMBINER_UNREF(combiner_, "lb_policy"); 39 } 40 41 void LoadBalancingPolicy::TryReresolutionLocked( 42 grpc_core::TraceFlag* grpc_lb_trace, grpc_error* error) { 43 if (request_reresolution_ != nullptr) { 44 GRPC_CLOSURE_SCHED(request_reresolution_, error); 45 request_reresolution_ = nullptr; 46 if (grpc_lb_trace->enabled()) { 47 gpr_log(GPR_INFO, 48 "%s %p: scheduling re-resolution closure with error=%s.", 49 grpc_lb_trace->name(), this, grpc_error_string(error)); 50 } 51 } else { 52 if (grpc_lb_trace->enabled()) { 53 gpr_log(GPR_INFO, "%s %p: no available re-resolution closure.", 54 grpc_lb_trace->name(), this); 55 } 56 } 57 } 58 59 } // namespace grpc_core 60