-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
77 lines (55 loc) · 1.27 KB
/
metadata.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package quacktors
import (
"sync"
)
var remoteMonitorQuitAbortables = make(map[string]Abortable)
var remoteMonitorQuitAbortablesMu = &sync.RWMutex{}
var machineId = uuidString()
var pidMap = make(map[string]*Pid)
var pidMapMu = &sync.RWMutex{}
var systemWg = &sync.WaitGroup{}
var machines = map[string]*Machine{}
var machinesMu = &sync.RWMutex{}
func registerPid(pid *Pid) {
pidMapMu.Lock()
defer pidMapMu.Unlock()
pid.Id = uuidString()
pidMap[pid.Id] = pid
systemWg.Add(1)
}
func deletePid(pidId string) {
pidMapMu.Lock()
defer pidMapMu.Unlock()
delete(pidMap, pidId)
systemWg.Done()
}
func getByPidId(pidId string) (*Pid, bool) {
pidMapMu.RLock()
defer pidMapMu.RUnlock()
v, ok := pidMap[pidId]
return v, ok
}
func registerMachine(machine *Machine) {
machinesMu.Lock()
defer machinesMu.Unlock()
machines[machine.MachineId] = machine
}
func getMachine(machineId string) (*Machine, bool) {
machinesMu.RLock()
defer machinesMu.RUnlock()
v, ok := machines[machineId]
return v, ok
}
func deleteMachine(machineId string) {
machinesMu.Lock()
defer machinesMu.Unlock()
delete(machines, machineId)
}
//Run waits until all actors have quit.
func Run() {
systemWg.Wait()
}
//MachineId returns the local machine id.
func MachineId() string {
return machineId
}