代码拉取完成,页面将自动刷新
package memqueue
import (
"errors"
"io"
"github.com/elastic/beats/libbeat/common/atomic"
"github.com/elastic/beats/libbeat/publisher"
"github.com/elastic/beats/libbeat/publisher/queue"
)
type consumer struct {
broker *Broker
resp chan getResponse
done chan struct{}
closed atomic.Bool
}
type batch struct {
consumer *consumer
events []publisher.Event
clientStates []clientState
ack *ackChan
state ackState
}
type ackState uint8
const (
batchActive ackState = iota
batchACK
)
func newConsumer(b *Broker) *consumer {
return &consumer{
broker: b,
resp: make(chan getResponse),
done: make(chan struct{}),
}
}
func (c *consumer) Get(sz int) (queue.Batch, error) {
// log := c.broker.logger
if c.closed.Load() {
return nil, io.EOF
}
select {
case c.broker.requests <- getRequest{sz: sz, resp: c.resp}:
case <-c.done:
return nil, io.EOF
}
// if request has been send, we do have to wait for a response
resp := <-c.resp
return &batch{
consumer: c,
events: resp.buf,
ack: resp.ack,
state: batchActive,
}, nil
}
func (c *consumer) Close() error {
if c.closed.Swap(true) {
return errors.New("already closed")
}
close(c.done)
return nil
}
func (b *batch) Events() []publisher.Event {
if b.state != batchActive {
panic("Get Events from inactive batch")
}
return b.events
}
func (b *batch) ACK() {
if b.state != batchActive {
switch b.state {
case batchACK:
panic("Can not acknowledge already acknowledged batch")
default:
panic("inactive batch")
}
}
b.report()
}
func (b *batch) report() {
b.ack.ch <- batchAckMsg{}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。