1 Star 3 Fork 3

tym_hmm/kafka-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
StrategyFactory.go 885 Bytes
一键复制 编辑 原始数据 按行查看 历史
天蝎儿 提交于 2年前 . 完成生产者处理
package Stragey
import (
"sync"
)
type strategyContext struct {
index int32
max int32
api StrategyApi
}
func (this *strategyContext) reset() {
this.index = 0
this.max = 0
}
func (this *strategyContext) handle() int32 {
return this.api.Exec(this.index, this.max)
}
/**
策略处理
*/
type strategyFactory struct {
pool sync.Pool
}
func NewStrategyFactory() *strategyFactory {
stf := &strategyFactory{}
stf.pool.New = func() any {
return &strategyContext{}
}
return stf
}
func (this *strategyFactory) param(index, max int32, api StrategyApi) *strategyContext {
_c := this.pool.Get().(*strategyContext)
_c.index = index
_c.max = max
_c.api = api
paramC := *_c
_c.reset()
this.pool.Put(_c)
return &paramC
}
/**
轮询
*/
func (this *strategyFactory) RoundRobin(index, max int32) int32 {
return this.param(index, max, newStrategyRoundRobin()).handle()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/tym_hmm/kafka-go.git
git@gitee.com:tym_hmm/kafka-go.git
tym_hmm
kafka-go
kafka-go
master

搜索帮助