示例#1
0
文件: fetcher.go 项目: gameogre/agent
// message fetcher
func fetcher_task() {
	//connect to game service
	clients, err := services.GetAllService(services.SERVICE_GAME)
	if err != nil {
		log.Critical(err)
		os.Exit(-1)
	}
	for _, cli := range clients {
		service, _ := cli.(proto.GameServiceClient)
		stream, err := service.Notify(context.Background(), &proto.Game_Nil{})
		if err != nil {
			log.Critical(err)
			os.Exit(-1)
		}
		go func() {
			for {
				p, err := stream.Recv()
				if err == io.EOF {
					log.Infof("stream recv EOF err :%v", err)
					return
				}
				if err != nil {
					log.Critical("stream recv gs err", err)
					continue
				}
				registry.Deliver(p.Uid, p.Content)
			}
		}()
	}
}
示例#2
0
// watcher for data change in etcd directory
func (p *service_pool) watcher() {
	client := p.client_pool.Get().(*etcd.Client)
	defer func() {
		p.client_pool.Put(client)
	}()

	for {
		ch := make(chan *etcd.Response, 10)
		go func() {
			for {
				if resp, ok := <-ch; ok {
					if resp.Node.Dir {
						continue
					}
					key, value := resp.Node.Key, resp.Node.Value
					if value == "" {
						log.Tracef("node delete: %v", key)
						p.remove_service(key)
					} else {
						log.Tracef("node add: %v %v", key, value)
						p.add_service(key, value)
					}
				} else {
					return
				}
			}
		}()

		_, err := client.Watch(DEFAULT_SERVICE_PATH, 0, true, ch, nil)
		if err != nil {
			log.Critical(err)
		}
		<-time.After(RETRY_DELAY)
	}
}
示例#3
0
func (s *server) next_uid() int32 {
	c, err := services.GetService(services.SERVICE_SNOWFLAKE)
	service, _ := c.(proto.SnowflakeServiceClient)
	uid, err := service.Next(context.Background(), &proto.Snowflake_Key{Name: SEQS_UID})
	if err != nil {
		log.Critical(err)
		return 0
	}
	return int32(uid.Value)
}
示例#4
0
文件: forward.go 项目: gameogre/agent
func init() {
	_default_forward = forwarder{}
	//TODO connect all game server and forward packet
	clients, err := services.GetAllService(services.SERVICE_GAME)
	if err != nil {
		log.Critical(err)
		os.Exit(-1)
	}
	for k, cli := range clients {
		service, _ := cli.(GameServiceClient)
		stream, err := service.Packet(context.Background())
		if err != nil {
			log.Critical(err)
			os.Exit(-1)
		}
		_default_forward.gs[k] = stream

	}
	for k, c := range _default_forward.gs {
		go _default_forward.recv(k, c)
	}
}
示例#5
0
文件: proxy.go 项目: gameogre/agent
func init() {
	addr := DEFAULT_STATSD_HOST
	if env := os.Getenv(ENV_STATSD); env != "" {
		addr = env
	}

	s, err := g2s.Dial("udp", addr)
	if err != nil {
		log.Critical(err)
		os.Exit(-1)
	}
	_statter = s
}
示例#6
0
文件: forward.go 项目: gameogre/agent
func (f *forwarder) recv(key string, cli GameService_PacketClient) {
	for {
		in, err := cli.Recv()
		if err == io.EOF {
			log.Infof("stream recv EOF err : %v", err)
			return
		}
		if err != nil {
			log.Critical("Failed to receive a note : %v", err)
			continue
		}
		registry.Deliver(in.Uid, in.Content)
	}
}
示例#7
0
文件: main.go 项目: gameogre/agent
func checkError(err error) {
	if err != nil {
		log.Critical(err)
		os.Exit(-1)
	}
}