-
Notifications
You must be signed in to change notification settings - Fork 175
/
distributor.go
73 lines (62 loc) · 1.67 KB
/
distributor.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
package events
import (
"sync"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state/protocol"
)
// Distributor distributes events to a list of subscribers.
type Distributor struct {
subscribers []protocol.Consumer
mu sync.RWMutex
}
// NewDistributor returns a new events distributor.
func NewDistributor() *Distributor {
return &Distributor{}
}
func (d *Distributor) AddConsumer(consumer protocol.Consumer) {
d.mu.Lock()
defer d.mu.Unlock()
d.subscribers = append(d.subscribers, consumer)
}
func (d *Distributor) BlockFinalized(block *flow.Header) {
d.mu.RLock()
defer d.mu.RUnlock()
for _, sub := range d.subscribers {
sub.BlockFinalized(block)
}
}
func (d *Distributor) BlockProcessable(block *flow.Header, certifyingQC *flow.QuorumCertificate) {
d.mu.RLock()
defer d.mu.RUnlock()
for _, sub := range d.subscribers {
sub.BlockProcessable(block, certifyingQC)
}
}
func (d *Distributor) EpochTransition(newEpoch uint64, first *flow.Header) {
d.mu.RLock()
defer d.mu.RUnlock()
for _, sub := range d.subscribers {
sub.EpochTransition(newEpoch, first)
}
}
func (d *Distributor) EpochSetupPhaseStarted(epoch uint64, first *flow.Header) {
d.mu.RLock()
defer d.mu.RUnlock()
for _, sub := range d.subscribers {
sub.EpochSetupPhaseStarted(epoch, first)
}
}
func (d *Distributor) EpochCommittedPhaseStarted(epoch uint64, first *flow.Header) {
d.mu.RLock()
defer d.mu.RUnlock()
for _, sub := range d.subscribers {
sub.EpochCommittedPhaseStarted(epoch, first)
}
}
func (d *Distributor) EpochEmergencyFallbackTriggered() {
d.mu.RLock()
defer d.mu.RUnlock()
for _, sub := range d.subscribers {
sub.EpochEmergencyFallbackTriggered()
}
}