RegisterChannel registers the given channel c in the channelz database with target as its target and reference name, and adds it to the child list of its parent. parent == nil means no parent. Returns a unique channelz identifier assigned to this channel. If channelz is not turned ON, the channel
(parent *Channel, target string)
| 115 | // |
| 116 | // If channelz is not turned ON, the channelz database is not mutated. |
| 117 | func RegisterChannel(parent *Channel, target string) *Channel { |
| 118 | id := IDGen.genID() |
| 119 | |
| 120 | if !IsOn() { |
| 121 | return &Channel{ID: id} |
| 122 | } |
| 123 | |
| 124 | isTopChannel := parent == nil |
| 125 | |
| 126 | cn := &Channel{ |
| 127 | ID: id, |
| 128 | RefName: target, |
| 129 | nestedChans: make(map[int64]string), |
| 130 | subChans: make(map[int64]string), |
| 131 | Parent: parent, |
| 132 | trace: &ChannelTrace{CreationTime: time.Now(), Events: make([]*traceEvent, 0, getMaxTraceEntry())}, |
| 133 | } |
| 134 | cn.ChannelMetrics.Target.Store(&target) |
| 135 | db.addChannel(id, cn, isTopChannel, cn.getParentID()) |
| 136 | return cn |
| 137 | } |
| 138 | |
| 139 | // RegisterSubChannel registers the given subChannel c in the channelz database |
| 140 | // with ref as its reference name, and adds it to the child list of its parent |