aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-06-29 12:32:45 -0700
committerGravatar Noah Eisen <ncteisen@google.com>2018-07-06 15:34:54 -0700
commitc9c1feffca295ea9b6232c40d6ac09c5b82343d5 (patch)
tree61f750c0148527d05d6afcc5cfad64f3efaa2c45 /src
parent230035180fef721ae80ce7c35b574938040f4f80 (diff)
Write ClientChannelNode in terms of client_channel
Diffstat (limited to 'src')
-rw-r--r--src/core/ext/filters/client_channel/client_channel_channelz.cc17
-rw-r--r--src/core/ext/filters/client_channel/client_channel_channelz.h6
-rw-r--r--src/core/lib/channel/channelz.h7
-rw-r--r--src/core/lib/surface/channel.cc2
4 files changed, 22 insertions, 10 deletions
diff --git a/src/core/ext/filters/client_channel/client_channel_channelz.cc b/src/core/ext/filters/client_channel/client_channel_channelz.cc
index c9bdce1604..e9534f2207 100644
--- a/src/core/ext/filters/client_channel/client_channel_channelz.cc
+++ b/src/core/ext/filters/client_channel/client_channel_channelz.cc
@@ -18,8 +18,10 @@
#include <grpc/support/port_platform.h>
+#include "src/core/ext/filters/client_channel/client_channel.h"
#include "src/core/ext/filters/client_channel/client_channel_channelz.h"
#include "src/core/lib/gpr/useful.h"
+#include "src/core/lib/surface/channel.h"
#include "src/core/lib/transport/connectivity_state.h"
namespace grpc_core {
@@ -37,12 +39,21 @@ static const grpc_arg_pointer_vtable client_channel_channelz_vtable = {
client_channel_channelz_copy, client_channel_channelz_destroy,
client_channel_channelz_cmp};
+ClientChannelNode::ClientChannelNode(grpc_channel* channel,
+ size_t channel_tracer_max_nodes)
+ : ChannelNode(channel, channel_tracer_max_nodes) {
+ client_channel_ =
+ grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel));
+ GPR_ASSERT(client_channel_->filter == &grpc_client_channel_filter);
+}
+
void ClientChannelNode::PopulateConnectivityState(grpc_json* json) {
grpc_connectivity_state state;
- if (channel() != nullptr) {
- state = grpc_channel_check_connectivity_state(channel(), false);
- } else {
+ if (ChannelIsDestroyed()) {
state = GRPC_CHANNEL_SHUTDOWN;
+ } else {
+ state =
+ grpc_client_channel_check_connectivity_state(client_channel_, false);
}
json = grpc_json_create_child(nullptr, json, "state", nullptr,
GRPC_JSON_OBJECT, false);
diff --git a/src/core/ext/filters/client_channel/client_channel_channelz.h b/src/core/ext/filters/client_channel/client_channel_channelz.h
index d339b4e9f6..a3f8b07fd6 100644
--- a/src/core/ext/filters/client_channel/client_channel_channelz.h
+++ b/src/core/ext/filters/client_channel/client_channel_channelz.h
@@ -31,8 +31,7 @@ namespace channelz {
// functionality like querying for connectivity_state and subchannel data.
class ClientChannelNode : public ChannelNode {
public:
- ClientChannelNode(grpc_channel* channel, size_t channel_tracer_max_nodes)
- : ChannelNode(channel, channel_tracer_max_nodes) {}
+ ClientChannelNode(grpc_channel* channel, size_t channel_tracer_max_nodes);
virtual ~ClientChannelNode() {}
// Override this functionality since client_channels have a notion of
@@ -42,6 +41,9 @@ class ClientChannelNode : public ChannelNode {
// Helper to create a channel arg to ensure this type of ChannelNode is
// created.
static grpc_arg CreateArg();
+
+ private:
+ grpc_channel_element* client_channel_;
};
RefCountedPtr<ChannelNode> MakeClientChannelNode(
diff --git a/src/core/lib/channel/channelz.h b/src/core/lib/channel/channelz.h
index fc972bf802..e14e1b73cb 100644
--- a/src/core/lib/channel/channelz.h
+++ b/src/core/lib/channel/channelz.h
@@ -64,15 +64,14 @@ class ChannelNode : public RefCounted<ChannelNode> {
ChannelTrace* trace() { return trace_.get(); }
- void set_channel_destroyed() {
+ void MarkChannelDestroyed() {
GPR_ASSERT(channel_ != nullptr);
channel_ = nullptr;
}
- intptr_t channel_uuid() { return channel_uuid_; }
+ bool ChannelIsDestroyed() { return channel_ == nullptr; }
- protected:
- grpc_channel* channel() { return channel_; }
+ intptr_t channel_uuid() { return channel_uuid_; }
private:
// testing peer friend.
diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc
index a17fde015f..71bd24ce95 100644
--- a/src/core/lib/surface/channel.cc
+++ b/src/core/lib/surface/channel.cc
@@ -410,7 +410,7 @@ void grpc_channel_internal_unref(grpc_channel* c REF_ARG) {
static void destroy_channel(void* arg, grpc_error* error) {
grpc_channel* channel = static_cast<grpc_channel*>(arg);
if (channel->channelz_channel != nullptr) {
- channel->channelz_channel->set_channel_destroyed();
+ channel->channelz_channel->MarkChannelDestroyed();
channel->channelz_channel.reset();
}
grpc_channel_stack_destroy(CHANNEL_STACK_FROM_CHANNEL(channel));