Documentation
¶
Index ¶
- Variables
- type CID
- type CidGenerator
- type Component
- type ComponentPool
- type Config
- type ConfigArray
- type ConfigChanger
- type ConfigGroup
- type ConfigItem
- type ConfigMap
- type ConfigPath
- type ConfigRegisterPoint
- type ConfigWriter
- type Content
- type ContentScheduler
- type ContentType
- type DialogueListener
- type Engine
- type EngineState
- type ErrorManager
- type Event
- type Global
- type HandleScheduler
- type Handler
- type HandlerGroup
- type Listener
- type LockLevel
- type LockRef
- type ManagedScheduler
- type ManyInputLimit
- type ManyOutputLimit
- type PioneerError
- type Poller
- type PollerFactory
- type ProcessManager
- type PushScheduler
- type Pusher
- type PusherFactory
- type Receiver
- type RegisterPoint
- type Scheduler
- type Sender
- type SeriousError
- type Server
- type ServiceError
- type SessionListener
- type SingleInputLimit
- type SingleOutputLimit
- type Subject
- type SubjectMark
- type TextContent
- type TransformFunction
- type TransformScheduler
- type Transformer
- type Version
Constants ¶
This section is empty.
Variables ¶
var CoreVersion = Version([3]byte{0, 0, 1})
CoreVersion 核心库版本号
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component interface {
// GetCid 获取组件唯一 ID
GetCid() CID
// Bind 与引擎进行绑定
// 在被引擎接收时调用
Bind(CID, Global)
// Prepare 准备
// 在引擎处于 Preparing 状态时执行
Prepare(Config)
// OnEnable 启用组件时激活
// 组件被启用时调用
OnEnable()
// OnDisable 禁用组件时激活
// 组件被禁用时调用
OnDisable()
// Destroy 销毁组件
// 在组件被废弃时调用,将会销毁该组件的对象
Destroy()
}
Component 组件
type Config ¶
type Config interface {
// IsMap 判别该配置对象是否是一个 ConfigMap
IsMap() bool
// IsArray 判别该配置对象是否是一个 ConfigArray
IsArray() bool
// IsItem 判别该配置对象是否是一个 ConfigItem
IsItem() bool
// LockState 获取锁状态
LockState() LockLevel
// IsLock 判别该配置对象是否被加锁
IsLock() bool
// IsUnlock 判别该配置对象是否无锁
IsUnlock() bool
// CanRead 判断是否可读
CanRead(LockRef) bool
// CanWrite 判断是否可写
CanWrite(LockRef) bool
// Lock 加锁
Lock(LockLevel) LockRef
// Unlock 解锁
Unlock(LockRef)
// ChangeLockLevel 变更锁等级
ChangeLockLevel(LockRef, LockLevel)
// ToConfigMap 返回该配置对象的 ConfigMap 类型的引用
ToConfigMap() ConfigMap
// ToConfigArray 返回该配置对象的 ConfigArray 类型的引用
ToConfigArray() ConfigArray
// ToConfigItem 返回该配置对象的 ConfigItem 类型的引用
ToConfigItem() ConfigItem
// GetPath 获取从根配置项到当前配置项的路径
GetPath() ConfigPath
}
Config 配置
type ConfigArray ¶
type ConfigArray interface {
Config
ConfigGroup
// Get 根据 Index 获取对应的 Config 对象
Get(int) Config
// Items 获取该对象下的所有子配置
Items() []Config
}
ConfigArray 配置数组
type ConfigGroup ¶
type ConfigGroup interface {
// GetItem 获取配置项
GetItem(ConfigPath) ConfigItem
// GetSubConfig 获取子配置对象
GetSubConfig(ConfigPath) ConfigGroup
}
ConfigGroup 配置组
type ConfigItem ¶
type ConfigItem interface {
// GetName 获取当前配置项的名称
GetName() string
// GetValue 获取该配置项的值
GetValue() interface{}
// GetType 获取配置项的值的类型
GetType() reflect.Type
// GetStr 获取字符串类型的配置项的值
GetStr() string
// GetInt 获取整型类型的配置项的值
GetInt() int
// GetInt64 获取 64 位整型类型的配置项的值
GetInt64() int64
// GetBool 获取布尔类型的配置项的值
GetBool() bool
// GetBytes 获取字节数组类型的配置项的值
GetBytes() []byte
// Unmarshal 解组
// 将该配置项解组到指定的对象
Unmarshal(interface{}) error
}
ConfigItem 配置项
type ConfigMap ¶
type ConfigMap interface {
Config
ConfigGroup
// Get 根据 Key 获取对应的 Config 对象
Get(string) Config
// GetByPoint 根据注册点获取对应的 Config 对象
GetByPoint(ConfigRegisterPoint) Config
// Items 获取该对象下的所有子配置
Items() map[string]Config
}
ConfigMap 配置映射集
type ConfigPath ¶
type ConfigPath interface {
// Backward 回退路径
Backward(int) ConfigPath
// Append 在该路径后面追加路径
Append(...interface{}) ConfigPath
// AppendByKey 在该路径后面追加一个 Key 寻址路径
AppendByKey(...string) ConfigPath
// AppendByIndex 在该路径后面追加一个索引寻址路径
AppendByIndex(...int) ConfigPath
// AppendByPath 将指定的路径对象的内容全部追加到该路径后面
AppendByPath(...ConfigPath) ConfigPath
// AppendByExpr 将一个路径表达式追加到该路径后面
AppendByExpr(...string) ConfigPath
// ToExpr 将该对象转换为路径表达式
ToExpr() string
// String 将该对象转换为字符串
// 该方法应该被重写,并且返回结果应该与 ToExpr() 一致
String() string
}
ConfigPath 配置路径
type ConfigWriter ¶
type ConfigWriter interface {
ConfigItem
Set(interface{}) error
}
ConfigWriter 配置修改器
type Content ¶
type Content interface {
// GetType 获取内容类型
GetType() ContentType
// Bytes 返回内容的 Byte 数组表现形式
Bytes() []byte
}
Content 内容接口
type ContentScheduler ¶
type ContentScheduler interface {
Scheduler
// SelectSuitableOutput 选择合适的输出类型
SelectSuitableOutput(Content, Content, Subject) ContentType
}
ContentScheduler 内容调度器 当收到用户的一条请求时,内容调度器将会决定应该给予用户怎样的内容,以及通过哪种方式。 与其他调度器不同的是,内容调度器只决定方向,不决定具体的方式; 比如,内容调度器决定应该通过邮件响应用户,而推送调度器将会选择通过那个邮件推送器去执行。
type ContentType ¶
type ContentType int
ContentType 内容类型 用于标记输入/输出的内容的表示类型
const ( // Text 文本内容 Text ContentType = iota // Audio 音频内容 Audio // Image 图像内容 Image // Video 视频内容 Video )
定义 ContentType 枚举
type DialogueListener ¶
type DialogueListener interface {
Listener
// OnReceive 接收对话时执行
OnReceive()
// OnBeforeAnswer 回答之前执行
OnBeforeAnswer()
}
DialogueListener 对话监听器
type Engine ¶
type Engine interface {
// State 获取引擎的状态
State() EngineState
// Global 获取全局唯一共享对象
Global() Global
// Init 引擎初始化函数
// 同步
// 该方法仅允许引擎处于 Uninitialized 状态时调用
// 该方法被调用后,引擎会立即进入 Configuring 状态
// 该方法执行失败时,引擎将进入 Error 状态,且通过 panic 抛出异常
Init(Global, CidGenerator, ComponentPool)
// Prepare 准备
// 异步
// 该方法仅允许引擎处于 Configuring 状态时调用
// 该方法执行过程中,引擎将进入 Preparing 状态
// 该方法执行失败时,若发生了严重异常,引擎将进入 Error 状态;若发生了其他异常,引擎将回到 Configuring 状态
// 该方法执行完成后,引擎将进入 Ready 状态
Prepare() error
// Run 运行
// 异步
// 该方法仅允许引擎处于 Ready 状态时调用
// 该方法执行过程中,引擎将进入 Running 状态
// 该方法执行失败时,若发生了严重异常,引擎将进入 Error 状态;若发生了其他异常,引擎将进入 Ready 状态
// 该方法会持续执行,直到调用了 Stop() 方法
Run()
// Stop 暂停
// 异步
// 该方法仅允许引擎处于 Running 状态时调用
// 该方法执行过程中,引擎将进入 Stopping 状态
// 该方法执行失败时,引擎将进入 Error 状态
// 该方法执行完成后,引擎将进入 Ready 状态
Stop()
// Destroy 销毁
// 异步
// 该方法仅允许引擎处于 Configuring 或 Ready 状态时调用
// 该方法执行过程中,引擎将进入 Destroying 状态
// 该方法执行失败时,引擎将进入 Error 状态
// 该方法执行完成后,引擎将进入 Destroyed 状态
Destroy()
// Error 获取引擎发生的异常
Error() error
}
Engine 引擎接口
type EngineState ¶
type EngineState uint
EngineState 引擎状态
const ( // Uninitialized 未初始化 // 引擎的初始状态 // 处于该状态下的引擎,可以被调用:State()、Global()、Init() // 当调用 Init() 后,引擎将进入 Configuring 状态,调用失败将进入 Error 状态 Uninitialized EngineState = iota // Configuring 配置中 // 处于该状态下的引擎允许修改全局配置项 // 处于该状态下的引擎,可以被调用:State()、Global()、Prepare()、Destroy() // 当调用 Prepare() 时,引擎将进入 Preparing 状态,若执行成功则进入 Ready 状态,若执行失败将回到 Configuring 状态 // 当调用 Destroy() 时,引擎将进入 Destroying 状态,若执行成功则进入 Destroyed 状态,若执行失败将进入 Error 状态 Configuring // Preparing 准备中 // Configuring 与 Ready 的中间状态 Preparing // Ready 准备就绪 // Ready // Running 运行中 Running // Stopping 暂停中 Stopping // Destroying 销毁中 Destroying // Destroyed 已销毁 Destroyed // Error 异常 Error )
type ErrorManager ¶
type ErrorManager interface {
// Error 接收错误
Error(error)
}
type Global ¶
type Global interface {
// Debug 是否启用调试模式
Debug() bool
// RootConfig 根配置
RootConfig() ConfigMap
// ErrorManager 异常管理器
ErrorManager() ErrorManager
}
Global 全局唯一共享类 应由引擎创建
type HandleScheduler ¶
type HandleScheduler interface {
ManagedScheduler
// Import 导出处理器
// 优先于 Prepare 之前执行
Import(...Handler)
// SelectSuitable 选择合适的处理器
// 参数
// Content: 请求的内容
// Subject: 请求的主体
// TransformFunction: 内容转换函数
// 返回值
// Handler: 合适的处理器
// ContentType: 合适的内容类型,用于调用处理器
SelectSuitable(Content, Subject, TransformFunction) (Handler, ContentType)
}
HandleScheduler 处理调度器 当接收到一条请求时,由处理调度器决定应该由那个处理器来处理请求
type Handler ¶
type Handler interface {
// Component 声明处理器为一个组件
Component
// ManyInputLimit 允许多种输入类型
ManyInputLimit
// SingleOutputLimit 仅允许一种输出类型
SingleOutputLimit
// Active 是否激活
Active(Content, Subject) bool
// Handle 处理函数
Handle(Content, Subject) (Content, error)
}
Handler 处理器接口
type HandlerGroup ¶
type HandlerGroup interface {
// Handler HandlerGroup 也是一个 Handler
Handler
// Add 添加一个 Handler 到该组中
Add(Handler)
// Remove 移除一个 Handler
Remove(CID)
}
HandlerGroup 处理器组 当处理器组被激活时,会依次调用它管辖的所有 Handler
type Listener ¶
type Listener interface {
// Component 声明监听器为一个组件
Component
// OnMount 挂载时执行
OnMount()
// OnUnmount 卸载时执行
OnUnmount()
}
Listener 监听器
type LockLevel ¶
type LockLevel uint
LockLevel 配置锁
const ( // NotAccessible 不可访问 // 锁的拥有者:读 (X) 写 (X) // 其他访问者:读 (X) 写 (X) NotAccessible LockLevel = iota // OwnerReadOnly 拥有者可读 // 锁的拥有者:读 (Y) 写 (X) // 其他访问者:读 (X) 写 (X) OwnerReadOnly // ReadOnly 只读锁 // 锁的拥有者:读 (Y) 写 (X) // 其他访问者:读 (Y) 写 (X) ReadOnly // OwnerCanWrite 拥有者可写 // 锁的拥有者:读 (Y) 写 (Y) // 其他访问者:读 (Y) 写 (X) OwnerCanWrite // Unlock 无锁 // 锁的拥有者:读 (Y) 写 (Y) // 其他访问者:读 (Y) 写 (Y) Unlock )
type LockRef ¶
type LockRef uint64
LockRef 锁引用 用于识别锁的拥有者
const NoneLockRef LockRef = 0
NoneLockRef 空引用
type ManagedScheduler ¶
type ManagedScheduler interface {
// Scheduler 声明托管式调度器为一个调度器
Scheduler
// Enable 启用指定的组件
Enable(CID)
// Disable 禁用指定的组件
Disable(CID)
}
ManagedScheduler 托管式调度器 即,将对组件的管理托管给对应的调度器,由调度器去决定采用哪种组件
type ManyInputLimit ¶
type ManyInputLimit interface {
// InputLimit 输入限定类型
InputLimit() []ContentType
}
ManyInputLimit 多输入限定
type ManyOutputLimit ¶
type ManyOutputLimit interface {
// OutputLimit 输出限定类型
OutputLimit() []ContentType
}
ManyOutputLimit 多输出限定
type Poller ¶
type Poller interface {
// Receiver 继承接收器接口
Receiver
// HasNext 是否存在下一项输入内容
HasNext() bool
// Next 获取下一项输入内容
Next() (Content, Subject, error)
}
Poller 轮询器(主动接收器) 轮询器会在运行期间,根据固定的轮询策略被不断调用,若存在待处理的消息,则进行激活处理,否则等待下一次轮询
type PollerFactory ¶
PollerFactory 轮询器工厂 用于构造 Poller 对象
type ProcessManager ¶
ProcessManager 流程管理器
type PushScheduler ¶
type PushScheduler interface {
ManagedScheduler
// Import 导出推送器
// 优先于 Prepare 之前执行
Import(...Pusher)
// SelectSuitable 选择合适的推送器
// Content: 请求的内容
// Subject: 请求的主体
// ContentType: 要求的响应内容类型(返回的 Pusher 的输入类型必须可以接受该类型)
// TransformFunction: 内容转换函数
SelectSuitable(Content, Subject, ContentType, TransformFunction) Pusher
}
PushScheduler 推送调度器 当需要响应请求时,由推送调度器决定应该使用哪个推送器响应用户
type PusherFactory ¶
PusherFactory 推送器工厂 用于构造 Pusher 对象
type Receiver ¶
type Receiver interface {
// Component 声明接收器为一个组件
Component
// ManyOutputLimit 允许接收器接收多种类型的输入
// 接收器的输出等同于整个引擎的输入
ManyOutputLimit
}
Receiver 接收器接口
type Sender ¶
type Sender interface {
// Component 声明发送器为一个组件
Component
// ManyInputLimit 允许发送器发送多种类型的输出
// 发送器的输入等同于整个引擎的输出
ManyInputLimit
}
Sender 发送器接口
type Server ¶
type Server interface {
// Receiver 继承接收器接口
Receiver
// Sender 继承发送器接口
Sender
// OnStart 开始服务
OnStart()
// OnStop 暂停服务
OnStop()
}
Server 服务器 它即是一个接收器,也是一个发送器
type SessionListener ¶
type SessionListener interface {
Listener
// OnCreateSession 创建会话时执行
OnCreateSession(sessionID string)
// OnDestroySession 销毁会话时执行
OnDestroySession(sessionID string)
}
SessionListener 会话监听器
type SingleInputLimit ¶
type SingleInputLimit interface {
// InputLimit 输入限定类型
InputLimit() ContentType
}
SingleInputLimit 单输入限定
type SingleOutputLimit ¶
type SingleOutputLimit interface {
// OutputLimit 输出限定类型
OutputLimit() ContentType
}
SingleOutputLimit 单输出限定
type Subject ¶
type Subject interface {
// Get 获取主体值
Get(SubjectMark) string
// Set 设置主体值
Set(SubjectMark, string) string
}
Subject 主体
type TextContent ¶
type TextContent interface {
// Content 继承 Content 接口
Content
// GetText 获取文本内容
GetText() string
// GetCharset 获取该文本的字符编码
GetCharset() string
}
TextContent 文本内容接口
type TransformFunction ¶
type TransformFunction func(Content, ContentType) Content
TransformFunction 转换函数 不同于转换器,转换函数是运行时构建的,交由 HandleScheduler 和 PushScheduler 使用的 其一,是为了防止 TransformScheduler 被暴露 其二,是可以在转换时做一些操作,比如转换的缓存什么的
type TransformScheduler ¶
type TransformScheduler interface {
ManagedScheduler
// Import 导出转换器
// 优先于 Prepare 之前执行
Import(...Transformer)
// SelectSuitable 选择合适的转换器
// src : 输入的内容类型
// dst : 输出的内容类型
SelectSuitable(src ContentType, dst ContentType) Transformer
}
TransformScheduler 转换调度器 当需要进行内容转换时,由转换调度器决定应该激活哪个转换器进行内容转换
type Transformer ¶
type Transformer interface {
// Component 声明变换器为一个组件
Component
// SingleInputLimit 仅允许一种输入类型
SingleInputLimit
// SingleOutputLimit 仅允许一种输出类型
SingleOutputLimit
// Transform 转换
Transform(original Content) Content
}
Transformer 变换器 对象类型:单例 作用:用于将一种 Content 转换成另一种 Content