subchannel_interface.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 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_SUBCHANNEL_INTERFACE_H
18 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_INTERFACE_H
19 
21 
22 #include <memory>
23 #include <utility>
24 
25 #include "absl/status/status.h"
26 
29 
33 
34 namespace grpc_core {
35 
36 // The interface for subchannels that is exposed to LB policy implementations.
37 class SubchannelInterface : public RefCounted<SubchannelInterface> {
38  public:
40  public:
41  virtual ~ConnectivityStateWatcherInterface() = default;
42 
43  // Will be invoked whenever the subchannel's connectivity state changes.
44  // If the new state is TRANSIENT_FAILURE, status indicates the reason
45  // for the failure. There will be only one invocation of this method
46  // on a given watcher instance at any given time.
48  absl::Status status) = 0;
49 
50  // TODO(roth): Remove this as soon as we move to EventManager-based
51  // polling.
52  virtual grpc_pollset_set* interested_parties() = 0;
53  };
54 
55  // Opaque interface for watching data of a particular type for this
56  // subchannel.
58  public:
59  virtual ~DataWatcherInterface() = default;
60  };
61 
62  explicit SubchannelInterface(const char* trace = nullptr)
63  : RefCounted<SubchannelInterface>(trace) {}
64 
65  ~SubchannelInterface() override = default;
66 
67  // Starts watching the subchannel's connectivity state.
68  // The first callback to the watcher will be delivered ~immediately.
69  // Subsequent callbacks will be delivered as the subchannel's state
70  // changes.
71  // The watcher will be destroyed either when the subchannel is
72  // destroyed or when CancelConnectivityStateWatch() is called.
73  // There can be only one watcher of a given subchannel. It is not
74  // valid to call this method a second time without first cancelling
75  // the previous watcher using CancelConnectivityStateWatch().
76  virtual void WatchConnectivityState(
77  std::unique_ptr<ConnectivityStateWatcherInterface> watcher) = 0;
78 
79  // Cancels a connectivity state watch.
80  // If the watcher has already been destroyed, this is a no-op.
81  virtual void CancelConnectivityStateWatch(
83 
84  // Attempt to connect to the backend. Has no effect if already connected.
85  // If the subchannel is currently in backoff delay due to a previously
86  // failed attempt, the new connection attempt will not start until the
87  // backoff delay has elapsed.
88  virtual void RequestConnection() = 0;
89 
90  // Resets the subchannel's connection backoff state. If RequestConnection()
91  // has been called since the subchannel entered TRANSIENT_FAILURE state,
92  // starts a new connection attempt immediately; otherwise, a new connection
93  // attempt will be started as soon as RequestConnection() is called.
94  virtual void ResetBackoff() = 0;
95 
96  // Registers a new data watcher.
97  virtual void AddDataWatcher(
98  std::unique_ptr<DataWatcherInterface> watcher) = 0;
99 
100  // TODO(roth): Need a better non-grpc-specific abstraction here.
101  virtual const grpc_channel_args* channel_args() = 0;
102 };
103 
104 // A class that delegates to another subchannel, to be used in cases
105 // where an LB policy needs to wrap a subchannel.
107  public:
110 
112  return wrapped_subchannel_;
113  }
114 
116  std::unique_ptr<ConnectivityStateWatcherInterface> watcher) override {
117  return wrapped_subchannel_->WatchConnectivityState(std::move(watcher));
118  }
121  return wrapped_subchannel_->CancelConnectivityStateWatch(watcher);
122  }
123  void RequestConnection() override {
124  wrapped_subchannel_->RequestConnection();
125  }
126  void ResetBackoff() override { wrapped_subchannel_->ResetBackoff(); }
127  const grpc_channel_args* channel_args() override {
128  return wrapped_subchannel_->channel_args();
129  }
130  void AddDataWatcher(std::unique_ptr<DataWatcherInterface> watcher) override {
131  wrapped_subchannel_->AddDataWatcher(std::move(watcher));
132  }
133 
134  private:
136 };
137 
138 } // namespace grpc_core
139 
140 #endif // GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_INTERFACE_H
grpc_core::DelegatingSubchannel::RequestConnection
void RequestConnection() override
Definition: subchannel_interface.h:123
grpc_core::ConnectivityStateWatcherInterface
Definition: src/core/lib/transport/connectivity_state.h:49
grpc_core::DelegatingSubchannel::channel_args
const grpc_channel_args * channel_args() override
Definition: subchannel_interface.h:127
grpc_core
Definition: call_metric_recorder.h:31
grpc_pollset_set
struct grpc_pollset_set grpc_pollset_set
Definition: iomgr_fwd.h:23
subchannel
RingHashSubchannelData * subchannel
Definition: ring_hash.cc:285
grpc_core::SubchannelInterface::ConnectivityStateWatcherInterface::interested_parties
virtual grpc_pollset_set * interested_parties()=0
status
absl::Status status
Definition: rls.cc:251
grpc_channel_args
Definition: grpc_types.h:132
grpc_connectivity_state
grpc_connectivity_state
Definition: include/grpc/impl/codegen/connectivity_state.h:30
grpc_types.h
grpc_core::SubchannelInterface::WatchConnectivityState
virtual void WatchConnectivityState(std::unique_ptr< ConnectivityStateWatcherInterface > watcher)=0
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::DelegatingSubchannel::ResetBackoff
void ResetBackoff() override
Definition: subchannel_interface.h:126
grpc_core::SubchannelInterface::ConnectivityStateWatcherInterface::~ConnectivityStateWatcherInterface
virtual ~ConnectivityStateWatcherInterface()=default
connectivity_state.h
grpc_core::SubchannelInterface::channel_args
virtual const grpc_channel_args * channel_args()=0
grpc_core::SubchannelInterface::DataWatcherInterface::~DataWatcherInterface
virtual ~DataWatcherInterface()=default
grpc_core::DelegatingSubchannel::wrapped_subchannel
RefCountedPtr< SubchannelInterface > wrapped_subchannel() const
Definition: subchannel_interface.h:111
grpc_core::DelegatingSubchannel
Definition: subchannel_interface.h:106
grpc_core::DelegatingSubchannel::wrapped_subchannel_
RefCountedPtr< SubchannelInterface > wrapped_subchannel_
Definition: subchannel_interface.h:135
grpc_core::RefCounted
Definition: ref_counted.h:280
grpc_core::DelegatingSubchannel::AddDataWatcher
void AddDataWatcher(std::unique_ptr< DataWatcherInterface > watcher) override
Definition: subchannel_interface.h:130
grpc_core::SubchannelInterface::RequestConnection
virtual void RequestConnection()=0
ref_counted.h
grpc_core::DelegatingSubchannel::DelegatingSubchannel
DelegatingSubchannel(RefCountedPtr< SubchannelInterface > subchannel)
Definition: subchannel_interface.h:108
grpc_core::SubchannelInterface::ConnectivityStateWatcherInterface::OnConnectivityStateChange
virtual void OnConnectivityStateChange(grpc_connectivity_state new_state, absl::Status status)=0
absl::Status
Definition: third_party/abseil-cpp/absl/status/status.h:424
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
grpc_core::DelegatingSubchannel::WatchConnectivityState
void WatchConnectivityState(std::unique_ptr< ConnectivityStateWatcherInterface > watcher) override
Definition: subchannel_interface.h:115
grpc_core::SubchannelInterface::SubchannelInterface
SubchannelInterface(const char *trace=nullptr)
Definition: subchannel_interface.h:62
grpc_core::SubchannelInterface::DataWatcherInterface
Definition: subchannel_interface.h:57
ref_counted_ptr.h
grpc_core::DelegatingSubchannel::CancelConnectivityStateWatch
void CancelConnectivityStateWatch(ConnectivityStateWatcherInterface *watcher) override
Definition: subchannel_interface.h:119
watcher
ClusterWatcher * watcher
Definition: cds.cc:148
grpc_core::SubchannelInterface::CancelConnectivityStateWatch
virtual void CancelConnectivityStateWatch(ConnectivityStateWatcherInterface *watcher)=0
iomgr_fwd.h
grpc_core::SubchannelInterface::AddDataWatcher
virtual void AddDataWatcher(std::unique_ptr< DataWatcherInterface > watcher)=0
grpc_core::SubchannelInterface
Definition: subchannel_interface.h:37
grpc_core::SubchannelInterface::~SubchannelInterface
~SubchannelInterface() override=default
grpc_core::SubchannelInterface::ConnectivityStateWatcherInterface
Definition: subchannel_interface.h:39
grpc_core::SubchannelInterface::ResetBackoff
virtual void ResetBackoff()=0
port_platform.h


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