func (self *MmuxConnection) SetId(id string) { self.Mutex.Lock() defer self.Mutex.Unlock() self.Identifier = id self.Hash = util.MurmurHash([]byte(id)) }
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() }
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() }
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") }