forked from FactomProject/factomd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
specialQueues.go
91 lines (76 loc) · 2.3 KB
/
specialQueues.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
package state
import "github.com/FactomProject/factomd/common/interfaces"
// InMsgMSGQueue counts incoming and outgoing messages for inmsg queue
type InMsgMSGQueue chan interfaces.IMsg
func NewInMsgQueue(capacity int) InMsgMSGQueue {
channel := make(chan interfaces.IMsg, capacity)
return channel
}
// Length of underlying channel
func (q InMsgMSGQueue) Length() int {
return len(q)
}
// Cap of underlying channel
func (q InMsgMSGQueue) Cap() int {
return cap(q)
}
// Enqueue adds item to channel and instruments based on type
func (q InMsgMSGQueue) Enqueue(m interfaces.IMsg) {
measureMessage(TotalMessageQueueInMsgGeneralVec, m, true)
measureMessage(CurrentMessageQueueInMsgGeneralVec, m, true)
q <- m
}
// Dequeue removes an item from channel and instruments based on type. Returns nil if nothing in
// queue
func (q InMsgMSGQueue) Dequeue() interfaces.IMsg {
select {
case v := <-q:
measureMessage(CurrentMessageQueueInMsgGeneralVec, v, false)
return v
default:
return nil
}
}
// BlockingDequeue will block until it retrieves from queue
func (q InMsgMSGQueue) BlockingDequeue() interfaces.IMsg {
v := <-q
measureMessage(CurrentMessageQueueInMsgGeneralVec, v, false)
return v
}
// ElectionQueue counts incoming and outgoing messages for inmsg queue
type ElectionQueue chan interfaces.IMsg
func NewElectionQueue(capacity int) ElectionQueue {
channel := make(chan interfaces.IMsg, capacity)
return channel
}
// Length of underlying channel
func (q ElectionQueue) Length() int {
return len(q)
}
// Cap of underlying channel
func (q ElectionQueue) Cap() int {
return cap(q)
}
// Enqueue adds item to channel and instruments based on type
func (q ElectionQueue) Enqueue(m interfaces.IMsg) {
//measureMessage(TotalMessageQueueInMsgGeneralVec, m, true)
//measureMessage(CurrentMessageQueueInMsgGeneralVec, m, true)
q <- m
}
// Dequeue removes an item from channel and instruments based on type. Returns nil if nothing in
// queue
func (q ElectionQueue) Dequeue() interfaces.IMsg {
select {
case v := <-q:
// measureMessage(CurrentMessageQueueInMsgGeneralVec, v, false)
return v
default:
return nil
}
}
// BlockingDequeue will block until it retrieves from queue
func (q ElectionQueue) BlockingDequeue() interfaces.IMsg {
v := <-q
//measureMessage(CurrentMessageQueueInMsgGeneralVec, v, false)
return v
}