-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnector.go
59 lines (51 loc) · 1.88 KB
/
connector.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
package eevee
import "context"
//Connector contains all the information for this connection to interact with another connector.
//
// Notes:
// The logic in Translator will be specific to this connector as the input and the other connector as the output.
// The MessageID in Translate and IDStore will need to be the same type
type Connector struct {
Connection Connection
Translator Translator
IDStore IDStore
}
// Connection contains the actual connection made to the sink/source
type Connection interface {
Start(ctx context.Context)
In() <-chan Payload
Out() chan<- Payload
RouteStatus() chan<- RouteStatus
}
// Translator translates a raw message to the other connector's raw message
//
// Notes:
// 'out' refers to the other Connection's rawMessage format
// In most case, the translator should be shared since message conversion is not optimal
type Translator interface {
GetID(rawMessage []byte) (messageID MessageID, err error)
SetID(rawMessage []byte, messageID MessageID) ([]byte, error)
TranslateOut(rawMessage []byte) (outRawMessage []byte)
}
// IDStore ensures that message are not duplicated by keeping tracking which messages have been seen
type IDStore interface {
GenerateID() MessageID
MarkID(id MessageID)
UnmarkID(id MessageID)
IsDuplicate(id MessageID) bool
}
// MessageID is how duplicate messages are identified.
//
// Notes:
// Usually the type should be same between Connectors but if they are different, the Translator and IDStore must be able to handle the translation and storage differences.
type MessageID interface{}
// NoMessageID is use to signal that there is no message id set in message
var NoMessageID = 0
// NewConnector returns a new connection object to a sink/source
func NewConnector(connection Connection, translator Translator, idStore IDStore) *Connector {
return &Connector{
Connection: connection,
Translator: translator,
IDStore: idStore,
}
}