-
Notifications
You must be signed in to change notification settings - Fork 0
/
flowlookup.go
46 lines (39 loc) · 925 Bytes
/
flowlookup.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
package balance
import (
"fmt"
"sync"
)
type flowLookup struct {
lock sync.RWMutex
lookup map[string]*worker
}
func newFlowLookup() *flowLookup {
return &flowLookup{
lookup: make(map[string]*worker),
}
}
func (f *flowLookup) store(hash string, w *worker) {
f.lock.Lock()
defer f.lock.Unlock()
f.lookup[hash] = w
}
func (f *flowLookup) load(hash string) (w *worker, found bool) {
f.lock.RLock()
defer f.lock.RUnlock()
w, found = f.lookup[hash]
return
}
func (f *flowLookup) delete(hash string) {
f.lock.Lock()
defer f.lock.Unlock()
delete(f.lookup, hash)
}
func (f *flowLookup) print() {
f.lock.RLock()
defer f.lock.RUnlock()
fmt.Println("\n\n==============================================================")
for hash, worker := range f.lookup {
fmt.Printf("[%s]\t%s (%v)\n", hash, worker.uuid, worker.idx)
}
fmt.Printf("==============================================================\n\n")
}