Beispiel #1
0
func WatchConnChange(conn *zk.Conn) {
	fpath := ZOOKEEPER_CONN_PATH
	for {
		log.Info("zk path:%s set a watch", fpath)
		_, _, watch, err := conn.ChildrenW(fpath)
		if err != nil {
			log.Info("path:%s get error ,try later", fpath)
			time.Sleep(10 * time.Second)
			continue
		}
		event := <-watch
		log.Info("zk path:%s receive a event %v", fpath, event)
		UpdateConnectorList()
	}
}
Beispiel #2
0
func loadConfig(fail bool) error {
	temp := NewDefaultConfig()
	if Conf == nil {
		configLock.Lock()
		Conf = temp
		configLock.Unlock()
	}
	data, err := ioutil.ReadFile(confFile)
	if err != nil {
		log.Error("open config: ", err)
		if fail {
			os.Exit(1)
		}
		return err
	}
	if err = yaml.Unmarshal(data, temp); err != nil {
		log.Error("yaml unmarshal error", err)
		if fail {
			os.Exit(1)
		}
		return err
	}
	log.Info("load config ok", *temp)
	configLock.Lock()
	Conf = temp
	configLock.Unlock()
	return nil
}
Beispiel #3
0
func init() {
	flag.StringVar(&confFile, "c", "router.yaml", "set the connector conf file")
	s := make(chan os.Signal, 1)
	signal.Notify(s, syscall.SIGUSR2)
	go func() {
		for {
			<-s
			loadConfig(false)
			log.Info("Reloaded")
		}
	}()
}
Beispiel #4
0
func WatchRoomConnChange(conn *zk.Conn, roomid string, cancel <-chan int) {
	fpath := path.Join(ZOOKEEPER_ROOM_PATH, roomid)
	for {
		log.Info("zk path:%s set a watch", fpath)
		_, _, watch, err := conn.ChildrenW(fpath)
		if err != nil {
			log.Info("path:%s get error ,try later", fpath)
			time.Sleep(10 * time.Second)
			continue
		}
		select {
		case event := <-watch:
			log.Info("zk path:%s receive a event %v", fpath, event)
			err = GetRoomConnectorFromZk(roomid)
			if err != nil {
				log.Error("get room:%s from zk error", roomid)
			}
		case <-cancel:
			log.Info("cancel room:%s watch", roomid)
			break
		}
	}
}