|
|
|
@ -2,39 +2,22 @@ package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"net"
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
pb "FRMS/internal/pkg/grpc"
|
|
|
|
|
"FRMS/internal/pkg/reactor"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
fmt.Println("running")
|
|
|
|
|
lis, err := net.Listen("tcp", "192.1.168.156:2000")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
}
|
|
|
|
|
grpcServer := grpc.NewServer()
|
|
|
|
|
pb.RegisterCoordinatorServer(grpcServer, newServer())
|
|
|
|
|
grpcServer.Serve(lis)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newServer() *coordinatorServer {
|
|
|
|
|
s := &coordinatorServer{}
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type coordinatorServer struct {
|
|
|
|
|
pb.UnimplementedCoordinatorServer
|
|
|
|
|
id string
|
|
|
|
|
type coordinator interface {
|
|
|
|
|
Start() error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *coordinatorServer) PingHandler(ctx context.Context, ping *pb.PingRequest) (*pb.PingResponse, error) {
|
|
|
|
|
now := time.Now()
|
|
|
|
|
fmt.Printf("Ping from Central server recieved at time %v\n", now.Format("15:04:05"))
|
|
|
|
|
return &pb.PingResponse{Id: s.id}, nil
|
|
|
|
|
func main() {
|
|
|
|
|
id:= "192.1.168.156"
|
|
|
|
|
port:= 2000
|
|
|
|
|
c := reactor.NewCoordinator(id,port)
|
|
|
|
|
go c.Start()
|
|
|
|
|
fmt.Printf("Starting reactor %v\n",id)
|
|
|
|
|
for true {
|
|
|
|
|
// endless loop to keep main alive
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|