Skip to content

Commit

Permalink
refactor balancer server
Browse files Browse the repository at this point in the history
  • Loading branch information
pysel committed Nov 29, 2023
1 parent 3b0cd7f commit deb6aa5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions balancer/balancer-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ type BalancerServer struct {
*Balancer
}

func RunBalancerServer(port int64, partitions int) net.Addr {
func RegisterBalancerServer(b *Balancer) *grpc.Server {
s := grpc.NewServer()
reflection.Register(s)
pbbalancer.RegisterBalancerServiceServer(s, &BalancerServer{Balancer: b})

return s
}

func listenOnPort(s *grpc.Server, port int64) net.Addr {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
panic(err)
}

balancer := NewBalancer(partitions)

s := grpc.NewServer()
reflection.Register(s)
pbbalancer.RegisterBalancerServiceServer(s, &BalancerServer{Balancer: balancer})
go s.Serve(lis)

return lis.Addr()
}

0 comments on commit deb6aa5

Please sign in to comment.