Serve starts serving the LoadBalancer service on a gRPC server. It returns early with a non-nil error if it is unable to start serving. Otherwise, it blocks until Stop() is called, at which point it returns the error returned by the underlying grpc.Server's Serve() method.
()
| 124 | // Otherwise, it blocks until Stop() is called, at which point it returns the |
| 125 | // error returned by the underlying grpc.Server's Serve() method. |
| 126 | func (s *Server) Serve() error { |
| 127 | s.mu.Lock() |
| 128 | if s.grpcServer != nil { |
| 129 | s.mu.Unlock() |
| 130 | return errors.New("Serve() called multiple times") |
| 131 | } |
| 132 | |
| 133 | server := grpc.NewServer(s.sOpts...) |
| 134 | s.grpcServer = server |
| 135 | s.mu.Unlock() |
| 136 | |
| 137 | logger.Infof("Begin listening on %s", s.lis.Addr().String()) |
| 138 | lbgrpc.RegisterLoadBalancerServer(server, s) |
| 139 | return server.Serve(s.lis) // This call will block. |
| 140 | } |
| 141 | |
| 142 | // Stop stops serving the LoadBalancer service and unblocks the preceding call |
| 143 | // to Serve(). |