-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathstructsStatusHandlers.go
101 lines (83 loc) · 3.23 KB
/
structsStatusHandlers.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package factory
import (
"fmt"
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go-core/core/check"
"github.com/ElrondNetwork/elrond-go-core/data/typeConverters"
"github.com/ElrondNetwork/elrond-go-core/marshal"
logger "github.com/ElrondNetwork/elrond-go-logger"
"github.com/ElrondNetwork/elrond-go/node/external"
"github.com/ElrondNetwork/elrond-go/statusHandler"
"github.com/ElrondNetwork/elrond-go/statusHandler/persister"
"github.com/ElrondNetwork/elrond-go/storage"
)
var log = logger.GetOrCreate("main")
// StatusHandlersInfo is struct that stores all components that are returned when status handlers are created
type statusHandlersInfo struct {
AppStatusHandler core.AppStatusHandler
StatusMetrics external.StatusMetricsHandler
PersistentHandler *persister.PersistentStatusHandler
}
type statusHandlerUtilsFactory struct {
}
// NewStatusHandlersFactory will return the status handler factory
func NewStatusHandlersFactory() (*statusHandlerUtilsFactory, error) {
return &statusHandlerUtilsFactory{}, nil
}
// Create will return a slice of status handlers
func (shuf *statusHandlerUtilsFactory) Create(
marshalizer marshal.Marshalizer,
uint64ByteSliceConverter typeConverters.Uint64ByteSliceConverter,
) (StatusHandlersUtils, error) {
var appStatusHandlers []core.AppStatusHandler
var err error
var handler core.AppStatusHandler
baseErrMessage := "error creating status handler"
if check.IfNil(marshalizer) {
return nil, fmt.Errorf("%s: nil marshalizer", baseErrMessage)
}
if check.IfNil(uint64ByteSliceConverter) {
return nil, fmt.Errorf("%s: nil uint64 byte slice converter", baseErrMessage)
}
statusMetrics := statusHandler.NewStatusMetrics()
appStatusHandlers = append(appStatusHandlers, statusMetrics)
persistentHandler, err := persister.NewPersistentStatusHandler(marshalizer, uint64ByteSliceConverter)
if err != nil {
return nil, err
}
appStatusHandlers = append(appStatusHandlers, persistentHandler)
if len(appStatusHandlers) > 0 {
handler, err = statusHandler.NewAppStatusFacadeWithHandlers(appStatusHandlers...)
if err != nil {
log.Warn("cannot init AppStatusFacade", "error", err)
}
} else {
handler = statusHandler.NewNilStatusHandler()
log.Debug("no AppStatusHandler used: started with NilStatusHandler")
}
statusHandlersInfoObject := new(statusHandlersInfo)
statusHandlersInfoObject.AppStatusHandler = handler
statusHandlersInfoObject.StatusMetrics = statusMetrics
statusHandlersInfoObject.PersistentHandler = persistentHandler
return statusHandlersInfoObject, nil
}
// UpdateStorerAndMetricsForPersistentHandler will set storer for persistent status handler
func (shi *statusHandlersInfo) UpdateStorerAndMetricsForPersistentHandler(store storage.Storer) error {
err := shi.PersistentHandler.SetStorage(store)
if err != nil {
return err
}
return nil
}
// StatusHandler returns the status handler
func (shi *statusHandlersInfo) StatusHandler() core.AppStatusHandler {
return shi.AppStatusHandler
}
// Metrics returns the status metrics
func (shi *statusHandlersInfo) Metrics() external.StatusMetricsHandler {
return shi.StatusMetrics
}
// IsInterfaceNil returns true if the interface is nil
func (shi *statusHandlersInfo) IsInterfaceNil() bool {
return shi == nil
}