frame

package
v0.0.0-...-fa9b265 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2017 License: GPL-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CA_OK        = iota // 0:连接正常
	CA_BROKEN    = iota // 1:连接已断开
	CA_RECONNING = iota // 2:正在重连
	CA_ABANDON   = iota // 3:重连失败放弃connactor对象
)
View Source
const EachReadBufSize = 1024 * 2048

EachReadBufSize buf大小

View Source
const (
	Normalformat = "2006-01-02 15:04:05"
)

定义格式化时间格式

Variables

View Source
var (
	ErrBlocking       = errors.New("operation blocking")
	ErrClosed         = errors.New("connection is closed")
	ErrTimeout        = errors.New("netio timeout")
	ErrMethodNotFound = errors.New("method not found")
)

定义错误类型

View Source
var SrvVersionName = map[SrvVersion]string{
	SV1: "v1",
	SV2: "v2",
}

SrvVersionName 定义服务版本映射

Functions

func ContinuousRecvPack

func ContinuousRecvPack(conn net.Conn, cstmFunc ProcessInComingPackFunc)

ContinuousRecvPack 用于从长连接中持续读取数据 全双工的方式读取数据

func DeliverTo

func DeliverTo(task *protocol.Proto) (*protocol.Proto, error)

DeliverTo deliver request to anthor serve

func GetInnerID

func GetInnerID() int64

GetInnerID 获取内部服务ID

func Netip

func Netip() string

Netip 返回内网IP地址

func RandPort

func RandPort() string

RandPort 随机端口 1024 - 65535

func ReadyTask

func ReadyTask(ctx context.Context, srvMethod string, srvName string, in interface{}) (*protocol.Proto, error)

ReadyTask 准备请求的任务

func RecvPack

func RecvPack(conn net.Conn) ([]byte, error)

RecvPack 用于从客户端连接中读取数据,不提供断线重连功能

func RegisterAndServe

func RegisterAndServe(sd *ServiceDesc, ss interface{}, cfg *config.BaseCfg)

RegisterAndServe 后端服务注册并开启

func SendAll

func SendAll(conn net.Conn, buf []byte) int

SendAll 往连接上发送数据

func ShapingTime

func ShapingTime(begin time.Time, cell time.Duration, ticks int64) time.Time

ShapingTime 把超时时间整形,得到的超时时间显现有规律的间隔; 参数: cell time.Duration 超时的时间粒度 ticks int64 超时的时间滴答数。

func SpanFromTask

func SpanFromTask(task *protocol.Proto) opentracing.Span

SpanFromTask 从Task中加工出Span

func SpanWithTask

func SpanWithTask(ctx context.Context, task *protocol.Proto) opentracing.Span

SpanWithTask 讲Span注入Task

Types

type ConnActor

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

ConnActor 连接对象

func NewActiveConnActor

func NewActiveConnActor(c net.Conn) *ConnActor

NewActiveConnActor 生成一个主动的连接,主动向对端发送请求并等待响应的连接

func NewPassiveConnActor

func NewPassiveConnActor(c net.Conn) *ConnActor

NewPassiveConnActor Iceberg下层服务需建立此种连接,用于接收并处理数据

func (*ConnActor) Close

func (connActor *ConnActor) Close()

Close 连接关闭

func (*ConnActor) RemoteAddr

func (connActor *ConnActor) RemoteAddr() string

RemoteAddr 取得连接的目的地址

func (*ConnActor) RequestAndReponse

func (connActor *ConnActor) RequestAndReponse(b []byte, requstID int64) (*protocol.Proto, error)

RequestAndReponse 向特定的服务发送请求,并等待响应

func (*ConnActor) Status

func (connActor *ConnActor) Status() int32

Status 获取连接状态

func (*ConnActor) Write

func (connActor *ConnActor) Write(b []byte) error

Write 向连接上写入数据, 参数: b []byte 待写入的数据 返回值:n 成功写入的字节数; err 写入时发生的错误

type ConnActorType

type ConnActorType int8

ConnActorType TCP 连接类型 1-passive 2-active

type ConsistentHash

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

ConsistentHash 一致性哈希类

该类维护哈希环并提供hash接口 我们限制hash的值空间在uint32的表示范围内

func NewConsistentHash

func NewConsistentHash() *ConsistentHash

NewConsistentHash 创建并初始化一个新的一致性哈希实例

func (*ConsistentHash) AddNode

func (chash *ConsistentHash) AddNode(svrAddr string) bool

AddNode 增加一个节点

key 要增加的节点key svrAddr 新节点的监听地址 realNodeKey 如果长度不为0说明要增加的是一个虚拟节点。realNodeKey里保存就是虚拟节点对应的真实节点的key

func (*ConsistentHash) AllNode

func (chash *ConsistentHash) AllNode() []string

AllNode 返回所有节点地址

func (*ConsistentHash) Clear

func (chash *ConsistentHash) Clear()

Clear 清除所有节点

func (*ConsistentHash) Find

func (chash *ConsistentHash) Find(key []byte) *Node

Find find node

func (*ConsistentHash) Leastload

func (chash *ConsistentHash) Leastload() string

Leastload 返回服务实例中负载最小的节点

func (*ConsistentHash) Locate

func (chash *ConsistentHash) Locate(key []byte) (string, bool)

Locate 根据hash key返回对应的后台服务的地址

func (*ConsistentHash) RmNode

func (chash *ConsistentHash) RmNode(key []byte) string

RmNode 删除一个节点,如果该节点有虚拟节点将一并清除 返回值 string 被删除的节点的远端地址

type Discover

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

Discover 服务发现的类结构 topology 拓扑表的根节点; topoLocker 保护拓扑表的锁; kapi 连接到etcd的客户端会话handle; selfURI 当前进程自己在服务树中的位置; name 服务名称; localListenAddr 本地监听的地址;

func DiscoverInstance

func DiscoverInstance() *Discover

DiscoverInstance 返回GateSvr的单例对象

func (*Discover) Dispatch

func (discover *Discover) Dispatch(URI string) (*ConnActor, error)

Dispatch 找出请求被分派到哪一个实例去处理 URI 请求的接口路径

func (*Discover) DrectDispatch

func (discover *Discover) DrectDispatch(URI string) (*ConnActor, error)

DrectDispatch 负载均衡的进行分发消息 分发的时候会进行负载均衡的处理 URI 请求的接口路径 匹配节点时会进行完全匹配

func (*Discover) Quit

func (discover *Discover) Quit()

Quit Quit

func (*Discover) Start

func (discover *Discover) Start(srvName string, cfg *config.BaseCfg, selfURI []string, address string)

Start 开启服务发现机制

func (*Discover) StartZipkinTrace

func (discover *Discover) StartZipkinTrace(endPoint, srvHost, srvName string) error

StartZipkinTrace 启动zipkin

type Dispatcher

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

Dispatcher 请求分发

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher new dispatcher

func (*Dispatcher) Delete

func (dispatcher *Dispatcher) Delete(id int64)

Delete give up req id

func (*Dispatcher) Incoming

func (dispatcher *Dispatcher) Incoming(b []byte, ca *ConnActor)

Incoming 回调

func (*Dispatcher) Put

func (dispatcher *Dispatcher) Put(requstID int64) chan *protocol.Proto

Put put request enqueue

type Holder

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

Holder holder that hold all request

func NewHolder

func NewHolder() *Holder

NewHolder new holder

func (*Holder) Delete

func (h *Holder) Delete(reqID int64)

Delete delete req

func (*Holder) Get

func (h *Holder) Get(reqID int64) chan *protocol.Proto

Get get request chan

func (*Holder) GiveUp

func (h *Holder) GiveUp(reqID int64)

GiveUp give up request

func (*Holder) Put

func (h *Holder) Put(reqID int64, ch chan *protocol.Proto)

Put put request

type MethodDesc

type MethodDesc struct {
	MethodName string
	Handler    methodHandler
}

MethodDesc represents an RPC service's method specification.

type Node

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

Node 实例节点 @remoteAddr 节点监听地址 @reqNo 节点当前负载状况

type ProcessInComingPackFunc

type ProcessInComingPackFunc func([]byte)

ProcessInComingPackFunc 处理网络中接收到的请求的回调函数定义

type ServiceDesc

type ServiceDesc struct {
	Version     string
	ServiceName string
	// The pointer to the service interface. Used to check whether the user
	// provided implementation satisfies the interface requirements.
	HandlerType interface{}
	Methods     []MethodDesc
	Metadata    interface{}
	ServiceURI  []string
}

ServiceDesc 服务描述

type SignalFunc

type SignalFunc func(s os.Signal) (isExit bool)

SignalFunc 自定义类型,表示信号的回调函数

参数s: 当前收到的信号 返回值isExit: 表示信号处理完成后是否退出程序

type SignalHandler

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

SignalHandler 信号处理类,管理程序要处理的信号

func NewSignalHandler

func NewSignalHandler() *SignalHandler

NewSignalHandler 创建信号处理对象

func (*SignalHandler) Register

func (shr *SignalHandler) Register(s os.Signal, f SignalFunc)

Register 注册感兴趣的信号及该信号的回调函数

func (*SignalHandler) Start

func (shr *SignalHandler) Start()

Start 开始对信号的拦截

func (*SignalHandler) UnRegister

func (shr *SignalHandler) UnRegister(s os.Signal, f SignalFunc)

UnRegister 解除已注册的信号及回调函数

type SrvVersion

type SrvVersion int8

SrvVersion 服务版本

const (
	SV1 SrvVersion = 1
	SV2 SrvVersion = 2
)

定义服务版本

type TopoChange

type TopoChange struct {
	URI         string
	Conn        *ConnActor
	NodeHashKey string
	NewNode     bool
}

TopoChange 拓扑变化通过的数据结构 URI 拓扑在服务体系树中的位置; Conn 到新实例的连接; NodeHashKey 实例节点的HashKey; 标识当前变更是否是新增一个实点;

Directories

Path Synopsis
protoc-gen-go
descriptor
Package descriptor is a generated protocol buffer package.
Package descriptor is a generated protocol buffer package.
generator
The code generator for the plugin for the Google protocol buffer compiler.
The code generator for the plugin for the Google protocol buffer compiler.
grpc
Package grpc outputs gRPC service descriptions in Go code.
Package grpc outputs gRPC service descriptions in Go code.
irpc
Package irpc outputs iRPC service descriptions in Go code.
Package irpc outputs iRPC service descriptions in Go code.
plugin
Package plugin_go is a generated protocol buffer package.
Package plugin_go is a generated protocol buffer package.
Package protocol is a generated protocol buffer package.
Package protocol is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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