Documentation
¶
Index ¶
- Variables
- func CalculateScoreSimple(counts Counts) uint64
- func CheckType(moduleType Type, module Module) bool
- func LegalMID(mid MID) bool
- func LegalType(moduleType Type) bool
- func NewAddr(network string, ip string, port uint64) (net.Addr, error)
- func SetScore(module Module) bool
- func SplitMID(mid MID) ([]string, error)
- type Analyzer
- type CalculateScore
- type Counts
- type Data
- type Downloader
- type Item
- type MID
- type Module
- type ParseResponse
- type Pipeline
- type ProcessItem
- type Registrar
- type Request
- type Response
- type SNGenertor
- type SummaryStruct
- type Type
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultSNGen = NewSNGenertor(1, 0)
DefaultSNGen 代表默认的组件序列号生成器。
View Source
var ErrNotFoundModuleInstance = errors.New("not found module instance")
ErrNotFoundModuleInstance 代表未找到组件实例的错误类型。
Functions ¶
func CalculateScoreSimple ¶
CalculateScoreSimple 代表简易的组件评分计算函数。
Types ¶
type Analyzer ¶
type Analyzer interface {
Module
// RespParsers 会返回当前分析器使用的响应解析函数的列表。
RespParsers() []ParseResponse
// Analyze 会根据规则分析响应并返回请求和条目。
// 响应需要分别经过若干响应解析函数的处理,然后合并结果。
Analyze(resp *Response) ([]Data, []error)
}
Analyzer 代表分析器的接口类型。 该接口的实现类型必须是并发安全的!
type CalculateScore ¶
CalculateScore 代表用于计算组件评分的函数类型。
type Counts ¶
type Counts struct {
// CalledCount 代表调用计数。
CalledCount uint64
// AcceptedCount 代表接受计数。
AcceptedCount uint64
// CompletedCount 代表成功完成计数。
CompletedCount uint64
// HandlingNumber 代表实时处理数。
HandlingNumber uint64
}
Counts 代表用于汇集组件内部计数的类型。
type Downloader ¶
type Downloader interface {
Module
// Download 会根据请求获取内容并返回响应。
Download(req *Request) (*Response, error)
}
Downloader 代表下载器的接口类型。 该接口的实现类型必须是并发安全的!
type Module ¶
type Module interface {
// ID 用于获取当前组件的ID。
ID() MID
// Addr 用于获取当前组件的网络地址的字符串形式。
Addr() string
// Score 用于获取当前组件的评分。
Score() uint64
// 用于设置当前组件的评分。
SetScore(score uint64)
// ScoreCalculator 用于获取评分计算器。
ScoreCalculator() CalculateScore
// CallCount 用于获取当前组件被调用的计数。
CalledCount() uint64
// AcceptedCount 用于获取被当前组件接受的调用的计数。
// 组件一般会由于超负荷或参数有误而拒绝调用。
AcceptedCount() uint64
// CompletedCount 用于获取当前组件已成功完成的调用的计数。
CompletedCount() uint64
// HandlingNumber 用于获取当前组件正在处理的调用的数量。
HandlingNumber() uint64
//Counts 用于一次性获取所有计数。
Counts() Counts
// Summary 用于获取组件摘要。
Summary() SummaryStruct
}
Module 代表组件的基础接口类型。 该接口的实现类型必须是并发安全的!
type ParseResponse ¶
ParseResponse 代表用于解析HTTP响应的函数的类型。
type Pipeline ¶
type Pipeline interface {
Module
// ItemProcessors 会返回当前条目处理管道使用的条目处理函数的列表。
ItemProcessors() []ProcessItem
// Send 会向条目处理管道发送条目。
// 条目需要依次经过若干条目处理函数的处理。
Send(item Item) []error
// FailFast方法会返回一个布尔值。该值表示当前条目处理管道是否是快速失败的。
// 这里的快速失败是指:只要在处理某个条目时在某一个步骤上出错,
// 那么条目处理管道就会忽略掉后续的所有处理步骤并报告错误。
FailFast() bool
// 设置是否快速失败。
SetFailFast(failFast bool)
}
Pipeline 代表条目处理管道的接口类型。 该接口的实现类型必须是并发安全的!
type ProcessItem ¶
ProcessItem 代表用于处理条目的函数的类型。
type Registrar ¶
type Registrar interface {
// Register 用于注册组件实例。
Register(module Module) (bool, error)
// Unregister 用于注销组件实例。
Unregister(mid MID) (bool, error)
// Get 用于获取一个指定类型的组件的实例。
// 本函数应该基于负载均衡策略返回实例。
Get(moduleType Type) (Module, error)
// GetAllByType 用于获取指定类型的所有组件实例。
GetAllByType(moduleType Type) (map[MID]Module, error)
// GetAll 用于获取所有组件实例。
GetAll() map[MID]Module
// Clear 会清除所有的组件注册记录。
Clear()
}
Registrar 代表组件注册器的接口。
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request 代表数据请求的类型。
func NewRequest ¶
NewRequest 用于创建一个新的请求实例。
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response 代表数据响应的类型。
func NewResponse ¶
NewResponse 用于创建一个新的响应实例。
type SNGenertor ¶
type SNGenertor interface {
// Start 用于获取预设的最小序列号。
Start() uint64
// Max 用于获取预设的最大序列号。
Max() uint64
// Next 用于获取下一个序列号。
Next() uint64
// CycleCount 用于获取循环计数。
CycleCount() uint64
// Get 用于获得一个序列号并准备下一个序列号。
Get() uint64
}
SNGenertor 代表序列号生成器的接口类型。
func NewSNGenertor ¶
func NewSNGenertor(start uint64, max uint64) SNGenertor
NewSNGenertor 会创建一个序列号生成器。 参数start用于指定第一个序列号的值。 参数max用于指定序列号的最大值。
type SummaryStruct ¶
type SummaryStruct struct {
ID MID `json:"id"`
Called uint64 `json:"called"`
Accepted uint64 `json:"accepted"`
Completed uint64 `json:"completed"`
Handling uint64 `json:"handling"`
Extra interface{} `json:"extra,omitempty"`
}
SummaryStruct 代表组件摘要结构的类型。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.