module

package
v0.0.0-...-63bff7e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSNGen = NewSNGenertor(1, 0)

DefaultSNGen 代表默认的组件序列号生成器。

View Source
var ErrNotFoundModuleInstance = errors.New("not found module instance")

ErrNotFounErrNotFoundModuleInstancedInstance 代表未找到组件实例的错误类型。

Functions

func CalculateScoreSimple

func CalculateScoreSimple(counts Counts) uint64

CalculateScoreSimple 代表简易的组件评分计算函数。

func CheckType

func CheckType(moduleType Type, module Module) bool

CheckType 用于判断组件实例的类型是否匹配。

func LegalMID

func LegalMID(mid MID) bool

LegalMID 用于判断给定的组件ID是否合法。

func LegalType

func LegalType(moduleType Type) bool

LegalType 用于判断给定的组件类型是否合法。

func NewAddr

func NewAddr(network string, ip string, port uint64) (net.Addr, error)

NewAddr 会根据参数创建并返回一个网络地址值。 如果参数不合法,那么会返回非nil的错误值。

func SetScore

func SetScore(module Module) bool

SetScore 用于设置给定组件的评分。 结果值代表是否更新了评分。

func SplitMID

func SplitMID(mid MID) ([]string, error)

SplitMID 用于分解组件ID。 第一个结果值表示分解是否成功。 若分解成功,则第二个结果值长度为3, 并依次包含组件类型字母、序列号和组件网络地址(如果有的话)。

Types

type Analyzer

type Analyzer interface {
	Module
	// RespParsers 会返回当前分析器使用的响应解析函数的列表。
	RespParsers() []ParseResponse
	// Analyze 会根据规则分析响应并返回请求和条目。
	// 响应需要分别经过若干响应解析函数的处理,然后合并结果。
	Analyze(resp *Response) ([]Data, []error)
}

Analyzer 代表分析器的接口类型。 该接口的实现类型必须是并发安全的!

type CalculateScore

type CalculateScore func(counts Counts) uint64

CalculateScore 代表用于计算组件评分的函数类型。

type Counts

type Counts struct {
	// CalledCount 代表调用计数。
	CalledCount uint64
	// AcceptedCount 代表接受计数。
	AcceptedCount uint64
	// CompletedCount 代表成功完成计数。
	CompletedCount uint64
	// HandlingNumber 代表实时处理数。
	HandlingNumber uint64
}

Counts 代表用于汇集组件内部计数的类型。

type Data

type Data interface {
	// Valid 用于判断数据是否有效。
	Valid() bool
}

Data 代表数据的接口类型。

type Downloader

type Downloader interface {
	Module
	// Download 会根据请求获取内容并返回响应。
	Download(req *Request) (*Response, error)
}

Downloader 代表下载器的接口类型。 该接口的实现类型必须是并发安全的!

type Item

type Item map[string]interface{}

Item 代表条目的类型。

func (Item) Valid

func (item Item) Valid() bool

Valid 用于判断条目是否有效。

type MID

type MID string

MID 代表组件ID。

func GenMID

func GenMID(mtype Type, sn uint64, maddr net.Addr) (MID, error)

GenMID 会根据给定参数生成组件ID。

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

type ParseResponse func(httpResp *http.Response, respDepth uint32) ([]Data, []error)

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

type ProcessItem func(item Item) (result Item, err error)

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 代表组件注册器的接口。

func NewRegistrar

func NewRegistrar() Registrar

NewRegistrar 用于创建一个组件注册器的实例。

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request 代表数据请求的类型。

func NewRequest

func NewRequest(httpReq *http.Request, depth uint32) *Request

NewRequest 用于创建一个新的请求实例。

func (*Request) Depth

func (req *Request) Depth() uint32

Depth 用于获取请求的深度。

func (*Request) HTTPReq

func (req *Request) HTTPReq() *http.Request

HTTPReq 用于获取HTTP请求。

func (*Request) Valid

func (req *Request) Valid() bool

Valid 用于判断请求是否有效。

type Response

type Response struct {
	// contains filtered or unexported fields
}

Response 代表数据响应的类型。

func NewResponse

func NewResponse(httpResp *http.Response, depth uint32) *Response

NewResponse 用于创建一个新的响应实例。

func (*Response) Depth

func (resp *Response) Depth() uint32

Depth 用于获取响应深度。

func (*Response) HTTPResp

func (resp *Response) HTTPResp() *http.Response

HTTPResp 用于获取HTTP响应。

func (*Response) Valid

func (resp *Response) Valid() bool

Valid 用于判断响应是否有效。

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 代表组件摘要结构的类型。

type Type

type Type string

Type 代表组件的类型。

const (
	// TYPE_DOWNLOADER 代表下载器。
	TYPE_DOWNLOADER Type = "downloader"
	// TYPE_ANALYZER 代表分析器。
	TYPE_ANALYZER Type = "analyzer"
	// TYPE_PIPELINE 代表条目处理管道。
	TYPE_PIPELINE Type = "pipeline"
)

当前认可的组件类型的常量。

func GetType

func GetType(mid MID) (bool, Type)

GetType 用于获取组件的类型。 若给定的组件ID不合法则第一个结果值会是false。

Directories

Path Synopsis
local

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL