예제 #1
0
func (self *MmuxConnection) SetId(id string) {
	self.Mutex.Lock()
	defer self.Mutex.Unlock()

	self.Identifier = id
	self.Hash = util.MurmurHash([]byte(id))
}
예제 #2
0
파일: engine.go 프로젝트: kevinxusz/momonga
func (self *Momonga) RemoveConnectionByClientId(clientId string) {
	hash := util.MurmurHash([]byte(clientId))
	key := hash % uint32(self.config.Engine.LockPoolSize)

	self.LockPool[key].Lock()
	delete(self.Connections[key], clientId)
	self.LockPool[key].Unlock()
}
예제 #3
0
파일: engine.go 프로젝트: kevinxusz/momonga
func (self *Momonga) SetConnectionByClientId(clientId string, conn *MmuxConnection) {
	hash := util.MurmurHash([]byte(clientId))
	key := hash % uint32(self.config.Engine.LockPoolSize)

	self.LockPool[key].Lock()
	self.Connections[key][clientId] = conn
	self.LockPool[key].Unlock()
}
예제 #4
0
파일: engine.go 프로젝트: kevinxusz/momonga
func (self *Momonga) GetConnectionByClientId(clientId string) (*MmuxConnection, error) {
	hash := util.MurmurHash([]byte(clientId))
	key := hash % uint32(self.config.Engine.LockPoolSize)

	self.LockPool[key].RLock()
	if cn, ok := self.Connections[key][clientId]; ok {
		self.LockPool[key].RUnlock()
		return cn, nil
	}

	self.LockPool[key].RUnlock()
	return nil, fmt.Errorf("not found")
}