-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstream_processor_proxy.go
64 lines (47 loc) · 1.05 KB
/
stream_processor_proxy.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
package epee
import (
"github.com/golang/protobuf/proto"
"sync"
)
type streamProcessorProxy struct {
sync.Mutex
// Indicates if we need to flush this processor or not.
dirty bool
// Last known offset that was successfully processed.
lastOffset int64
// the underlying processor.
proc StreamProcessor
}
func (spp *streamProcessorProxy) Process(offset int64, message proto.Message) error {
spp.Lock()
defer spp.Unlock()
err := spp.proc.Process(offset, message)
if err == nil {
spp.lastOffset = offset
spp.dirty = true
}
return err
}
func (spp *streamProcessorProxy) LastOffset() int64 {
return spp.lastOffset
}
func (spp *streamProcessorProxy) Flush() error {
spp.Lock()
defer spp.Unlock()
err := spp.proc.Flush()
if err == nil {
// This is no longer dirty!
spp.dirty = false
}
return err
}
func (spp *streamProcessorProxy) Dirty() bool {
spp.Lock()
defer spp.Unlock()
return spp.dirty
}
func newStreamProcessorProxy(proc StreamProcessor) *streamProcessorProxy {
spp := new(streamProcessorProxy)
spp.proc = proc
return spp
}