-
Notifications
You must be signed in to change notification settings - Fork 1
/
agentstore.go
53 lines (44 loc) · 853 Bytes
/
agentstore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2020 Justice Nanhou. All rights reserved.
// license that can be found in the LICENSE file.
package chaos
import (
"sync"
)
// AgentStore ...
type AgentStore struct {
agents map[string]*Agent
sync.RWMutex
}
var instance *AgentStore
var once sync.Once
// GetAgentStoreInstance ...
func GetAgentStoreInstance() *AgentStore {
once.Do(func() {
instance = &AgentStore{
agents: make(map[string]*Agent, 10),
}
})
return instance
}
// Add ...
func (s *AgentStore) Add(a *Agent) {
s.Lock()
defer s.Unlock()
s.agents[a.ID] = a
}
// Get ...
func (s *AgentStore) Get(aid string) *Agent {
// s.Lock()
// defer s.Unlock()
return s.agents[aid]
}
// List ...
func (s *AgentStore) List() map[string]*Agent {
return s.agents
}
// Count ...
func (s *AgentStore) Count() int {
s.RLock()
defer s.RUnlock()
return len(s.agents)
}