Пример #1
0
// InitWatch initialize watch module
func InitWatch() error {
	// Initialize zookeeper connection
	Log.Info("Initializing zookeeper,zookeeper.Dial(\"%s\", \"%dms\")", Conf.ZKAddr, Conf.ZKTimeout/1000000)
	zkTmp, session, err := zookeeper.Dial(Conf.ZKAddr, Conf.ZKTimeout)
	if err != nil {
		return err
	}
	zk = zkTmp

	// Zookeeper client will reconnect automatically
	for {
		event := <-session
		if event.State < zookeeper.STATE_CONNECTING {
			return errors.New(fmt.Sprintf("connect zookeeper fail, event:\"%v\"", event))
		} else if event.State == zookeeper.STATE_CONNECTING {
			Log.Warn("Zookeeper connecting!")
			time.Sleep(time.Second)
			continue
		} else {
			break
		}
	}

	Log.Info("Initialize zookeeper OK")

	// Zookeeper create Public message subnode
	if err := zkCreate(); err != nil {
		return err
	}

	// Init public message mid-creater
	PubMID = timeID.NewTimeID()

	return nil
}
Пример #2
0
// New a user seq stored message channel.
func NewSeqChannel() *SeqChannel {
	ch := &SeqChannel{
		mutex:  &sync.Mutex{},
		conn:   hlist.New(),
		timeID: id.NewTimeID(),
		token:  nil,
	}
	// save memory
	if Conf.Auth {
		ch.token = NewToken()
	}
	return ch
}
Пример #3
0
func NewLockTimeID(conn *zk.Conn) *LockTimeID {
	return &LockTimeID{conn: conn, id: timeID.NewTimeID()}
}