NewCoordination creates a BasicCoordination
(client CoordinatorClient)
| 174 | |
| 175 | // NewCoordination creates a BasicCoordination |
| 176 | func (c *BasicCoordinationController) NewCoordination(client CoordinatorClient) *BasicCoordination { |
| 177 | b := &BasicCoordination{ |
| 178 | logger: c.Logger, |
| 179 | errChan: make(chan error, 1), |
| 180 | coordinatee: c.Coordinatee, |
| 181 | client: client, |
| 182 | respLoopDone: make(chan struct{}), |
| 183 | sendAcks: c.SendAcks, |
| 184 | initiator: c.Initiator, |
| 185 | direction: c.Direction, |
| 186 | } |
| 187 | |
| 188 | c.Coordinatee.SetNodeCallback(func(node *Node) { |
| 189 | pn, err := NodeToProto(node) |
| 190 | if err != nil { |
| 191 | b.logger.Critical(context.Background(), "failed to convert node", slog.Error(err)) |
| 192 | b.SendErr(err) |
| 193 | return |
| 194 | } |
| 195 | b.Lock() |
| 196 | defer b.Unlock() |
| 197 | if b.closed { |
| 198 | b.logger.Debug(context.Background(), "ignored node update because coordination is closed") |
| 199 | return |
| 200 | } |
| 201 | err = b.client.Send(&proto.CoordinateRequest{UpdateSelf: &proto.CoordinateRequest_UpdateSelf{Node: pn}}) |
| 202 | if err != nil { |
| 203 | b.SendErr(xerrors.Errorf("write: %w", err)) |
| 204 | } |
| 205 | }) |
| 206 | go b.respLoop() |
| 207 | |
| 208 | return b |
| 209 | } |
| 210 | |
| 211 | // BasicCoordination handles: |
| 212 | // |