-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
52 lines (42 loc) · 1.48 KB
/
interface.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
package types
import (
"sort"
)
type EngineEnqueue func(data IStreamData) bool
// ***********************************
type IStreamEngine interface {
URL() string
Write(data IStreamData, success *bool)
}
type StreamDataKind byte
const (
StreamDataNilKind StreamDataKind = 0x00
StreamDataAnalysisKind StreamDataKind = 0x01
StreamDataNotifyKind StreamDataKind = 0x02
StreamDataKlineKind StreamDataKind = 0x03
StreamDataWebSocketKind StreamDataKind = 0x04
)
// ***********************************
type IStreamData interface {
BlockHeight() int64
DataType() StreamDataKind
}
type IStreamDatas []IStreamData
//nolint
func (datas IStreamDatas) Len() int { return len(datas) }
func (datas IStreamDatas) Less(i, j int) bool { return datas[i].BlockHeight() < datas[j].BlockHeight() }
func (datas IStreamDatas) Swap(i, j int) { datas[i], datas[j] = datas[j], datas[i] }
// Sort is a helper function to sort the set of IStreamDatas in-place.
func (datas IStreamDatas) Sort() IStreamDatas {
sort.Sort(datas)
return datas
}
// Distributed State Service Interface
type IDistributeStateService interface {
GetLockerID() string
GetDistState(stateKey string) (string, error)
SetDistState(stateKey string, stateValue string) error
FetchDistLock(lockKey string, locker string, expiredInMS int) (bool, error)
ReleaseDistLock(lockKey string, locker string) (bool, error)
UnlockDistLockWithState(lockKey string, locker string, stateKey string, stateValue string) (bool, error)
}