forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch.go
73 lines (62 loc) · 1.2 KB
/
batch.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 kafka
import (
"io"
"sync"
)
// A BatchReader represents a batch of messages reader from a kafka connection.
type BatchReader struct {
rlock sync.Mutex
mutex sync.Mutex
conn *Conn
op *connOp
id int32
offset int64
err error
update bool
}
func (batch *BatchReader) Close() error {
batch.mutex.Lock()
err := batch.err
if batch.conn != nil {
batch.op.cancel(err)
batch.conn.unsetConnReadDeadline()
batch.conn.removeOperation(batch.id)
batch.conn = nil
}
batch.mutex.Unlock()
if err == io.EOF {
err = nil
}
return err
}
func (batch *BatchReader) Read(b []byte) (int, error) {
batch.mutex.Lock()
err := batch.err
batch.mutex.Unlock()
if err != nil {
return 0, err
}
batch.rlock.Lock()
// TODO
batch.rlock.Unlock()
return 0, io.EOF
}
func (batch *BatchReader) Offset() int64 {
batch.mutex.Lock()
offset := batch.offset
batch.mutex.Unlock()
return offset
}
// A BatchWriter exposes an API for writing batches of messages to a kafka
// connection.
type BatchWriter struct {
}
func (batch *BatchWriter) Close() error {
return nil
}
func (batch *BatchWriter) Flush() error {
return nil
}
func (batch *BatchWriter) Write(b []byte) (int, error) {
return 0, nil
}