GRPC Core  9.0.0
resolver.h
Go to the documentation of this file.
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 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_H
21 
23 
25 
32 
34 
35 namespace grpc_core {
36 
49 class Resolver : public InternallyRefCounted<Resolver> {
50  public:
52  struct Result {
56  const grpc_channel_args* args = nullptr;
57 
58  // TODO(roth): Remove everything below once grpc_error and
59  // grpc_channel_args are convert to copyable and movable C++ objects.
60  Result() = default;
61  ~Result();
62  Result(const Result& other);
63  Result(Result&& other);
64  Result& operator=(const Result& other);
65  Result& operator=(Result&& other);
66  };
67 
70  class ResultHandler {
71  public:
72  virtual ~ResultHandler() {}
73 
76  virtual void ReturnResult(Result result) = 0; // NOLINT
77 
81  virtual void ReturnError(grpc_error* error) = 0;
82 
83  // TODO(yashkt): As part of the service config error handling
84  // changes, add a method to parse the service config JSON string.
85  };
86 
87  // Not copyable nor movable.
88  Resolver(const Resolver&) = delete;
89  Resolver& operator=(const Resolver&) = delete;
90  virtual ~Resolver();
91 
93  virtual void StartLocked() = 0;
94 
108  virtual void RequestReresolutionLocked() {}
109 
116  virtual void ResetBackoffLocked() {}
117 
118  // Note: This must be invoked while holding the combiner.
119  void Orphan() override {
120  ShutdownLocked();
121  Unref();
122  }
123 
124  protected:
126  // TODO(roth): Once we have a C++-like interface for combiners, this
127  // API should change to take a RefCountedPtr<>, so that we always take
128  // ownership of a new ref.
129  explicit Resolver(Combiner* combiner,
130  std::unique_ptr<ResultHandler> result_handler);
131 
133  virtual void ShutdownLocked() = 0;
134 
135  Combiner* combiner() const { return combiner_; }
136 
137  ResultHandler* result_handler() const { return result_handler_.get(); }
138 
139  private:
140  std::unique_ptr<ResultHandler> result_handler_;
141  Combiner* combiner_;
142 };
143 
144 } // namespace grpc_core
145 
146 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_H */
grpc_core::Resolver::StartLocked
virtual void StartLocked()=0
Starts resolving.
iomgr.h
orphanable.h
GRPC_ERROR_NONE
#define GRPC_ERROR_NONE
The following "special" errors can be propagated without allocating memory.
Definition: error.h:125
grpc_core::Combiner
Definition: combiner.h:33
grpc_core::Resolver::operator=
Resolver & operator=(const Resolver &)=delete
grpc_core
Round Robin Policy.
Definition: backend_metric.cc:24
grpc_core::Resolver::Result::~Result
~Result()
Definition: resolver.cc:45
grpc_core::Resolver::result_handler
ResultHandler * result_handler() const
Definition: resolver.h:137
grpc_channel_args
An array of arguments that can be passed around.
Definition: grpc_types.h:132
grpc_core::TraceFlag
Definition: trace.h:61
grpc_types.h
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
grpc_core::Resolver::~Resolver
virtual ~Resolver()
Definition: resolver.cc:39
grpc_core::Resolver::Orphan
void Orphan() override
Definition: resolver.h:119
grpc_core::Resolver::RequestReresolutionLocked
virtual void RequestReresolutionLocked()
Asks the resolver to obtain an updated resolver result, if applicable.
Definition: resolver.h:108
grpc_core::Resolver::ResultHandler
A proxy object used by the resolver to return results to the client channel.
Definition: resolver.h:70
grpc_core::Resolver::Result::addresses
ServerAddressList addresses
Definition: resolver.h:53
grpc_core::Resolver::ResultHandler::~ResultHandler
virtual ~ResultHandler()
Definition: resolver.h:72
grpc_core::Resolver::Result
Results returned by the resolver.
Definition: resolver.h:52
grpc_core::Resolver::Result::args
const grpc_channel_args * args
Definition: resolver.h:56
server_address.h
grpc_core::Resolver
Interface for name resolution.
Definition: resolver.h:49
grpc_core::Resolver::Result::Result
Result()=default
grpc_core::InternallyRefCounted< Resolver >::Unref
void Unref()
Definition: orphanable.h:107
grpc_core::InternallyRefCounted
Definition: orphanable.h:77
grpc_core::Resolver::Result::service_config_error
grpc_error * service_config_error
Definition: resolver.h:55
grpc_core::Resolver::ResultHandler::ReturnResult
virtual void ReturnResult(Result result)=0
Returns a result to the channel.
grpc_core::Resolver::Result::service_config
RefCountedPtr< ServiceConfig > service_config
Definition: resolver.h:54
combiner.h
grpc_core::Resolver::Resolver
Resolver(const Resolver &)=delete
ref_counted_ptr.h
grpc_core::InlinedVector< ServerAddress, 1 >
service_config.h
grpc_core::Resolver::ResultHandler::ReturnError
virtual void ReturnError(grpc_error *error)=0
Returns a transient error to the channel.
grpc_core::Resolver::combiner
Combiner * combiner() const
Definition: resolver.h:135
grpc_core::Resolver::Result::operator=
Result & operator=(const Result &other)
Definition: resolver.cc:66
grpc_error
Definition: error_internal.h:39
grpc_trace_resolver_refcount
grpc_core::DebugOnlyTraceFlag grpc_trace_resolver_refcount
grpc_core::Resolver::ResetBackoffLocked
virtual void ResetBackoffLocked()
Resets the re-resolution backoff, if any.
Definition: resolver.h:116
grpc_core::Resolver::ShutdownLocked
virtual void ShutdownLocked()=0
Shuts down the resolver.
port_platform.h