2020-09-15 14:44:38 +08:00
|
|
|
package schedulingconfigs
|
2020-09-13 19:27:47 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
)
|
|
|
|
|
|
2021-09-20 11:54:21 +08:00
|
|
|
// SchedulingInterface 调度算法接口
|
2020-09-13 19:27:47 +08:00
|
|
|
type SchedulingInterface interface {
|
2021-09-20 11:54:21 +08:00
|
|
|
// HasCandidates 是否有候选对象
|
2020-09-13 19:27:47 +08:00
|
|
|
HasCandidates() bool
|
|
|
|
|
|
2021-09-20 11:54:21 +08:00
|
|
|
// Add 添加候选对象
|
2020-09-13 19:27:47 +08:00
|
|
|
Add(candidate ...CandidateInterface)
|
|
|
|
|
|
2021-09-20 11:54:21 +08:00
|
|
|
// Start 启动
|
2020-09-13 19:27:47 +08:00
|
|
|
Start()
|
|
|
|
|
|
2021-09-20 11:54:21 +08:00
|
|
|
// Next 查找下一个候选对象
|
2020-09-13 19:27:47 +08:00
|
|
|
Next(call *shared.RequestCall) CandidateInterface
|
|
|
|
|
|
2021-09-20 11:54:21 +08:00
|
|
|
// Summary 获取简要信息
|
2020-09-13 19:27:47 +08:00
|
|
|
Summary() maps.Map
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-20 11:54:21 +08:00
|
|
|
// Scheduling 调度算法基础类
|
2020-09-13 19:27:47 +08:00
|
|
|
type Scheduling struct {
|
|
|
|
|
Candidates []CandidateInterface
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-20 11:54:21 +08:00
|
|
|
// HasCandidates 判断是否有候选对象
|
2020-09-13 19:27:47 +08:00
|
|
|
func (this *Scheduling) HasCandidates() bool {
|
|
|
|
|
return len(this.Candidates) > 0
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-20 11:54:21 +08:00
|
|
|
// Add 添加候选对象
|
2020-09-13 19:27:47 +08:00
|
|
|
func (this *Scheduling) Add(candidate ...CandidateInterface) {
|
|
|
|
|
this.Candidates = append(this.Candidates, candidate...)
|
|
|
|
|
}
|