GRPC Core  9.0.0
subchannel_interface.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2019 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_SUBCHANNEL_INTERFACE_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_INTERFACE_H
21 
23 
26 
27 namespace grpc_core {
28 
29 // The interface for subchannels that is exposed to LB policy implementations.
30 class SubchannelInterface : public RefCounted<SubchannelInterface> {
31  public:
33  public:
35 
36  // Will be invoked whenever the subchannel's connectivity state
37  // changes. There will be only one invocation of this method on a
38  // given watcher instance at any given time.
40  grpc_connectivity_state new_state) = 0;
41 
42  // TODO(roth): Remove this as soon as we move to EventManager-based
43  // polling.
45  };
46 
47  template <typename TraceFlagT = TraceFlag>
48  explicit SubchannelInterface(TraceFlagT* trace_flag = nullptr)
49  : RefCounted<SubchannelInterface>(trace_flag) {}
50 
51  virtual ~SubchannelInterface() = default;
52 
53  // Returns the current connectivity state of the subchannel.
55 
56  // Starts watching the subchannel's connectivity state.
57  // The first callback to the watcher will be delivered when the
58  // subchannel's connectivity state becomes a value other than
59  // initial_state, which may happen immediately.
60  // Subsequent callbacks will be delivered as the subchannel's state
61  // changes.
62  // The watcher will be destroyed either when the subchannel is
63  // destroyed or when CancelConnectivityStateWatch() is called.
64  // There can be only one watcher of a given subchannel. It is not
65  // valid to call this method a second time without first cancelling
66  // the previous watcher using CancelConnectivityStateWatch().
67  virtual void WatchConnectivityState(
68  grpc_connectivity_state initial_state,
69  std::unique_ptr<ConnectivityStateWatcherInterface> watcher) = 0;
70 
71  // Cancels a connectivity state watch.
72  // If the watcher has already been destroyed, this is a no-op.
75 
76  // Attempt to connect to the backend. Has no effect if already connected.
77  // If the subchannel is currently in backoff delay due to a previously
78  // failed attempt, the new connection attempt will not start until the
79  // backoff delay has elapsed.
80  virtual void AttemptToConnect() = 0;
81 
82  // Resets the subchannel's connection backoff state. If AttemptToConnect()
83  // has been called since the subchannel entered TRANSIENT_FAILURE state,
84  // starts a new connection attempt immediately; otherwise, a new connection
85  // attempt will be started as soon as AttemptToConnect() is called.
86  virtual void ResetBackoff() = 0;
87 
88  // TODO(roth): Need a better non-grpc-specific abstraction here.
89  virtual const grpc_channel_args* channel_args() = 0;
90 };
91 
92 } // namespace grpc_core
93 
94 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_INTERFACE_H */
Definition: ref_counted.h:248
virtual void OnConnectivityStateChange(grpc_connectivity_state new_state)=0
Definition: subchannel_interface.h:30
virtual void WatchConnectivityState(grpc_connectivity_state initial_state, std::unique_ptr< ConnectivityStateWatcherInterface > watcher)=0
virtual ~SubchannelInterface()=default
virtual void CancelConnectivityStateWatch(ConnectivityStateWatcherInterface *watcher)=0
SubchannelInterface(TraceFlagT *trace_flag=nullptr)
Definition: subchannel_interface.h:48
virtual grpc_connectivity_state CheckConnectivityState()=0
virtual const grpc_channel_args * channel_args()=0
virtual void AttemptToConnect()=0
grpc_connectivity_state
Connectivity state of a channel.
Definition: connectivity_state.h:27
Round Robin Policy.
Definition: backend_metric.cc:24
struct grpc_pollset_set grpc_pollset_set
Definition: pollset_set.h:31
An array of arguments that can be passed around.
Definition: grpc_types.h:132