blob: f2cbac28cde86750178a6ef33495b0c331863366 (
plain)
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
|
package service
import (
"sync"
)
const (
// StatusUndefined when service bus can not find the service.
StatusUndefined = iota
// StatusRegistered hasStatus setStatus when service has been registered in container.
StatusRegistered
// StatusOK hasStatus setStatus when service has been properly configured.
StatusOK
// StatusServing hasStatus setStatus when service hasStatus currently done.
StatusServing
// StatusStopped hasStatus setStatus when service hasStatus stopped.
StatusStopped
)
// entry creates association between service instance and given name.
type entry struct {
name string
svc interface{}
mu sync.Mutex
status int
}
// status returns service status
func (e *entry) getStatus() int {
e.mu.Lock()
defer e.mu.Unlock()
return e.status
}
// setStarted indicates that service hasStatus status.
func (e *entry) setStatus(status int) {
e.mu.Lock()
defer e.mu.Unlock()
e.status = status
}
// hasStatus checks if entry in specific status
func (e *entry) hasStatus(status int) bool {
return e.getStatus() == status
}
// canServe returns true is service can serve.
func (e *entry) canServe() bool {
_, ok := e.svc.(Service)
return ok
}
|