network

package
v1.1.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConnectionShort 短连接模式
	ConnectionShort int = iota
	// ConnectionLong 长连接模式
	ConnectionLong
)

Variables

View Source
var (
	// DefaultServerServiceToConnectionControl 不同系统服务使用不同的连接持有模式
	DefaultServerServiceToConnectionControl = map[config.ClusterType]int{
		config.DiscoverCluster:    ConnectionLong,
		config.HealthCheckCluster: ConnectionShort,
		config.MonitorCluster:     ConnectionShort,
	}
)

Functions

func IsAvailableConnection

func IsAvailableConnection(conn *Connection) bool

IsAvailableConnection 连接是否可用

func ToGRPCConn

func ToGRPCConn(conn ClosableConn) *grpc.ClientConn

ToGRPCConn 转换成GRPC连接

Types

type ClientInfo

type ClientInfo struct {
	IP      atomic.Value
	HashKey atomic.Value
}

ClientInfo 当前客户端相关信息

func (*ClientInfo) GetHashKey

func (c *ClientInfo) GetHashKey() []byte

GetHashKey 获取Hash值

func (*ClientInfo) GetIPString

func (c *ClientInfo) GetIPString() string

GetIPString 获取IP值

type ClosableConn

type ClosableConn interface {
	// Close 关闭并释放
	Close() error
}

ClosableConn 可关闭连接对象

type ConnCreator

type ConnCreator interface {
	// Name 插件名
	Name() string
	// CreateConnection 创建实际的连接
	CreateConnection(address string, timeout time.Duration, clientInfo *ClientInfo) (ClosableConn, error)
}

ConnCreator 连接创建器

type ConnID

type ConnID struct {
	// ID 唯一ID
	ID uint32
	// Service 所属服务
	Service config.ClusterService
	// Address 目标server地址
	Address string
	// contains filtered or unexported fields
}

ConnID 连接标识

func (ConnID) String

func (c ConnID) String() string

String TOString方法

type Connection

type Connection struct {
	ConnID
	// 连接实体
	Conn ClosableConn
	// contains filtered or unexported fields
}

Connection GRPC连接对象,含唯一连接ID

func (*Connection) ForceClose

func (c *Connection) ForceClose() bool

func (*Connection) Release

func (c *Connection) Release(opKey string)

Release 释放连接

type ConnectionManager

type ConnectionManager interface {

	// SetConnCreator 设置当前协议的连接创建器
	SetConnCreator(creator ConnCreator)

	// Destroy 销毁并释放连接管理器
	Destroy()

	// GetConnection 获取并占用连接
	GetConnection(opKey string, clusterType config.ClusterType) (*Connection, error)

	// GetConnectionByHashKey 通过传入一致性hashKey的方式获取链接
	GetConnectionByHashKey(opKey string, clusterType config.ClusterType, hashKey []byte) (*Connection, error)

	// ReportConnectionDown 报告连接故障
	ReportConnectionDown(connID ConnID)

	// ReportSuccess 上报接口调用成功
	ReportSuccess(connID ConnID, retCode int32, timeout time.Duration)

	// ReportFail 上报接口调用失败
	ReportFail(connID ConnID, retCode int32, timeout time.Duration)

	// UpdateServers 更新服务地址
	UpdateServers(svcEventKey model.ServiceEventKey)

	// GetClientInfo 获取当前客户端信息
	GetClientInfo() *ClientInfo

	// IsReady discover服务是否已经就绪
	IsReady() bool

	// GetHashExpectedInstance 计算hash Key对应的实例
	GetHashExpectedInstance(clusterType config.ClusterType, hash []byte) (string, model.Instance, error)

	// ConnectByAddr 直接通过addr连接,慎使用
	ConnectByAddr(clusterType config.ClusterType, addr string, instance model.Instance) (*Connection, error)
}

ConnectionManager 通用的连接管理器

func NewConnectionManager

func NewConnectionManager(
	cfg config.Configuration, valueCtx model.ValueContext) (ConnectionManager, error)

NewConnectionManager 创建连接管理器

type ServerAddressList

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

ServerAddressList 服务地址列表

func (*ServerAddressList) ConnectServerByAddrOnly

func (s *ServerAddressList) ConnectServerByAddrOnly(addr string, timeout time.Duration,
	clsService config.ClusterService, instance model.Instance) (*Connection, error)

ConnectServerByAddrOnly 。根据地址进行链接

Jump to

Keyboard shortcuts

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